Top Banner
9th July 2015 An introduction to Redis by Romain Francez
17
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Steam Learn: An introduction to Redis

9th July 2015

An introduction to Redisby Romain Francez

Page 2: Steam Learn: An introduction to Redis

9th July 2015

Redis

“An in memory non relational database”

“Memcached but better”

“A data structure server”

Page 3: Steam Learn: An introduction to Redis

9th July 2015

Redis is Simple

● Works out of the box○ No schema○ No user○ Default config works just fine

Page 4: Steam Learn: An introduction to Redis

9th July 2015

Redis is Simple

● Key/Value Store

● Simple operations○ Usually get/set with variations

Page 5: Steam Learn: An introduction to Redis

9th July 2015

Redis is Flexible

● Data types○ Bitmaps○ Hashes○ HyperLogLogs

■ Probabilistic data structure to estimate the cardinality of a set■ Memory efficient

○ Keys■ Yes, also a type■ Anything binary safe (like the content of an image)

○ Lists○ Sets○ Sorted Sets○ Strings

Page 6: Steam Learn: An introduction to Redis

9th July 2015

Redis is Flexible

● Configuration○ Store denormalised data you can afford to lose?

■ By default in memory + snapshot on the disk■ Disable the disk writes

○ Use it as a cache?■ Use a LRU (Least Recently Used) memory policy

Page 7: Steam Learn: An introduction to Redis

9th July 2015

Redis is Flexible

● Custom functions with lua● Transactions

○ If you need them

● Pub/Sub○ Isn’t even related to the key space

Page 8: Steam Learn: An introduction to Redis

9th July 2015

Redis is Scalable

● High Availability with Sentinel○ Configuration based

● Most operations are O(1)○ But some have high constant time (See some Hyperloglogs commands)

● Non relational database○ No problems related to scaling relations across servers

● Partitioning○ With limitations

Page 9: Steam Learn: An introduction to Redis

9th July 2015

Redis Use Cases

“So basically I can do everything and anything with Redis?”

Page 10: Steam Learn: An introduction to Redis

9th July 2015

Widely adopted

● GitHub○ Routing, queue, config management

● Instagram○ Mapping photos with the user that created them○ Needs the persistence of data on disk○ Advanced usage of hashes

● StackOverflow○ Cache

● Twitter○ Timeline (tweets ordered by ids), ads○ On disk features not used○ Added custom data types

● Your favorite video site○ Hint: not YouTube○ Sorted sets and hashes○ Kept MySQL, but no reads from it: use it to populate Redis

Page 11: Steam Learn: An introduction to Redis

9th July 2015

Other Usages

● Autocomplete● Search engine● Distributed locking● Session management● Leaderboards

Page 12: Steam Learn: An introduction to Redis

9th July 2015

Leaderboard Example> ZADD leaderboard 13 "Cold" 22 "Cindy" 7 "mymo" 20 "herrrox" 15

"Dreaty" 4 "cqnqr"

(integer) 6

> ZREVRANGE leaderboard 0 2 WITHSCORES

1) "Cindy"

2) "22"

3) "herrrox"

4) "20"

5) "Dreaty"

6) "15"

> ZRANGE leaderboard 0 0 WITHSCORES

1) "cqnqr"

2) "4"

Page 13: Steam Learn: An introduction to Redis

9th July 2015

Leaderboard Example> ZINCRBY leaderboard 20 "cqnqr"

"24"

> ZREVRANK leaderboard "cqnqr"

(integer) 0

Page 14: Steam Learn: An introduction to Redis

9th July 2015

Leaderboard Example> ZCARD leaderboard

(integer) 6

> ZADD leaderboard 7 "BaDy"

(integer) 1

> ZCARD leaderboard

(integer) 7

> ZREM leaderboard "mymo"

(integer) 1

> ZCARD leaderboard

(integer) 6

Page 15: Steam Learn: An introduction to Redis

9th July 2015

Conclusion

● Redis can be used for any of your needs○ You might have to get into advanced stuff though

● Handles well lots of data

Page 16: Steam Learn: An introduction to Redis

9th July 2015

Thanks

Any questions ?

Page 17: Steam Learn: An introduction to Redis

9th July 2015

Join the community !(in Paris)

Social networks :● Follow us on Twitter : https://twitter.com/steamlearn● Like us on Facebook : https://www.facebook.com/steamlearn

SteamLearn is an Inovia initiative : inovia.fr

You wish to be in the audience ? Join the meetup group! http://www.meetup.com/Steam-Learn/