lanfix/yii2-redis-pub-sub
Composer 安装命令:
composer require lanfix/yii2-redis-pub-sub
包简介
Yii2 pub/sub component for Redis
README 文档
README
This library adds binding functions for Redis to publish and subscribe to channels.
How to install
You must do it for prepare system to work:
- Compile php with php-redis extension if you use php-fpm or install php-redis apache module in other case.
- Enable php-redis in php.ini
extension=redis
Next install this library with composer
composer require --prefer-dist lanfix/yii2-redis-pub-sub
Or add this string to composer.json
"lanfix/yii2-redis-pub-sub": "*"
Set up
Firstly add to configure file web.php this code
'redisPubSub' => [ 'class' => 'lanfix\redis_pub_sub\RedisPubSub', 'connect' => [ 'hostname' => 'localhost', 'port' => 6379, 'password' => '' ] ],
Usage
Subscribe to Redis channel
Warning! It function stops your application and wait messages!
It is desirable to run this function in parallel or in other daemon
Yii::$app->redisPubSub->subscribe('my-channel-name', function($message) { var_dump($message); });
And sending message to this channel
Yii::$app->redisPubSub->publish('my-channel-name', 'Hello! How are you?');
To unsubscribe from channel use
Yii::$app->redisPubSub->unsubscribe('my-channel-name');
统计信息
- 总下载量: 309
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-04-11