- PHP 7.4+
- PhpRedis extension (More connection schemes will be available in the future)
pinggetsetappenddelunlinkex
ixIndicates the command should be executed when source does existnxIndicates the command should be executed when source does NOT existjsonTransforms the value to store in Redis in a json string format, or transform a received json string to a PHP objectexecExecutes command
Client options is not required as all important options have a default
- Create a client
use Dodo\Redis\RedisClient;
$redis = new RedisClient([
"scheme" => "redis",
"host" => "...",
"port" => "...",
"debug" => true
]);- Set command in combination with expiry time
$redis->set("test", "this is a test")
->ex(2) // Expire in 2 seconds
->exec();
$query = $redis->get("test")
echo $query->get(); // 'this is a test'
sleep(2);
$query = $redis->get("test")
echo $query->get(); // Throws an error because the query response is a boolean: falsenxandixcommands
$redis->set("test", "this is a test")->exec();
$redis->set("test", "this is NOT a test")
->nx() // If 'test' does not exist
->exec();
$query = $redis->get("test")
echo $query->get(); // 'this is a test'
$redis->set("test", "this is a NOT test")
->ix() // If 'test' does exist
->exec();
$query = $redis->get("test")
echo $query->get(); // 'this is NOT a test'- Command with JSON
$redis->set("test", array(
"id" => uuid_create()
))
->json() // JSON stringyfies sent data
->ex(10)
->exec();
$query = $redis->get("test")
->json() // JSON decodes retrieved data
->exec();
$object = $query->get();
echo $object->id;