1 COSC 6339 Big Data Analytics NoSQL (II) – Redis and Memcached Edgar Gabriel Spring 2017 Redis • in-memory key/value • Support for various types: – Lists – sets and sorted sets – hash tables – append-able buffers • Open sourceSponsored by VMWare • Used in the real world: github, craigslist, engineyard, ... • Used heavily as a front-end database Slide based on tutorial by Dvir Volk https://www.slideshare.net/dvirsky/introduction-to-redis
15
Embed
COSC 6339 Big Data Analytics NoSQL (II) Redis and Memcachedgabriel/courses/cosc6339_s17/BDA_21_NoSQL_4.pdf · 1 COSC 6339 Big Data Analytics NoSQL (II) – Redis and Memcached Edgar
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
1
COSC 6339
Big Data Analytics
NoSQL (II) –
Redis and Memcached
Edgar Gabriel
Spring 2017
Redis
• in-memory key/value
• Support for various types:
– Lists
– sets and sorted sets
– hash tables
– append-able buffers
• Open sourceSponsored by VMWare
• Used in the real world: github, craigslist, engineyard, ...
• Used heavily as a front-end database
Slide based on tutorial by Dvir Volk https://www.slideshare.net/dvirsky/introduction-to-redis
2
Redis features
• All data is in memory
• All data is eventually persistent (But can be
immediately)
• Handles huge workloads easily
• Mostly O(1) behavior
• Ideal for write-heavy workloads
• Support for atomic operations
• Supports for transactions
• Has publish / subscribe functionality
• Tons of client libraries for all major languages
Slide based on tutorial by Dvir Volk https://www.slideshare.net/dvirsky/introduction-to-redis
• Master-slave replication out of the box
• Slaves can be made masters on the fly
• Supports cluster mode (sharding) or and manually shard
it client side
• If your database is too big - redis can handle swapping
on its own.
• Keys remain in memory and least used values are
swapped to disk.
• Swapping I/O happens in separate threads
Redis features (II)
Slide based on tutorial by Dvir Volk https://www.slideshare.net/dvirsky/introduction-to-redis
3
Usage examples
• Get/Sets - nothing fancy. Keys are strings, anything goes - just
quote spaces.
redis> SET foo "bar"
OK
redis> GET foo
"bar"
• You can atomically increment numbers
redis> SET bar 337
OK
redis> INCRBY bar 1000
(integer) 1337
• Getting multiple values at once
redis> MGET foo bar
1. "bar"
2. "1337"Slide based on tutorial by Dvir Volk https://www.slideshare.net/dvirsky/introduction-to-redis
Usage examples
• Keys are lazily expired
redis> EXPIRE foo 1
(integer) 1
redis> GET foo
(nil)
• Note: re-setting a value without re-expiring it will remove the
expiration
• GET / SET puts a different value inside a key, retrieving the old
one
redis> SET foo bar
OK
redis> GETSET foo baz
"bar"
Slide based on tutorial by Dvir Volk https://www.slideshare.net/dvirsky/introduction-to-redis
4
Usage examples
• SETNX sets a value only if it does not exist
redis> SETNX foo bar
*OK*
redis> SETNX foo baz
*FAILS*
• SETNX + Timestamp => Named Locks! w00t!
redis> SETNX myLock <current_time>
OK
redis> SETNX myLock <new_time>
*FAILS*
Note that If the locking client crashes that might cause some problems, but it
can be solved easily.
Slide based on tutorial by Dvir Volk https://www.slideshare.net/dvirsky/introduction-to-redis