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