异步Redis客户端

连接池(连接池默认开启)

  1. use AsyncRedis;
  2. //关闭连接池
  3. AsyncRedis::enablePool(false);
  4. //开启连接池
  5. AsyncRedis::enablePool(true);

使用AsyncRedis

  1. use AsyncRedis;
  2. //设置超时时间
  3. AsyncRedis::setTimeout(2);
  4. yield AsyncRedis::set('foo', 'bar');
  5. dump(yield AsyncRedis::get('foo'));
  6. $user = json_encode(['foo' => 'bar']);
  7. yield AsyncRedis::hSet('user', 1, $user);
  8. dump(yield AsyncRedis::hGet('user', 1));

修改配置信息config/database.php:

  1. 'redis' => [
  2. //redis连接池数量
  3. 'maxPool' => 5,
  4. //redis连接超时时间
  5. 'timeout' => 5,
  6. 'default' => [
  7. 'host' => '127.0.0.1',
  8. 'port' => 6379,
  9. 'prefix' => 'group_',
  10. 'auth' => '',
  11. 'connect' => 'persistence'
  12. ],
  13. ],

#