forge($name = 'default', $config = array())
Create a new named redis instance, optionally with a custom configuration
Static | Yes | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
パラメータ |
|
|||||||||
返り値 | Fuel\Core\Redis Object | |||||||||
例 |
|
The Redis class allows you to interact with a Redis key-value store.
Create a new named redis instance, optionally with a custom configuration
Static | Yes | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
パラメータ |
|
|||||||||
返り値 | Fuel\Core\Redis Object | |||||||||
例 |
|
Return a named instance that was created earlier.
Static | Yes | ||||||
---|---|---|---|---|---|---|---|
Parameters |
|
||||||
Returns | Fuel\Core\Redis Object | ||||||
Example |
|
Once you have created a redis object using the instance() method, every valid redis command (see the Redis Documentation) as a method of that object.
Some examples:
// create the Redis 'mystore' instance
$redis = Redis::forge('mystore');
// create some test data
$redis->rpush('particles', 'proton');
$redis->rpush('particles', 'electron');
$redis->rpush('particles', 'neutron');
// fetch the range
$particles = $redis->lrange('particles', 0, -1);
// count the number of elements
$particle_count = $redis->llen('particles');
// display the results
echo "<p>The {$particle_count} particles that make up atoms are:</p>";
echo "<ul>";
foreach ($particles as $particle) {
echo "<li>{$particle}</li>";
}
echo "</ul>";
You can add multiple Redis commands into a command pipeline, and execute them all at once.
An example:
// create the Redis 'mystore' instance
$redis = Redis::forge('mystore');
// pipeline some redis commands, then execute them
$result = $redis->pipeline()
->sadd('list', 4)
->sadd('list', 1)
->sadd('list', 55)
->execute();