您的位置:首页 > 其它

弄技术要弄通-公司reis的pub/sub怎么使用的呢?

2018-01-31 23:44 435 查看

Pub/Sub in Redis using PHP

Posted on November 14, 2011by xmeng

I would like to put an example together about the pub/sub using php in Redis; there is only API documentation available in phpredis, the PHP client I am using (http://redis.io/clients).

0. Setup
First setup a Redis Server. I set up a Redis server in my local box using port 6378 (myredisserver.test.com:6378).

1. Publish: push a message to a channel.
This part is relatively easy. The following is a php script “publish.php“.

1.5 Checkpoint: Monitor in Redis server.
Let’s take a break now and see what will happen if we run the script “publish.php” from a client side.
Because I use a non default port, “-p” option is used with “redis-cli” command.
Open a new terminal at Redis Server, and issue “MONITOR” command in redis “console”:

2. Subscribe: Listen to a channel (or some channels).
Here is the complete php script “subscribe.php” after I did some debugging. Thanks to the info here: https://github.com/nicolasff/phpredis/issues/36.

2.5
1) run script “subscribe.php“:

of course, nothing happens.

2) In another terminal window, run script “publish.php” twice, and come back to have a look!

3. Breakpoint: Revisit the MINTOR window in Redis Server:

4. Test with multiple publishers and multiple subscribers!

Reference: http://robots.thoughtbot.com/post/6325247416/redis-pub-sub-how-does-it-work
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐