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 <hostname>      Server hostname (default: 127.0.0.1).
  -p <port>          Server port (default: 6379).
  -s <socket>        Server socket (overrides hostname and port).
  -a <password>      Password to use when connecting to the server.
  -r <repeat>        Execute specified command N times.
  -i <interval>      When -r is used, waits <interval> seconds per command.
                     It is possible to specify sub-second times like -i 0.1.
  -n <db>            Database number.
  -x                 Read last argument from STDIN.
  -d <delimiter>     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 <keys>  Simulate a cache workload with an 80-20 distribution.
  --slave            Simulate a slave showing commands received from the master.
  --rdb <filename>   Transfer an RDB dump from remote server to local file.
  --pipe             Transfer raw Redis protocol from stdin to server.
  --pipe-timeout <n> In --pipe mode, abort with error if after sending all data.
                     no reply is received within <n> 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 <pat>    Useful with --scan to specify a SCAN pattern.
  --intrinsic-latency <sec> Run a test to measure intrinsic system latency.
                     The test will run for the specified amount of seconds.
  --eval <file>      Send an EVAL command using the Lua script at <file>.
  --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> 將 ip 和 port 所指定的節點添加到集群當中,讓它成為集群的一份子。  
CLUSTER FORGET <node_id> 從集群中移除 node_id 指定的節點。  
CLUSTER REPLICATE <node_id> 將當前節點設置為 node_id 指定的節點的從節點。  
CLUSTER SAVECONFIG 將節點的配置文件保存到硬盤里面。   

//槽(slot)  
CLUSTER ADDSLOTS <slot> [slot ...] 將一個或多個槽(slot)指派(assign)給當前節點。  
CLUSTER DELSLOTS <slot> [slot ...] 移除一個或多個槽對當前節點的指派。  
CLUSTER FLUSHSLOTS 移除指派給當前節點的所有槽,讓當前節點變成一個沒有指派任何槽的節點。 
CLUSTER SETSLOT <slot> NODE <node_id> 將槽 slot 指派給 node_id 指定的節點,如果槽已經指派給另一個節點,那么先讓另一個節點刪除該槽>,然后再進行指派。  
CLUSTER SETSLOT <slot> MIGRATING <node_id> 將本節點的槽 slot 遷移到 node_id 指定的節點中。  
CLUSTER SETSLOT <slot> IMPORTING <node_id> 從 node_id 指定的節點中導入槽 slot 到本節點。  
CLUSTER SETSLOT <slot> STABLE 取消對槽 slot 的導入(import)或者遷移(migrate)。   

//鍵 (key)  
CLUSTER KEYSLOT <key> 計算鍵 key 應該被放置在哪個槽上。  
CLUSTER COUNTKEYSINSLOT <slot> 返回槽 slot 目前包含的鍵值對數量。  
CLUSTER GETKEYSINSLOT <slot> <count> 返回 count 個 slot 槽中的鍵。  
這些命令是集群所獨有的。執行上述命令要先登錄

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

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM