php - 当密钥存在时,phpredis rpop 返回 false
问题描述
我正在构建一个使用 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 下的值,在这种情况下是“ubuntu5”。在我的调试块中,当我打印 $my_key 时,它以“ubuntu5”响应,所以我很难弄清楚为什么它不会打印存储在 $my_key 下的值。此外,当我从终端打开 redis-cli 并运行 rpop "ubuntu5" 时,它会以预期值响应。
关于这里可能发生什么的任何想法?{ "key": "\nubuntuleft22" } 我使用了 var_dump,并将其添加到脚本中:
$redis->lpush("my_control",$my_key);
当我弹出“my_control”时,我从一个客户端获得 { "key": "\nubuntuleft22" },而使用浏览器从另一个客户端获得 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
解决方案
推荐阅读
- c - 使用 CMake 测试 GSL 时 CBLAS 中的未定义引用
- mongodb - MongoDB,按经常更新的字段对大集合进行排序
- matlab - 将双曲 Poincare 圆盘转换为能带模型
- java - 如何在按钮之外访问所选文件的文件路径?
- python - 如何对数组中的范围值求和,其中每行都有不同的范围
- java - 是否可以在使用 `startActivityForResult` 的线程中捕获 Intent 或任何其他类型的“消息”?
- java - 如何使用 Apache Kafka 在 Spring Boot 中使用和保存自定义类型列表?
- android - 布局预览中未显示图像
- powershell - Invoke-Command 未到达 catch 块
- angular - 如何使用 Angular Material 从子组件使用 Angular 路由