Created
December 2, 2010 19:58
-
-
Save dhrrgn/725945 to your computer and use it in GitHub Desktop.
An Example on Redis Usage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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