Home | 簡體中文 | 繁體中文 | 雜文 | 打賞(Donations) | ITEYE 博客 | OSChina 博客 | Facebook | Linkedin | 知乎專欄 | Search | Email

46.3. redis-cli - Command-line client to redis-server

46.3.1. 命令參數

			
-a <password>      Password to use when connecting to the server.
[root@netkiller conf.d]# redis-cli -a hsM8NK8b71vFQKFOS55jbWJrA1TYgI4e

			
			

46.3.2. auth

認證密碼

[root@netkiller ~]# redis-cli 
127.0.0.1:6379> keys *
(error) NOAUTH Authentication required.
127.0.0.1:6379> auth hsM8NKb71vjbWJrA1TYgI4
OK
127.0.0.1:6379> keys *
 1) "HK50(1605)"
 2) "GBPUSD"
 3) "USDCHF"
 4) "SP500(1609)"
 5) "NZDJPY"
 6) "AUDNZD"
 7) "EURGBP"
 8) "CLN6"
 9) "BU6"
			

46.3.3. MONITOR

$ redis-cli monitor			
			

46.3.4. save/bgsave/lastsave

save/bgsave 保存持久化將數據,lastsave 查看相關信息

			
redis 127.0.0.1:6379> save
OK
redis 127.0.0.1:6379> bgsave
Background saving started
redis 127.0.0.1:6379> lastsave
(integer) 1373335757
			
			

46.3.5. Pub/Sub 訂閲與發佈

redis 提供基本的MQ 功能,下面我們做一個演示

開啟第一個終端窗口,訂閲first second

$ redis-cli
redis 127.0.0.1:6379> SUBSCRIBE first second
Reading messages... (press Ctrl-C to quit)
1) "subscribe"
2) "first"
3) (integer) 1
1) "subscribe"
2) "second"
3) (integer) 2
			

開啟第二個終端窗口,分別發送first second

$ redis-cli
redis 127.0.0.1:6379>  PUBLISH second Hello
(integer) 1
redis 127.0.0.1:6379>  PUBLISH first Helloworld!!!
(integer) 1
redis 127.0.0.1:6379> quit
			

現在切換到第一個終端窗口,應該能夠看到發送過來的字元串

$ redis-cli
redis 127.0.0.1:6379> SUBSCRIBE first second
Reading messages... (press Ctrl-C to quit)
1) "subscribe"
2) "first"
3) (integer) 1
1) "subscribe"
2) "second"
3) (integer) 2

1) "message"
2) "second"
3) "Hello"

1) "message"
2) "first"
3) "Helloworld!!!"
			

46.3.6. --latency Enter a special mode continuously sampling latency.

參數的功能是從客戶端發出一條命令到客戶端接受到該命令的反饋所用的最長響應時間

# redis-cli --latency -h 192.168.2.1 
min: 1, max: 210, avg: 3.64 (13453 samples)