redis的mq功能演示

netkiller發表於2016-05-14

redis-cli – Command-line client to redis-server

2.1. 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!!!"


相關文章