我想知道我可以在php中获得$ 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;
答案 0 :(得分:0)
不确定你的意思 - 这很好用:
#!/usr/local/bin/php -f
<?php
$redis = new Redis();
$redis->connect('127.0.0.1',6379);
$key = "MyFunkyKey";
# Start with a clean slate
$res = $redis->del($key);
var_dump($res);
# LPUSH key twice
$res = $redis->lPush($key,1);
var_dump($res);
$res = $redis->lPush($key,1);
var_dump($res);
?>
示例输出
int(1)
int(1)
int(2)
这是我的版本信息:
$ pecl info redis
About pecl.php.net/redis-4.0.2
==============================
Release Type PECL-style PHP extension (source code)
Name redis
Channel pecl.php.net
Summary PHP extension for interfacing with Redis
Description This extension provides an API for communicating
with Redis servers.
Maintainers Nicolas Favre-Felix <n.favrefelix@gmail.com>
(lead)
Michael Grunder <michael.grunder@gmail.com>
(lead)
Pavlo Yatsukhnenko <p.yatsukhnenko@gmail.com>
(lead)
Release Date 2018-04-25 11:28:55
Release Version 4.0.2 (stable)
API Version 4.0.2 (stable)
License PHP (http://www.php.net/license)
Release Notes phpredis 4.0.2
This release contains only fix of exists method
to take multiple keys
and return integer value (was broken in 4.0.1)
Thanks @RanjanRohit!
Required Dependencies PHP version 5.3.0-7.9.99
PEAR installer version 1.4.0b1 or newer
package.xml version 2.0
Last Modified 2018-05-31 06:54
Previous Installed - None -
Version