I'm building a game application that uses redis and this is my php script.
<?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;
}
?>
What I have going on in the above code is a game client sends $key to php and I want to pop the value stored under $key which in this case was "ubuntu5". In my debug block when I print $my_key it responds with "ubuntu5", so I'm struggling to figure out why it won't print the value stored under $my_key. Furthermore, when I open redis-cli from the terminal and run rpop "ubuntu5" it responds with the expected value.
Any ideas on what could be going on here? { "key": "\nubuntuleft22" } I used var_dump, and also added this to the script:
$redis->lpush("my_control",$my_key);
When I pop "my_control" I get { "key": "\nubuntuleft22" } from one client and just ubunturight22 from the other using a browser. When I manually pop from the command line I get the below:
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