Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Redis

 Redis

Introduction to Redis including use cases, simple explanations to get started and examples on the use of the most important data structures

Miguel Cordova

April 16, 2020
Tweet

More Decks by Miguel Cordova

Other Decks in Programming

Transcript

  1. REDIS HISTORY 2 Ø Developers: Salvatore Sanfilippo, Pieter Noordhuis Ø

    Initial release: April 10, 2009 Ø Stable release: 5.0 October 2018 Ø Written in C
  2. REDIS WHAT IS IT? Redis is an open source (BSD

    licensed), in-memory, NoSQL data structure store, frequently used as: Ø Database Ø Cache Ø Message Broker Source: redis.io
  3. REDIS SUPPORTED DATA STRUCTURES Redis is more than a key-value

    NoSql store. In fact, it is better to think of Redis as a data structure store. Redis supports these data structures: Ø Strings Ø Bitmaps Ø Lists Ø Sets Ø Sorted sets Ø Hashes Ø HyperLogLogs Ø Geospatial Indexes
  4. REDIS KEY FEATURES 5 Ø Speed: It loads up to

    110,000 SETs/second and 81,000 GETs/second can be achieved in an entry level Linux box. Ø Persistence Ø Atomic Operations Ø Master/Slave Replication Ø Cluster Ø Operating System: “Cross-Platform”
  5. REDIS ADVANTAGES & DISADVANTAGES 7 Ø Some of Advantages •

    Incredibly Fast. • Robust. • Easy to setup, use and maintain. Ø Some of Disadvantages • Persistence affects performance. • Single-thread. • Lack of UI.
  6. 1. CACHING Load data from slower data sources into Redis

    and provide near- instant response times. Redis keeps data in random access memory (RAM) to make retrieval fast.
  7. 2. USE IT FOR SESSION STORAGE Redis is an excellent

    fit for session storage due to its native data-type storage (Hash) that mirrors the kind of storage needed for storing session data.
  8. 3. REAL TIME LEADERBOARDS Sorted sets in Redis are a

    perfect fit for implementing a leaderboard, which has made Redis a popular choice for many gaming applications.
  9. 6. USER RECOMMENDATIONS Using Sets and its commands we can

    intersect different entries to provide user recommendations. If a user previously liked or bought an article with the three tags (1,2,3); we can now find which other articles have the same three tags.
  10. DEMO TIME $ docker run -d -p 6379:6379 --name redis-demo

    redis $ docker exec -it redis-demo sh # redis-cli
  11. TRY IT YOURSELF strings set student miguel get student set

    student:1 sergio get student:1 keys * set color red keys stu* set student:2 john ex 25 get student:2 ttl student:2 exists student:2 lists lpush numbers 1 2 3 lrange numbers 0 3 rpush numbers 4 lrange numbers 0 -1 llen numbers lpop numbers rpop numbers sets sadd colors blue white blue smembers colors scard colors sadd colors2 blue red sdiff colors colors2 sorted sets zadd leaderboard 1 teama 2 teamb zrange leaderboard 0 -1 withscores zrank leaderboard teama zscore leaderboard teama zrem leaderboard teamc
  12. TRY IT YOURSELF hash hset users login cordomig hget users

    login hkeys users geospatial geoadd cars -100 30 mycar geoadd cars -110.1 50 yourcar geodist cars mycar yourcar georadius cars -115 40 100000000 m pub/sub (open 2 terminals) subscribe weather publish weather hi user recommendations sadd article:3 tag:1 tag:2 tag:3 sadd tag:1 article:3 article:4 article:5 sadd tag:2 article:3 article:7 article:5 sadd tag:3 article:3 article:8 article:5 sinter tag:1 tag:2 tag:3
  13. RESOURCES Do You Really Know Redis? https://redislabs.com/docs/really-know-redis/ 15 Reasons to

    Use Redis as an Application Cache https://redislabs.com/docs/15-reasons-caching-is-best-done-with-redis/ Redis for Geospatial Data https://redislabs.com/docs/redis-for-geospatial-data/ Redis for Dummies https://redislabs.com/redis-for-dummies/ Introduction to Redis https://www.linkedin.com/learning/learning-redis