RedisAsynPool

异步redis连接池

示例:

$this->redis_pool->hMGet(’test',[1,2,3,4], function ($uids) {
});

协程模式

        $this->redis_pool->getCoroutine();

这个函数在注释中表示返回的是\Redis扩展的一个抽象类其实返回的是一个迭代器,我们只需要他的代码提示,1.7版本已经将同步和异步的使用方式做了完全的统一,和\Redis扩展的用法完全一致。

示例:

        $mySqlCoroutine = $this->mysql_pool->dbQueryBuilder->select('*')->from('account')->where('uid', 10303)->coroutineSend();
        $mysql_result = yield $mySqlCoroutine;
        $redisCoroutine = $this->redis_pool->getCoroutine()->get('test');
        $redis_result = yield $redisCoroutine;

使用协程会大大简化代码的书写,提高代码的可读性。 上面的代码通过yield关键字返回了异步回调的值。 执行顺序 mysql_send->mysql_rev->redis_send->redis_rev;

        $mySqlCoroutine = $this->mysql_pool->dbQueryBuilder->select('*')->from('account')->where('uid', 10303)->coroutineSend();       
        $redisCoroutine = $this->redis_pool->getCoroutine()->get('test');
        $mysql_result = yield $mySqlCoroutine;
        $redis_result = yield $redisCoroutine;

执行顺序 mysql_send->redis_send->mysql_rev->redis_rev;

results matching ""

    No results matching ""