1.安装redis

忽视

2.安装hiredis库

https://wiki.swoole.com/wiki/page/p-redis.html

a. wget https://github.com/redis/hiredis/archive/v0.13.3.tar.gz

b. tar -zxvf v0.13.3.tar.gz 

c. cd hiredis-0.13.3/

d.  make -j

e.  make install

f. sudo ldconfig

3.重新编译swoole库,加入-enable-async-redis

 ./configure --help

可以看到

swoole 异步redis

./configure --with-php-config=/home/work/bin/php-config --enable-async-redis

make clean 清理上次make的情况

swoole 异步redis

make -j

make install

一. 可以查看php -m扩展情况


swoole 异步redis

二.是否支持异步

php --ri swoole

swoole 异步redis


<?php

class AysRedis
{
    const HOST = '127.0.0.1';
    const PORT = 6379;
    public $redis_client = null;

    function __construct()
    {
        $this->redis_client = new swoole_redis;
    }

    /**
     * 闭包里不好直接用变量,要用use
     * @return bool
     */
    public function execute($id, $username)
    {
        $this->redis_client->connect(self::HOST, self::PORT, function ($redis_client, $result) use ($id, $username) {
            if ($result === false) {
                var_dump($redis_client->connect_errno, $redis_client->connect_error);
                die;
            }
            var_dump('wawa');
            //设置值
            $redis_client->set('wawa', time(), function (swoole_redis $redis_client, $result){
                //设置是否成功的返回值
                var_dump($result);
            });
            //取值
            $redis_client->get('wawa', function (swoole_redis $redis_client, $result){
                var_dump($result);
            });
            //取所有值
            $redis_client->keys('*', function (swoole_redis $redis_client, $result){
                var_dump($result);
            });
            //模糊匹配KEY
            $redis_client->keys('*l*', function (swoole_redis $redis_client, $result){
                var_dump($result);
            });
            $redis_client->close();

        });
        return true;
    }

}

$ws = new AysRedis();
$result = $ws->execute(1, 'test');
print_r($result.PHP_EOL);
echo 'start:'.PHP_EOL;

swoole 异步redis

swoole 异步redis

reids官网的参数都可这样方式

相关文章:

  • 2021-09-18
  • 2021-09-02
  • 2021-12-03
  • 2021-11-19
  • 2019-06-03
  • 2021-12-10
  • 2021-11-23
  • 2021-11-13
猜你喜欢
  • 2021-11-20
  • 2019-01-25
  • 2021-04-26
  • 2021-07-15
  • 2021-05-19
  • 2021-09-11
  • 2021-06-25
相关资源
相似解决方案