Using Redis to save sessions
Redis is a popular key/value data store and is quite fast. Laravel includes Redis support, and makes it easy to interact with the Redis data.
Getting ready
For this recipe, we'll need to have a Redis server properly configured and running. More information on that can be found at http://redis.io/.
How to do it...
Follow these steps to complete this recipe:
In our
routes.php
file, create the routes as given in the following code:Route::get('redis-login', function() { return View::make('redis-login'); }); Route::post('redis-login', function() { $redis = Redis::connection(); $redis->hset('user', 'name', Input::get('name')); $redis->hset('user', 'email', Input::get('email')); return Redirect::to('redis-view'); }); Route::get('redis-view', function() { $redis = Redis::connection(); $name = $redis->hget('user', 'name'); $email = $redis->hget('user', 'email'); echo 'Hello ' . $name . '. Your email is ' . $email; });
In the
views
directory,...