Your SlideShare is downloading. ×
Redis - The Universal NoSQL Tool
Nächste SlideShare
Wird geladen in ...5

Thanks for flagging this SlideShare!

Oops! An error has occurred.

Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Redis - The Universal NoSQL Tool


Published on

Presentation about Redis from WJAX 2012

Presentation about Redis from WJAX 2012

0 Kommentare
3 Gefällt mir
  • Hinterlassen Sie den ersten Kommentar

Keine Downloads
Bei Slideshare
Aus Einbettungen
Anzahl an Einbettungen
Gefällt mir
Einbettungen 0
No embeds

Inhalte melden
Als unangemessen gemeldet Als unangemessen melden
Als unangemessen melden

Wählen Sie Ihren Grund, warum Sie diese Präsentation als unangemessen melden.

No notes for slide


  • 1. Redis: The Universal NoSQL- Tool Eberhard WolffArchitecture and Technology Manager adesso AG
  • 2. NoSQL is allabout Big Data
  • 3. NoSQL is allabout Big Data
  • 4. Redis•  Remote Dictionary Server•  Advanced Key Value Store•  Actually also a cache and a messaging server•  Open Source – free to change the code•  Sponsored by VMware•  No commercial agenda•  Implemented in C (actually pretty small)•  In memory (fast)
  • 5. Redis•  Data should fit in memory•  Data written asynchronously to disk or in an append only file –  Wont slow down operations –  Configurable delay•  Bindings for many languages•  Very easy replication•  i.e. like an in-memory cache with persistence option•
  • 6. How to Use Redis•  Very simple protocol•  Can telnet to it•  Libraries for lots of languages•  Java: –  Jedis –  JRedis –  RJC•  Spring Data Redis as abstraction –  Uniform concepts (e.g. templates) across all NoSQL and SQL stores –  Even JPA –  Exception translation –  Still exposes unique features
  • 7. Use Case: High Scores for Players•  Online game•  Store high scores•  High data volume•  Frequently changing data
  • 8. Use Case: High Scores for Players•  Note: Other data (name, email, etc) can still be stored somewhere else•  Key: Name of player•  Value: Score•  Encoded as bytes•  Operations: GET, SET, DEL
  • 9. Demo: RedisWriter /RedisMultiWriter / RedisClean / redis-cli / telnet / redis- benchmark
  • 10. Points to Note•  Extremely fast•  See•  Multi Set: Can issue multiple set operations in one round trip for very high performance•  Data in database does not impact performance•  Data written asynchronously•  Not shown: –  APPEND : append data to a key –  KEYS : find all keys for a pattern –  RENAME : Change key
  • 11. Redis as a Cache•  Data kept in memory•  …and on disk•  Data survives restarts•  No need for the cache to warm up•  But: What about evicting data from the cache?•  Solution: Data can have time-to-live•  Can set global memory policy to avoid excessive memory consumption•  Let assume certain texts (e.g. HTML) should be cached for our application…
  • 12. Demo: RedisCache
  • 13. Create Unique Player ID•  Each player should have a unique ID•  Needs to be unique, even in a cluster•  Solution: atomic incr operation•  i.e. works correctly even if multiple threads access the counter at the same time•  Quick – in memory
  • 14. Demo: RedisCreateID
  • 15. Similar operations•  GETSET : Atomically get old value and set to new value•  Global locks using SETNX / DEL•  SETNX returns true only if the client successfully set the value•  i.e. lock was successfully acquired
  • 16. Replication•  Redis uses master / slave replication•  Slaves can replicate to other slaves•  Replication does not block the master•  Useable for scalability of reads or data redundancy•  Write would go to the master and be propagated•  Make backups quite easy•  Just add slaveof <ip> <port> to redis.conf
  • 17. Scaling•  Slaves can be used for (eventually consistent) reads•  Storage to disk can be offloaded to slaves•  No more breaks during disk writes•  But: Only one master can write•  Still: All data should fit in RAM
  • 18. Scaling•  Can use Virtual Memory•  Redis has its own Virtual Memory implementation (to be deprecated)•  Partially implemented: Redis Cluster with Master / Slave replication•  Sharding i.e. data distributed across many nodes•  Could implement your own sharding on the client
  • 19. Redis Data Types•  So far: Simple types: byte[] –  String and numbers encoded as byte[] –  Can cluster multiple get/set into one atomic action•  Atomic increment / decrement for integers•  Lists –  Can add / remove atomically•  Sets –  Like lists but no order•  Sorted sets –  Each element has a score to sort by
  • 20. Highscores•  Range the high scores•  Solutions: Use a sorted set•  Result: scores automatically sorted•  Trivial to get the top high scores
  • 21. Demo: RedisHighScore
  • 22. Sending EMails•  EMails should be sent by a server•  Need to queue emails•  Solution: Use a list + push / pop
  • 23. Demo: RedisEMailReaderList / RedisEMailWriterList
  • 24. Next step: Messaging•  Lists are not really designed for communication•  Message driven middleware is an established concept•  Redis has some parts•  Topics –  Have a name –  Multiple receivers can listen to it•  Subscribe to –  A Topic –  Or a patterns of topic names
  • 25. Demo:RedisEMailReaderMessaging / RedisEMailWriterMessaging
  • 26. Transactions•  Multiple actions can be put into a transaction•  Command MULTI to start transaction•  EXEC to execute•  DISCARD to discard•  Guarantees: –  Executed in the defined order –  Atomic (all or nothing) –  No isolation –  Can use optimistic locking
  • 27. Key-Value Stores: Store Complex Data•  Storing data as serialized blobs / JSON / XML –  ”player:wolff" è ”all the data"•  Storing data as multiple keys –  "player:wolff:score" è 42 –  "player:wolff:email" è ”"•  Requires multi get/set to be efficient•  Can find all keys using patterns•  Can create your custom Serializer in Spring Data•  Key / values stores are no really useful for complex data
  • 28. Conclusion – Redis is a Swiss Knife•  Very fast - In Memory•  Cache + persistence•  Messaging•  Centralized locking and counting•  Much more than just persistence•  Not shown: Lua scripting•  Not useful for –  Big Data –  Seamless scaling –  Ad hoc queries•  Will not be the only data store you use
  • 29. Links••  Try it yourself:•  Spring Data Redis•  Demos:•  Who is using it?•  Books –  Tiago Macedo, Fred Oliveira: Redis Cookbook –  Pollack, Gierke, Risberg, Brisbin, Hunger: Spring Data