当密钥存在时,phpredis rpop返回false

时间:2018-05-23 05:51:21

标签: php redis phpredis

我正在构建一个使用redis的游戏应用程序,这是我的php脚本。

<?php
//melon game pop

//connect to redis db
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);


//receive the data as json
//$data = json_decode(file_get_contents('php://input'), true);
$data = null;


//decided to just grab the string
$key = file_get_contents('php://input');

//Shotgun debugging in action
$my_key = trim($key);

/*
 was originally sending json on reading into variables from array decided to simplify until my issue is resolved
//parse my data in to separate variables  
if ($data != null) {
$key = $data['key'];
//$value = $data['value'];  

//$key = utf8_decode($key);        
}
else
{
print "It's not recognizing your data!";
}
*/




$my_echo = $redis->rpop($my_key);

 //it returns false if the key doesn't exist, but i've shown that it clearly exists so  why is it returning false???

if ($my_echo == false) {

print $my_key;
//print '5'.$key;

//print "5failure";

}
else
{
print $my_echo;
}
?>

我在上面的代码中发现的是游戏客户端将$ key发送到php并且我想要弹出存储在$ key下的值,在这种情况下是&#34; ubuntu5&#34;。在我的调试块中,当我打印$ my_key时,它会响应&#34; ubuntu5&#34;,所以我很难弄清楚为什么它不会打印存储在$ my_key下的值。 此外,当我从终端打开redis-cli并运行rpop&#34; ubuntu5&#34;它以预期值响应。

关于可能会发生什么的任何想法? {&#34; key&#34;:&#34; \ nubuntuleft22&#34; } 我使用了var_dump,并将其添加到脚本中:

$redis->lpush("my_control",$my_key);

当我弹出&#34; my_control&#34;我得到{&#34; key&#34;:&#34; \ nubuntuleft22&#34;使用浏览器从一个客户端和另一个客户端使用ubunturight22。当我从命令行手动弹出时,我得到以下内容:

redis-cli
127.0.0.1:6379> rpop my_control
"ubunturight22"
127.0.0.1:6379> rpop my_control
"{ \"key\": \"\\nubuntuleft23\" }"
127.0.0.1:6379> rpop "my_control"
"ubunturight23"
127.0.0.1:6379

0 个答案:

没有答案