I using Phpredis and am trying to get information from the following key called "statHistory" I am new to redis and not sure how to call each value individually. I am able to connect to redis using php and have tested it using the ping command. It has been two days of testing and I still cant get it to call properly. If anyone could point me in the right direction I would greatly appreciate it.
Key Name: statHistory
http://pastebin.com/pXz5d0zf
image of redis-commander

Dani AI

Generated

Short answer: verify the key exists in the same Redis database and read it according to its type. As can already connect/ping and as observed, the snapshot you linked looks like it doesn’t show a key named statHistory. Common causes are using the wrong DB index in your client, invisible characters in the key name, or the key being a non-string type (hash, list, set, zset).

Use phpredis to check existence, type, then fetch with the matching API. Example pattern:

$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
$redis->select(0); // make sure this matches redis-commander

$key = 'statHistory';

if (! $redis->exists($key)) {
    echo "Key not found — try scanning for similar names or check DB index\n";
    $it = null;
    while ($keys = $redis->scan($it, 'stat*')) {
        foreach ($keys as $k) echo $k . PHP_EOL;
    }
    exit;
}

$type = $redis->type($key);

switch ($type) {
  case Redis::REDIS_STRING: $value = $redis->get($key); break;
  case Redis::REDIS_HASH:   $value = $redis->hGetAll($key); break;
  case Redis::REDIS_LIST:   $value = $redis->lRange($key, 0, -1); break;
  case Redis::REDIS_SET:    $value = $redis->sMembers($key); break;
  case Redis::REDIS_ZSET:   $value = $redis->zRange($key, 0, -1, true); break;
}
var_dump($value);

Troubleshooting notes: don’t use KEYS * in production (use SCAN as shown). Confirm the DB number in redis-commander matches the one your script selects. Watch for leading/trailing whitespace or non-printable characters in the key name (try pattern scans). If the returned value looks like PHP serialization or JSON, decode it before use. If the above still returns nothing, inspect with redis-cli (same DB) to rule out client/namespace mismatches.

Member Avatar for Member #120589

There is no key called statHistory in the data. Or am I missing something?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.