Skip to content

[MultiDB] sonic-db-cli should support EVAL operation, app script use …#58

Merged
qiluo-msft merged 2 commits intosonic-net:masterfrom
dzhangalibaba:sonicdbcli
Dec 18, 2019
Merged

[MultiDB] sonic-db-cli should support EVAL operation, app script use …#58
qiluo-msft merged 2 commits intosonic-net:masterfrom
dzhangalibaba:sonicdbcli

Conversation

@dzhangalibaba
Copy link
Copy Markdown
Collaborator

@dzhangalibaba dzhangalibaba commented Dec 18, 2019

sonic-db-cli should support EVAL operation, one app script use it in this way

test :
admin@ASW-7005:~$ sudo /tmp/sonic-db-cli APPL_DB EVAL "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}" 2 k1 k2 v1 v2
['k1', 'k2', 'v1', 'v2']

Signed-off-by: Dong Zhang d.zhang@alibaba-inc.com

@dzhangalibaba
Copy link
Copy Markdown
Collaborator Author

@qiluo-msft we need this merged first and then we can move further on the replacement of redis-cli

keys_args = [] if numkeys == 0 else sys.argv[5:]
print client.execute_command(op, lua_script, numkeys, *keys_args)
else:
print client.execute_command(" ".join(sys.argv[2:]))
Copy link
Copy Markdown
Contributor

@qiluo-msft qiluo-msft Dec 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you unify both branches? execute_command is quite general for both cases. #Closed

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DONE

@qiluo-msft
Copy link
Copy Markdown
Contributor

qiluo-msft commented Dec 18, 2019

print "Example 3: sonic-db-cli APPL_DB HGET VLAN_TABLE:Vlan10 mtu"

Could you add one more example? And use python heredoc https://en.wikipedia.org/wiki/Here_document#Python ? #Closed


Refers to: src/swsssdk/scripts/sonic-db-cli:9 in 3ab2506. [](commit_id = 3ab2506, deletion_comment = False)

Copy link
Copy Markdown
Contributor

@qiluo-msft qiluo-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As comments.

@dzhangalibaba
Copy link
Copy Markdown
Collaborator Author

print "Example 3: sonic-db-cli APPL_DB HGET VLAN_TABLE:Vlan10 mtu"

Could you add one more example? And use python heredoc https://en.wikipedia.org/wiki/Here_document#Python ?

Refers to: src/swsssdk/scripts/sonic-db-cli:9 in 3ab2506. [](commit_id = 3ab2506, deletion_comment = False)

DONE

admin@ASW-7005:~$ /tmp/sonic-db-cli -h

Example 1: sonic-db-cli CONFIG_DB keys *
Example 2: sonic-db-cli APPL_DB HGETALL VLAN_TABLE:Vlan10
Example 3: sonic-db-cli APPL_DB HGET VLAN_TABLE:Vlan10 mtu
Example 4: sonic-db-cli APPL_DB EVAL "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}" 2 k1 k2 v1 v2

admin@ASW-7005:~$ /tmp/sonic-db-cli CONFIG_DB keys *
['ASPATH_ACCESS_LIST|as-filter20', 'PORT|Ethernet7', 'PORT|Ethernet27', 'PORTCHANNEL|PortChannel4', 'PORT|Ethernet33', 'PORT|Ethernet6', 'PORT|Ethernet28', 'ROUTE_MAP|SET_COMMUNITY|permit|10', 'PORTCHANNEL|PortChannel10', 'PORTCHANNEL|PortChannel5', 'PORT|Ethernet11', 'PORTCHANNEL_MEMBER|PortChannel1|Ethernet30', 'COMMUNITY_LIST|101', 'BGP_NEIGHBOR|up-group-v4', 'SNMP_USER|alimonitor2', 'ROUTE_MAP|ASW2PSW_OUT|permit|30', 'PORT|Ethernet29', 'PORT|Ethernet23', 'VLAN|Vlan10', 'PORTCHANNEL|PortChannel1', 'PORT|Ethernet100', 'PORT|Ethernet38', 'ROUTE_MAP|ASW2PSW_IN|permit|10', 'PORT|Ethernet9', 'PORT|Ethernet31', 'ASPATH_ACCESS_LIST|as-filter30', 'INTERFACE|Ethernet52|52.52.52.5/24', 'PORTCHANNEL_MEMBER|PortChannel7|Ethernet6', 'FLEX_COUNTER_TABLE|PFCWD', 'ROUTE_MAP|ASW2PSW_IN|permit|30', 'PORT|Ethernet108', 'TC_TO_PRIORITY_GROUP_MAP|ALI', 'PORT|Ethernet22', 'DEVICE_METADATA|localhost', 'PORT|Ethernet88', 'PORT|Ethernet13', 'PORT|Ethernet30', 'MGMT_INTERFACE|Management0|30.57.185.58/24', 'TC_TO_QUEUE_MAP|ALI', 'PORT|Ethernet46', 'BGP_NETWORK|11.163.117.192/26', 'VLAN_INTERFACE|Vlan10', 'INTERFACE|Ethernet0', 'BGP_NEIGHBOR|52.52.52.2', 'PORT|Ethernet8', 'VLAN_MEMBER|Vlan10|PortChannel5', 'PORT|Ethernet20', 'BGP_NETWORK|105.105.105.105/32', 'PORT|Ethernet42', 'PORT|Ethernet92', 'PORTCHANNEL_MEMBER|PortChannel8|Ethernet7', 'PORTCHANNEL|PortChannel6', 'SWITCH|SWITCH_ATTR', 'PORT|Ethernet40', 'VLAN_MEMBER|Vlan10|PortChannel1', 'PORT|Ethernet2', 'VLAN_MEMBER|Vlan10|PortChannel10', 'PORT|Ethernet16', 'INTERFACE|Ethernet52', 'PORT|Ethernet41', 'COMMUNITY_LIST|100', 'FLEX_COUNTER_TABLE|QUEUE_WATERMARK', 'BGP_REDIST|kernel', 'PORTCHANNEL|PortChannel8', 'ARP|arp2host', 'MAP_PFC_PRIORITY_TO_QUEUE|ALI', 'PORTCHANNEL_MEMBER|PortChannel3|Ethernet2', 'LOOPBACK_INTERFACE|Loopback0|105.105.105.105/32', 'PORT|Ethernet10', 'ARP|aging', 'TELEMETRY|gnmi', 'PORT|Ethernet47', 'PORT|Ethernet37', 'PORTCHANNEL_MEMBER|PortChannel10|Ethernet9', 'ROUTE_MAP|ASW2PSW_OUT|deny|20', 'LOOPBACK_INTERFACE|Loopback0', 'PORT|Ethernet12', 'PORT|Ethernet14', 'PORTCHANNEL|PortChannel2', 'PORT|Ethernet34', 'PORT|Ethernet104', 'SNMP_USER|alimonitor', 'PORT|Ethernet4', 'VLAN_MEMBER|Vlan10|PortChannel3', 'PORTCHANNEL_MEMBER|PortChannel9|Ethernet8', 'PORT|Ethernet56', 'PORTCHANNEL|PortChannel7', 'PORT|Ethernet44', 'VLAN_MEMBER|Vlan10|PortChannel8', 'PFC_WD|BUFFER_HANG_ENABLE', 'INTERFACE|Ethernet0|21.21.21.5/26', 'PORT|Ethernet0', 'PORT|Ethernet39', 'VLAN_MEMBER|Vlan10|PortChannel9', 'PORT|Ethernet21', 'PORT|Ethernet48', 'PORT|Ethernet1', 'PORT|Ethernet19', 'PORT|Ethernet26', 'VLAN_MEMBER|Vlan10|PortChannel6', 'VLAN_MEMBER|Vlan10|PortChannel4', 'CONFIG_DB_INITIALIZED', 'PORT|Ethernet68', 'PORTCHANNEL|PortChannel9', 'FLEX_COUNTER_TABLE|PORT', 'PORT|Ethernet64', 'PORT|Ethernet60', 'VLAN_INTERFACE|Vlan10|11.163.117.247/26', 'INTERFACE|Ethernet32|9.1.1.1/24', 'PORT|Ethernet24', 'PORT|Ethernet96', 'VERSIONS|DATABASE', 'PORT|Ethernet84', 'PORT|Ethernet5', 'PORT|Ethernet80', 'PORT|Ethernet18', 'INTERFACE|Ethernet32', 'PORTCHANNEL|PortChannel3', 'PORT|Ethernet32', 'PORT|Ethernet45', 'PORT|Ethernet36', 'PORTCHANNEL_MEMBER|PortChannel5|Ethernet4', 'PORT|Ethernet43', 'PORT|Ethernet15', 'FLEX_COUNTER_TABLE|PG_WATERMARK', 'BGP_NETWORK|52.52.52.0/24', 'PORT|Ethernet35', 'PORT|Ethernet52', 'ROUTE_MAP|ASW2PSW_IN|deny|20', 'PORTCHANNEL_MEMBER|PortChannel4|Ethernet3', 'BGP_PARAMETERS|65021', 'VLAN_MEMBER|Vlan10|PortChannel7', 'PORT|Ethernet76', 'FLEX_COUNTER_TABLE|QUEUE', 'PORT|Ethernet3', 'PORT|Ethernet25', 'BGP_NEIGHBOR|up-group-v6', 'PORT|Ethernet72', 'PORTCHANNEL_MEMBER|PortChannel6|Ethernet5', 'PORTCHANNEL_MEMBER|PortChannel2|Ethernet1', 'VLAN_MEMBER|Vlan10|PortChannel2', 'PORT|Ethernet17', 'LINK_DELAY_UP|global']

admin@ASW-7005:~$ /tmp/sonic-db-cli APPL_DB HGETALL VLAN_TABLE:Vlan10
{'admin_status': 'up', 'mtu': '9100'}

admin@ASW-7005:~$ /tmp/sonic-db-cli APPL_DB HGET VLAN_TABLE:Vlan10 mtu
9100

admin@ASW-7005:~$ /tmp/sonic-db-cli APPL_DB EVAL "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}" 2 k1 k2 v1 v2
['k1', 'k2', 'v1', 'v2']

@qiluo-msft qiluo-msft merged commit ccc1307 into sonic-net:master Dec 18, 2019
@dzhangalibaba dzhangalibaba deleted the sonicdbcli branch December 18, 2019 21:50
abdosi pushed a commit that referenced this pull request Jan 6, 2020
#58)

* [MultiDB] sonic-db-cli should support EVAL operation, app script use it in this way
* unify client.execute_command
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants