Redis and its many uses
   Christian Joudrey - @cjoudrey
‘‘Redis is an open source,
 advanced key-value store.

                             ’’
Key-value what?!
SET name "fido"
GET name
=> "fido"
EXPIRE name 120
So it's like
memcached?
Atomic operations
SET count 0
INCR count
=> 1
Ordered lists
LPUSH friends "Tom"
LPUSH friends "Sam"
LLEN friends
=> 2
LPUSH           RPUSH

        Sam   Tom
LRANGE friends 0 0
=> ["Sam"]
LRANGE friends 0 -1
=> ["Sam", "Tom"]
Sets, Hashes,
 Sorted Sets
Save to disk
Download it
http://redis.io/download


... and try it ...
    $ redis-cli
    redis> SET name "Chris"
    OK
    redis> GET name
    "Chris"
What about node?!
GitHub
   http://git.io/redis

... or via npm ...
    $ npm install redis
Use case #1:
Caching
var redis = require('redis'),
    client = redis.createClient();

function getSomeValue (callback) {
   client.get('someVal', function (err, val) {
     if (val) return callback(null, val);
     // Do call directly to Db
     // and cache result.
   });
};
Use case #2:
Session store
var app = require('express').createServer();
var RedisStore = require('connect-redis')(express);

app.use(express.session({
     secret: 'keyboard cat', store: new RedisStore
}));

app.get('/', function(req, res){
  res.send('hello world');
});

app.listen(3000);




http://expressjs.com/guide.html#session-support
Use case #3:
Pub/Sub
Chat                Chat
Server              Server



          Load
         Balancer
Use case #4:
Job Queue
i.e.:
Image resize API
1) Download image
   2) Resize image with GD




            Node
            Server




GET /image_resize?url=http://...
orker                     Job
      Resize
                               Queue
      Workers




1) Download image              Node
2) Resize image with GD
                               Server




                   GET /image_resize?url=http://...
Kue
https://github.com/learnboost/kue
There's a lot more!
 11 Common Web Use Cases Solved in Redis
           http://bit.ly/pgDmXn
Questions? :)

Redis and its many use cases