$30 off During Our Annual Pro Sale. View Details »

Redis for fun and profit

mattg
August 25, 2012

Redis for fun and profit

A simple overview of redis

mattg

August 25, 2012
Tweet

More Decks by mattg

Other Decks in Technology

Transcript

  1. Redis
    matt george 8/25/2012
    Saturday, August 25, 12

    View Slide

  2. @binarydud
    http://github.com/binarydud/redis-fun
    Saturday, August 25, 12

    View Slide

  3. Redis is not ...
    Saturday, August 25, 12

    View Slide

  4. Redis is not ...
    a replacement for your database.
    or necessarily fault tolerant.
    Saturday, August 25, 12

    View Slide

  5. WTF
    Saturday, August 25, 12

    View Slide

  6. what is it?
    Saturday, August 25, 12

    View Slide

  7. Key-Value Store
    Saturday, August 25, 12

    View Slide

  8. Key-Value Store
    Data Structure Server
    Saturday, August 25, 12

    View Slide

  9. why?
    Saturday, August 25, 12

    View Slide

  10. if you...
    need key value store that’s very fast.
    have a dataset that can fit into ram.
    are ok if not everything survives.
    Redis is very interesting!
    Saturday, August 25, 12

    View Slide

  11. Data structure basics
    Saturday, August 25, 12

    View Slide

  12. Strings
    Saturday, August 25, 12

    View Slide

  13. String Basics
    SET key value
    GET key
    SETEX key seconds value
    APPEND key value
    Saturday, August 25, 12

    View Slide

  14. redis>get hello
    (nil)
    redis> set hello world
    OK
    redis>get hello
    “world”
    String Basics
    Saturday, August 25, 12

    View Slide

  15. String Basics
    INCR key
    DECR key
    INCRBY key value
    DECRBY key value
    Saturday, August 25, 12

    View Slide

  16. String Basics
    redis>incr stat1
    1
    redis> incrby stat1 2
    3
    redis> decr stat1
    2
    redis> get stat1
    2
    Saturday, August 25, 12

    View Slide

  17. String Patterns
    session handling
    caching
    counter/stats
    Saturday, August 25, 12

    View Slide

  18. Lists
    Saturday, August 25, 12

    View Slide

  19. Lists
    LPUSH key value
    (B)LPOP key
    LRANGE key start stop
    LLEN key
    LSET key index value
    LINDEX key index
    Saturday, August 25, 12

    View Slide

  20. List Patterns
    stacks
    queues
    message passing
    Saturday, August 25, 12

    View Slide

  21. Sets
    Saturday, August 25, 12

    View Slide

  22. Sets
    SADD key member
    SREM key member
    SISMEMBER key member
    SMEMBERS key
    SCARD key
    Saturday, August 25, 12

    View Slide

  23. Hashes
    Saturday, August 25, 12

    View Slide

  24. Hashes
    HSET key field value
    HDEL key field
    HKEYS keys
    HLEN key
    HGETALL key
    Saturday, August 25, 12

    View Slide

  25. Other Interesting Commands
    KEYS pattern
    DEL key
    RENAME key newkey
    EXISTS key
    EXPIRE key
    PERSIST key
    Saturday, August 25, 12

    View Slide

  26. Pub/Sub
    Saturday, August 25, 12

    View Slide

  27. Pub/Sub
    SUBSCRIBE channel ...
    UNSUBSCRIBE channel ...
    PUBLISH channel message
    Saturday, August 25, 12

    View Slide

  28. Administration
    Saturday, August 25, 12

    View Slide

  29. Persistence
    AOF
    Snapshots
    Saturday, August 25, 12

    View Slide

  30. Replication
    master/slave
    slave chaining
    Saturday, August 25, 12

    View Slide

  31. Server Commands
    redis> BGREWRITEAOF
    redis> BGSAVE
    redis> DBSIZE
    redis> INFO
    redis> FLUSHALL
    redis> SLAVEOF host port
    Saturday, August 25, 12

    View Slide

  32. Benchmarks
    SET: 47709.93 requests per second
    GET: 49900.20 requests per second
    INCR: 47801.15 requests per second
    LPUSH: 49188.39 requests per second
    LPOP: 48355.90 requests per second
    SADD: 46970.41 requests per second
    SPOP: 50581.69 requests per second
    LPUSH: 47755.49 requests per second
    Saturday, August 25, 12

    View Slide

  33. Demo Time
    aka, watch Matt flail in the command line
    Saturday, August 25, 12

    View Slide

  34. Caveats
    Saturday, August 25, 12

    View Slide

  35. Questions?
    http://redis.io
    Saturday, August 25, 12

    View Slide