Executing Redis commands in PHP
suggest changeThe phpredis extension exposes the Redis commands. $redis here is a connected Redis instance. get() returns a string, so the stored 123 comes back as "123". keys() returns key names, not values, and it scans the whole keyspace, so avoid it on a production server.
The calls follow the Redis command names:
// Creates two new keys:
$redis->set('mykey-1', 123);
$redis->set('mykey-2', 'abcd');
// Gets one value: string(3) "123"
var_dump($redis->get('mykey-1'));
// Returns the matching key names, such as "mykey-1" and "mykey-2".
// The order is not guaranteed.
var_dump($redis->keys('mykey-*'));
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents