steam learn: an introduction to redis

17
9th July 2015 An introduction to Redis by Romain Francez

Upload: inovia

Post on 07-Aug-2015

118 views

Category:

Software


0 download

TRANSCRIPT

9th July 2015

An introduction to Redisby Romain Francez

9th July 2015

Redis

“An in memory non relational database”

“Memcached but better”

“A data structure server”

9th July 2015

Redis is Simple

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

9th July 2015

Redis is Simple

● Key/Value Store

● Simple operations○ Usually get/set with variations

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

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

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

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

9th July 2015

Redis Use Cases

“So basically I can do everything and anything with 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

9th July 2015

Other Usages

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

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"

9th July 2015

Leaderboard Example> ZINCRBY leaderboard 20 "cqnqr"

"24"

> ZREVRANK leaderboard "cqnqr"

(integer) 0

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

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

9th July 2015

Thanks

Any questions ?

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/