鍍金池/ 問答/人工智能  PHP/ redis->lPush這個方法能拿到返回值么?

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;

             
回答
編輯回答
風(fēng)畔

Redis Lpush 命令將一個或多個值插入到列表頭部。會得到當(dāng)前鍵下有多少個數(shù)據(jù)的數(shù)量

2017年10月25日 11:10
編輯回答
獨白

如果你是直接使用redis,而不是php-redis的話,根據(jù)https://redis.io/commands/lpush
Return: the length of the list after the push operations,你會得到當(dāng)前l(fā)ist的長度

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

如果你使用的是php的redis擴展庫,php-redis,也同樣會得到一樣的結(jié)果,你會得到當(dāng)前l(fā)ist的長度

$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' ] */

如果你確實沒有獲得相關(guān)的值,你不如貼上你的相關(guān)代碼

2018年3月21日 23:02
編輯回答
大濕胸

通常來說,應(yīng)該會返回一個整型的值,也就是列表的長度,如果什么都沒有,我建議你:

try {
    $redis->lPush();
} catch(\Exception $e) {
    var_dump('異常:' . $e->getMessage);
} catch(\Error $e) {
    var_dump('錯誤:' . $e->getMessage);
}
2017年12月20日 13:43