Embed presentation
Downloaded 1,951 times










![List operations ● Lists are your ordinary linked lists. ● You can push and pop at both sides, extract range, resize, etc. ● Random access and ranges at O(N)! :-(redis> LPUSH foo bar(integer) 1redis> LPUSH foo baz(integer) 2redis> LRANGE foo 0 21. "baz"2. "bar"redis> LPOP foo"baz" ● BLPOP: Blocking POP - wait until a list has elements and pop them. Useful for realtime stuff.redis> BLPOP baz 10 [seconds]..... We wait!](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fredisdb1-110602141852-phpapp02%2f85%2fIntroduction-to-Redis-11-320.jpg&f=jpg&w=240)
![Set operations ● Sets are... well, sets of unique values w/ push, pop, etc. ● Sets can be intersected/diffed /union'ed server side. ● Can be useful as keys when building complex schemata.redis> SADD foo bar(integer) 1redis> SADD foo baz(integer) 1redis> SMEMBERS foo["baz", "bar"]redis> SADD foo2 baz // << another set(integer) 1redis> SADD foo2 raz(integer) 1redis> SINTER foo foo2 // << only one common element1. "baz"redis> SUNION foo foo2 // << UNION["raz", "bar", "baz"]](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fredisdb1-110602141852-phpapp02%2f85%2fIntroduction-to-Redis-12-320.jpg&f=jpg&w=240)





![Gotchas, Lessons Learned● Memory fragmentation can be a problem with some usage patterns. Alternative allocators (jemalloc, tcmalloc) ease that.● Horrible bug with Ubuntu 10.x servers and amazon EC2 machines [resulted in long, long nights at the office...]● 64 bit instances consume much much more RAM.● Master/Slave sync far from perfect.● DO NOT USE THE KEYS COMMAND!!!● vm.overcommit_memory = 1● Use MONITOR to see what's going on](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fredisdb1-110602141852-phpapp02%2f85%2fIntroduction-to-Redis-18-320.jpg&f=jpg&w=240)
![Example: *Very* Simple Social Feed#let's add a couple of followers>>> client.rpush('user:1:followers', 2)>>> numFollowers = client.rpush('user:1:followers', 3)>>> msgId = client.incr('messages:id') #ATOMIC OPERATION#add a message>>> client.hmset('messages:%s' % msgId, {'text': 'hello world', 'user': 1})#distribute to followers>>> followers = client.lrange('user:1:followers', 0, numFollowers)>>> pipe = client.pipeline()>>> for f in followers: pipe.rpush('user:%s:feed' % f, msgId)>>> pipe.execute()>>> msgId = client.incr('messages:id') #increment id#....repeat...repeat..repeat..repeat..#now get user 2's feed>>> client.sort(name = 'user:2:feed', get='messages:*->text')['hello world', 'foo bar']](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fredisdb1-110602141852-phpapp02%2f85%2fIntroduction-to-Redis-19-320.jpg&f=jpg&w=240)






Redis is an in-memory key-value store that is often used as a database, cache, and message broker. It supports various data structures like strings, hashes, lists, sets, and sorted sets. While data is stored in memory for fast access, Redis can also persist data to disk. It is widely used by companies like GitHub, Craigslist, and Engine Yard to power applications with high performance needs.










![List operations ● Lists are your ordinary linked lists. ● You can push and pop at both sides, extract range, resize, etc. ● Random access and ranges at O(N)! :-(redis> LPUSH foo bar(integer) 1redis> LPUSH foo baz(integer) 2redis> LRANGE foo 0 21. "baz"2. "bar"redis> LPOP foo"baz" ● BLPOP: Blocking POP - wait until a list has elements and pop them. Useful for realtime stuff.redis> BLPOP baz 10 [seconds]..... We wait!](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fredisdb1-110602141852-phpapp02%2f85%2fIntroduction-to-Redis-11-320.jpg&f=jpg&w=240)
![Set operations ● Sets are... well, sets of unique values w/ push, pop, etc. ● Sets can be intersected/diffed /union'ed server side. ● Can be useful as keys when building complex schemata.redis> SADD foo bar(integer) 1redis> SADD foo baz(integer) 1redis> SMEMBERS foo["baz", "bar"]redis> SADD foo2 baz // << another set(integer) 1redis> SADD foo2 raz(integer) 1redis> SINTER foo foo2 // << only one common element1. "baz"redis> SUNION foo foo2 // << UNION["raz", "bar", "baz"]](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fredisdb1-110602141852-phpapp02%2f85%2fIntroduction-to-Redis-12-320.jpg&f=jpg&w=240)





![Gotchas, Lessons Learned● Memory fragmentation can be a problem with some usage patterns. Alternative allocators (jemalloc, tcmalloc) ease that.● Horrible bug with Ubuntu 10.x servers and amazon EC2 machines [resulted in long, long nights at the office...]● 64 bit instances consume much much more RAM.● Master/Slave sync far from perfect.● DO NOT USE THE KEYS COMMAND!!!● vm.overcommit_memory = 1● Use MONITOR to see what's going on](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fredisdb1-110602141852-phpapp02%2f85%2fIntroduction-to-Redis-18-320.jpg&f=jpg&w=240)
![Example: *Very* Simple Social Feed#let's add a couple of followers>>> client.rpush('user:1:followers', 2)>>> numFollowers = client.rpush('user:1:followers', 3)>>> msgId = client.incr('messages:id') #ATOMIC OPERATION#add a message>>> client.hmset('messages:%s' % msgId, {'text': 'hello world', 'user': 1})#distribute to followers>>> followers = client.lrange('user:1:followers', 0, numFollowers)>>> pipe = client.pipeline()>>> for f in followers: pipe.rpush('user:%s:feed' % f, msgId)>>> pipe.execute()>>> msgId = client.incr('messages:id') #increment id#....repeat...repeat..repeat..repeat..#now get user 2's feed>>> client.sort(name = 'user:2:feed', get='messages:*->text')['hello world', 'foo bar']](/image.pl?url=https%3a%2f%2fimage.slidesharecdn.com%2fredisdb1-110602141852-phpapp02%2f85%2fIntroduction-to-Redis-19-320.jpg&f=jpg&w=240)




