Redis client


Description


The Redis class provides a simple and consistent way of communicating with a Redis server.


Methods


__construct([string $name = null])


You create a Redis object by using the constructor. Use the optional name parameter if you don't want to create an object using the default Redis configuration.


// Create an object using the default configuration

$redis = new Redis();

// Create an object using the 'my_other_server' configuration

$redis = new Redis('my_other_server');

factory([string $name = null])


The factory method returns a Redis object. This allows you to chain methods.


Redis::factory()->get('key');

Examples


The Redis class uses the magic __call method so every valid Redis command is a valid method.


$redis = new Redis();

// Add some dummy data

$redis->rpush('drinks', 'water');
$redis->rpush('drinks', 'milk');
$redis->rpush('drinks', 'orange juice');

// Prints out a list of drinks

echo HTML::ol($redis->lrange('drinks', 0, -1));

// Delete data

$redis->del('drinks');

There is also a magic shortcut that can be used to access the default configuration. Every valid Redis command is a valid method.


Redis::set('foo', 'bar');

echo Redis::get('foo');

Redis::del('foo');