redis->lPush这个方法能拿到返回值么?

redis->lPush这个方法能拿到返回值么?
打印了一下,好像什么都没有

             $id = $this->post('id');
             $info = $this->PushModel->getPush($id);

             if(empty($info)){
                 $this->json(Constant::FAILURE);
             }

             $gameId = $info['game_id'];
             $title = $info['title'];
             $content = $info['content'];
             $pushInfo = "$id|$gameId|$title|$content";

             $redis = $this->redis();
             $ret = $redis->connect(REDIS_HOST, ZGH_REDIS_PORT);

             $res = $redis->lPush(REDIS_HRGAME_PUSH_BATCH_KEY,$pushInfo);

             print_r($ret);
             print_r($res);exit;

             
阅读 7.3k
3 个回答

如果你是直接使用redis,而不是php-redis的话,根据https://redis.io/commands/lpush
Return: the length of the list after the push operations,你会得到当前list的长度

redis> LPUSH mylist "world"
(integer) 1
redis> LPUSH mylist "hello"
(integer) 2

如果你使用的是php的redis扩展库,php-redis,也同样会得到一样的结果,你会得到当前list的长度

$redis->delete('key1');
$redis->lPush('key1', 'C'); // returns 1
$redis->lPush('key1', 'B'); // returns 2
$redis->lPush('key1', 'A'); // returns 3
/* key1 now points to the following list: [ 'A', 'B', 'C' ] */

如果你确实没有获得相关的值,你不如贴上你的相关代码

Redis Lpush 命令将一个或多个值插入到列表头部。会得到当前键下有多少个数据的数量

通常来说,应该会返回一个整型的值,也就是列表的长度,如果什么都没有,我建议你:

try {
    $redis->lPush();
} catch(\Exception $e) {
    var_dump('异常:' . $e->getMessage);
} catch(\Error $e) {
    var_dump('错误:' . $e->getMessage);
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题