[multi-DB] Part 4: add sonic-db-cli to replace redis-cli#54
[multi-DB] Part 4: add sonic-db-cli to replace redis-cli#54qiluo-msft merged 6 commits intosonic-net:masterfrom
Conversation
|
@qiluo-msft move sonic-db-cli into swsssdk pkg |
src/swsssdk/scripts/sonic-db-cli
Outdated
|
|
||
| # Determine whether stdout is on a terminal | ||
| if os.isatty(1): | ||
| DOCKER_EXEC_FLAGS += "t" |
There was a problem hiding this comment.
DOCKER_EXEC_FLAGS [](start = 4, length = 17)
Not needed any more? #Closed
src/swsssdk/scripts/sonic-db-cli
Outdated
| print >> sys.stderr, msg | ||
| logger.error(msg) | ||
| else: | ||
| client = redis.StrictRedis(db=dbid, host=dbhostname, port=dbport) |
There was a problem hiding this comment.
client [](start = 8, length = 6)
This try-except is a working solution.
How about SonicV2Connector.get_redis_client() ? Is it much easier? #Closed
There was a problem hiding this comment.
we can use SonicV2Connector() as well, updated.
|
BTW do we have any app using SonicV2Connector who has no root role? If the app is not executed via root, we cannot use unix_socket_path by default since redis.sock requiring root access. For safety purpose, do we want to make use_unix_socket_path to FALSE by default. There are too many scripts using SonicV2Connector(). And today, they are all using TCP + port mode. #Resolved |
|
All app using SonicV2Connector are running by root. Python/script could use TCP port as default, which is current situation. I believe if you use unixsocket, it is still working fine. In reply to: 545566509 [](ancestors = 545566509) |
src/swsssdk/scripts/sonic-db-cli
Outdated
| logger.addHandler(logging.NullHandler()) | ||
|
|
||
| if len(sys.argv) < 3: | ||
| msg = "More than three arguments are required. 'usage: sonic-db-cli dbname rediscommands'" |
There was a problem hiding this comment.
"More than three arguments are required" is not quite an accurate message (more correctly, it requires at least two arguments (the first arg in argv is the program name)). I suggest removing that message altogether, and just print the usage message, like:
Usage: sonic-db-cli <db_name> <redis_commands>
There was a problem hiding this comment.
How about Usage: sonic-db-cli <db_name> <cmd> [cmd [arg [arg ...]]]
redis-cli -h will give an excellent sample. #Closed
There was a problem hiding this comment.
updated. @qiluo-msft @jleveque
admin@ASW-7005:~$ sonic-db-cli XXX
'Usage: sonic-db-cli <db_name> [cmd [arg [arg ...]]]'. See 'sonic-db-cli -h' for detail example.
admin@ASW-7005:~$ 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
src/swsssdk/scripts/sonic-db-cli
Outdated
| print "Example 2: sonic-db-cli APPL_DB HGETALL VLAN_TABLE:Vlan10" | ||
| print "Example 3: sonic-db-cli APPL_DB HGET VLAN_TABLE:Vlan10 mtu" | ||
| elif argc < 3: | ||
| msg = "'Usage: sonic-db-cli <db_name> <cmd> [cmd [arg [arg ...]]]'. See 'sonic-db-cli -h' for detail example." |
There was a problem hiding this comment.
| msg = "'Usage: sonic-db-cli <db_name> <cmd> [cmd [arg [arg ...]]]'. See 'sonic-db-cli -h' for detail example." | |
| msg = "'Usage: sonic-db-cli <db_name> <cmd> [arg [arg ...]]'. See 'sonic-db-cli -h' for detail example." |
Sorry for the wrong sample above #Closed
src/swsssdk/scripts/sonic-db-cli
Outdated
|
|
||
| logger = logging.getLogger(__name__) | ||
| logger.setLevel(logging.INFO) | ||
| logger.addHandler(logging.NullHandler()) |
There was a problem hiding this comment.
Do we really need logging? Is it a performance issue? #Closed
There was a problem hiding this comment.
I don't think it is necessary. There is no logging in original redis-cli shell script. I think we can remove it. Definitely it will add overhead to run this python script.
* [multi-DB] Part 4: add sonic-db-cli to replace redis-cli * use SonicV2Connector instead and fix previous if condition typo * remove unused import * use_unix_socket_path set to False by default to avoid unnecessary failed * update Usage message and add example under -h * remove logging and update usage msg
admin@ASW-7005:~$ sonic-db-cli LOGLEVEL_Dx
More than three arguments are required. 'usage: sonic-db-cli 'dbname' 'redis commands''
admin@ASW-7005:~$ sonic-db-cli LOGLEVEL_DB x
(error) ERR unknown command
x, with args beginning with:admin@ASW-7005:~$ sonic-db-cli LOGLEVEL_DB1 keys *
Invalid database name input : 'LOGLEVEL_DB1'
admin@ASW-7005:~$ sonic-db-cli LOGLEVEL_DB keys *
Signed-off-by: Dong Zhang [email protected]