Redis学习5之redis-cli使用方法总结

1.redis-cli使用时各参数的含义和使用方法

xubo@xubo:~/7000$ redis-cli  --help
redis-cli 3.0.3

Usage: redis-cli [OPTIONS] [cmd [arg [arg ...]]]
  -h       Server hostname (default: 127.0.0.1).
  -p           Server port (default: 6379).
  -s <socket>        Server socket (overrides hostname and port).
  -a       Password to use when connecting to the server.
  -r <repeat>        Execute specified command N times.
  -i       When -r is used, waits  seconds per command.
                     It is possible to specify sub-second times like -i 0.1.
  -n             Database number.
  -x                 Read last argument from STDIN.
  -d      Multi-bulk delimiter in for raw formatting (default: \n).
  -c                 Enable cluster mode (follow -ASK and -MOVED redirections).
  --raw              Use raw formatting for replies (default when STDOUT is
                     not a tty).
  --no-raw           Force formatted output even when STDOUT is not a tty.
  --csv              Output in CSV format.
  --stat             Print rolling stats about server: mem, clients, ...
  --latency          Enter a special mode continuously sampling latency.
  --latency-history  Like --latency but tracking latency changes over time.
                     Default time interval is 15 sec. Change it using -i.
  --latency-dist     Shows latency as a spectrum, requires xterm 256 colors.
                     Default time interval is 1 sec. Change it using -i.
  --lru-test   Simulate a cache workload with an 80-20 distribution.
  --slave            Simulate a slave showing commands received from the master.
  --rdb    Transfer an RDB dump from remote server to local file.
  --pipe             Transfer raw Redis protocol from stdin to server.
  --pipe-timeout  In --pipe mode, abort with error if after sending all data.
                     no reply is received within  seconds.
                     Default timeout: 30. Use 0 to wait forever.
  --bigkeys          Sample Redis keys looking for big keys.
  --scan             List all keys using the SCAN command.
  --pattern     Useful with --scan to specify a SCAN pattern.
  --intrinsic-latency  Run a test to measure intrinsic system latency.
                     The test will run for the specified amount of seconds.
  --eval       Send an EVAL command using the Lua script at .
  --help             Output this help and exit.
  --version          Output version and exit.

Examples:
  cat /etc/passwd | redis-cli -x set mypasswd
  redis-cli get mypasswd
  redis-cli -r 100 lpush mylist x
  redis-cli -r 100 -i 1 info | grep used_memory_human:
  redis-cli --eval myscript.lua key1 key2 , arg1 arg2 arg3
  redis-cli --scan --pattern '*:12345*'

  (Note: when using --eval the comma separates KEYS[] from ARGV[] items)

When no command is given, redis-cli starts in interactive mode.
Type "help" in interactive mode for information on available commands.

2.redis cluster集群的指令:
redis-cli -p 7000 cluster nodes
redis-cli -p 7000 cluster info
redis-cli -p 7000 cluster slots

xubo@xubo:~/7000$ redis-cli -p 7000 cluster nodes
b5ee3eedebf7319ac07f2497828390f5fa075c39 127.0.0.1:7003 master - 0 1441960406819 7 connected 0-5460
07dbe7d13669451a8bdf31ea7d8d30e654a84954 127.0.0.1:7001 master - 0 1441960404817 2 connected 5461-10922
7f5ad4dc90ba1f2c8557ce5522436fc1cf4c6084 127.0.0.1:7002 master - 0 1441960405818 3 connected 10923-16383
300125efa46f10c64e9db9835691889cde49bd61 127.0.0.1:7005 slave 7f5ad4dc90ba1f2c8557ce5522436fc1cf4c6084 0 1441960403816 6 connected
87ef8abfdfe8a3d1a74873d02a6f1ebd0eb9e115 127.0.0.1:7000 myself,slave b5ee3eedebf7319ac07f2497828390f5fa075c39 0 0 1 connected
039c98b646b95f0d912a0b5b80b9aba764fd453a 127.0.0.1:7004 slave 07dbe7d13669451a8bdf31ea7d8d30e654a84954 0 1441960402815 5 connected
xubo@xubo:~/7000$ redis-cli -p 7000 cluster info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:6
cluster_size:3
cluster_current_epoch:22
cluster_my_epoch:7
cluster_stats_messages_sent:53787
cluster_stats_messages_received:53782
xubo@xubo:~/7000$ redis-cli -p 7000 cluster slot
(error) ERR Wrong CLUSTER subcommand or number of arguments
xubo@xubo:~/7000$ redis-cli -p 7000 cluster slots
1) 1) (integer) 0
   2) (integer) 5460
   3) 1) "127.0.0.1"
      2) (integer) 7003
   4) 1) "127.0.0.1"
      2) (integer) 7000
2) 1) (integer) 5461
   2) (integer) 10922
   3) 1) "127.0.0.1"
      2) (integer) 7001
   4) 1) "127.0.0.1"
      2) (integer) 7004
3) 1) (integer) 10923
   2) (integer) 16383
   3) 1) "127.0.0.1"
      2) (integer) 7002
   4) 1) "127.0.0.1"
      2) (integer) 7005

其他:

redis cluster命令行

//集群(cluster)  
CLUSTER INFO 打印集群的信息  
CLUSTER NODES 列出集群当前已知的所有节点(node),以及这些节点的相关信息。   

//节点(node)  
CLUSTER MEET   将 ip 和 port 所指定的节点添加到集群当中,让它成为集群的一份子。  
CLUSTER FORGET  从集群中移除 node_id 指定的节点。  
CLUSTER REPLICATE  将当前节点设置为 node_id 指定的节点的从节点。  
CLUSTER SAVECONFIG 将节点的配置文件保存到硬盘里面。   

//槽(slot)  
CLUSTER ADDSLOTS  [slot ...] 将一个或多个槽(slot)指派(assign)给当前节点。  
CLUSTER DELSLOTS  [slot ...] 移除一个或多个槽对当前节点的指派。  
CLUSTER FLUSHSLOTS 移除指派给当前节点的所有槽,让当前节点变成一个没有指派任何槽的节点。 
CLUSTER SETSLOT  NODE  将槽 slot 指派给 node_id 指定的节点,如果槽已经指派给另一个节点,那么先让另一个节点删除该槽>,然后再进行指派。  
CLUSTER SETSLOT  MIGRATING  将本节点的槽 slot 迁移到 node_id 指定的节点中。  
CLUSTER SETSLOT  IMPORTING  从 node_id 指定的节点中导入槽 slot 到本节点。  
CLUSTER SETSLOT  STABLE 取消对槽 slot 的导入(import)或者迁移(migrate)。   

//键 (key)  
CLUSTER KEYSLOT  计算键 key 应该被放置在哪个槽上。  
CLUSTER COUNTKEYSINSLOT  返回槽 slot 目前包含的键值对数量。  
CLUSTER GETKEYSINSLOT   返回 count 个 slot 槽中的键。  
这些命令是集群所独有的。执行上述命令要先登录

没收集全,如果全的求告知。

参考资料:
【1】 http://www.111cn.net/database/276/84984.htm

你可能感兴趣的:(redis,NoSQL)