Redis

1,270 views

Published on

Published in: Technology

Redis

  1. 1. Redis
  2. 2. Redis is...an “advanced key- value store ”
  3. 3. NoSQL?An informal, loosely-defined term for non-relational, structured data storage systems like mongodb, couchdb, memcached and redis
  4. 4. memcached The canonically simple examplea networked “hash in the sky” behind a simple protocol Values page:index.html <html><head>[...] user:123:session xDrSdEwd4dSlZkEkj login_count “7464” user:100:last_login_time “102736485756” Everything’s a string (or a “blob”) Commands just set or get data (mostly)
  5. 5. Take memcached’s simplicity, Add more data types, Add persistence, Add more commands, .. and more Redis
  6. 6. Redis Data Types Strings Lists SetsSorted/Scored sets Hashesall accessed by a string key
  7. 7. Redis Data ExamplesKeys ValuesPage:index.html <html><head>[..]StringLogin_count 3121Users_logged_in_today {1,2,3,4,5}SetLatest_post_ids *201,204,209,…+listUser:123:session Time=>1092313 hash Username=>arildUsers_and_ratings biobot~ 1.3483 sorted (scored) set blast~ 93.4 ahriman~ 283.22 blabla~ 23774.17
  8. 8. Strings
  9. 9. Expiration
  10. 10. Deleting keys
  11. 11. Lists
  12. 12. Lists
  13. 13. Queues
  14. 14. Sets
  15. 15. Sets
  16. 16. Sorted sets? Sorry – no timeBasically like normal sets but each element can have a “rank” or “score” and be returned or sorted by it
  17. 17. Hashes
  18. 18. Session storage
  19. 19. Redis Social Network Usershave names, can follow others, can be followed Posts are things like messages, photos, etc
  20. 20. Building a unique names with colons like user:1:name Is just a convention any string win do…
  21. 21. A Simple Social Network
  22. 22. Unique IDs
  23. 23. Creating new userCreating new post
  24. 24. Enough commands!I havent covered them all though…. On to the soft issues….
  25. 25. AtomicityRedis is single threaded No locking necessary In other words, commands like INCR won’t tread on each other’s toes coming from multiple clients simultaneously!
  26. 26. Replication• supports master-slave replication• a single-rooted replication tree• a slave may be a master to another slave
  27. 27. Redis Factoids BSD licensed (free, open) Sponsored by Vmware Written in ANSI C Good community (list, IRC & wiki)Works on all POSIX-complaint UNIXes
  28. 28. PerformanceDepends a lot on configuration and operation complexity.Common range from 5000 to120,000 rps for basic ops. GET/SET/LPUSH/LPOP, etc. (ultra low end to high end hardware) comparison with other no-sql implementationshttp://kkovacs.eu/cassandra-vs-mongodb-vs-couchdb-vs-redis
  29. 29. PersistenceDump data to disk after certain conditions are met. Or manually.  SAVE and BGSAVE commands AND/OR An append only log file (which can be optimized/rebuid automatically) but needed to set this up in a config file
  30. 30. Language SupportRuby, Python, PHP, Erlang,Tcl, Perl, Lua, Java, Scala,Clojure,C#, C/C++,JavaScript/Node.js, Haskell,IO, Go
  31. 31. Missed a lot, now where? Google “redis”for the great official site http://www.redis.io

×