title: Redis coroutine client meta:

  • name: description content: Redis coroutine client,Implemented by swoole coroutine client,Covers the method of redis 99%
  • name: keywords content: swoole|swoole extension|swoole framework|EasySwoole redis| Swoole Redis coroutine client|swoole Redis|Redis coroutine

Redis coroutine client

Redis coroutine client,Implemented by swoole coroutine client
github地址: https://github.com/easy-swoole/redis

Composer installation

  1. composer require easyswoole/redis

Use the client (requires a coroutine environment):

  1. $redis = new \EasySwoole\Redis\Redis(new \EasySwoole\Redis\Config\RedisConfig([
  2. 'host' => '127.0.0.1',
  3. 'port' => '6379',
  4. 'auth' => 'easyswoole',
  5. 'serialize' => \EasySwoole\Redis\Config\RedisConfig::SERIALIZE_NONE
  6. ]));

Redis usage example

  1. <?php
  2. include "../vendor/autoload.php";
  3. go(function (){
  4. $redis = new \EasySwoole\Redis\Redis(new \EasySwoole\Redis\Config\RedisConfig([
  5. 'host' => '127.0.0.1',
  6. 'port' => '6379',
  7. 'auth' => 'easyswoole',
  8. 'serialize' => \EasySwoole\Redis\Config\RedisConfig::SERIALIZE_NONE
  9. ]));
  10. var_dump($redis->set('a',1));
  11. var_dump($redis->get('a'));
  12. });

Redis cluster usage example

  1. <?php
  2. include "../vendor/autoload.php";
  3. go(function () {
  4. $redis = new \EasySwoole\Redis\RedisCluster(new \EasySwoole\Redis\Config\RedisClusterConfig([
  5. ['172.16.253.156', 9001],
  6. ['172.16.253.156', 9002],
  7. ['172.16.253.156', 9003],
  8. ['172.16.253.156', 9004],
  9. ], [
  10. 'auth' => '',
  11. 'serialize' => \EasySwoole\Redis\Config\RedisConfig::SERIALIZE_PHP
  12. ]));
  13. var_dump($redis->set('a',1));
  14. var_dump($redis->get('a'));
  15. var_dump($redis->clusterKeySlot('a'));
  16. });