Skip to content

Instantly share code, notes, and snippets.

@dhrrgn
Created December 2, 2010 19:58
Show Gist options
  • Save dhrrgn/725945 to your computer and use it in GitHub Desktop.
Save dhrrgn/725945 to your computer and use it in GitHub Desktop.
An Example on Redis Usage
<?php
namespace Fuel\Application;
class Controller_Test extends Controller\Base {
public function action_index()
{
// You can access it this way
Redis::instance()->set('username', 'Dan');
echo Redis::instance()->get('username');
// Or this way
$redis = Redis::instance();
$redis->set('username', 'Dan');
echo $redis->get('username');
// Or this way (connecting to a second server). config held in config/db.php
$redis = Redis::instance('site2');
$redis->set('username', 'Dan');
echo $redis->get('username');
// A more complex example
$redis = Redis::instance();
$redis->rpush('particles', 'proton');
$redis->rpush('particles', 'electron');
$redis->rpush('particles', 'neutron');
$particles = $redis->lrange('particles', 0, -1);
$particle_count = $redis->llen('particles');
echo "<p>The {$particle_count} particles that make up atoms are:</p>";
echo "<ul>";
foreach ($particles as $particle) {
echo "<li>{$particle}</li>";
}
echo "</ul>";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment