SlideShare a Scribd company logo
1 of 24
Download to read offline
"Little Server of Awesome"


       2011 Dvir Volk

      Software Architect, Do@
   dvir@doat.com http://doat.com
What is redis
โ— Memcache-ish in-memory key/value store
โ— But it's also persistent!
โ— And it also has very cool value types:
    โ—‹ lists
    โ—‹ sets
    โ—‹ sorted sets
    โ—‹ hash tables
    โ—‹ append-able buffers
โ— Open source; very helpful and friendly community.
  Development is very active and responsive to requests.
โ— Sponsored by VMWare
โ— Used in the real world: github, craigslist, engineyard, ...
โ— Used heavily in do@ as a front-end database, search, geo
  resolving
Key Features and Cool Stuff
โ— All data is in memory (almost)
โ— 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 pub/sub functionality
โ— Tons of client libraries for all major languages
โ— Single threaded, uses aync. IO
โ— Internal scripting with LUA coming soon
A little benchmark

This is on my laptop (core i7 @2.2Ghz)

 โ— SET: 187265.92 requests per second
 โ— GET: 185185.17 requests per second
 โ— INCR: 190114.06 requests per second


 โ— LPUSH: 190114.06 requests per second
 โ— LPOP: 187090.73 requests per second

 โ—
 โ— SADD: 186567.16 requests per second
 โ— SPOP: 185873.61 requests per second
Scaling it up

 โ— Master-slave replication out of the box

 โ— Slaves can be made masters on the fly

 โ— Currently does not support "real" clustered mode....

 โ— ... But Redis-Cluster to be released soon

 โ— You can manually shard it client side

 โ— Single threaded - run num_cores/2 instances on the same
   machine
Persistence
โ— All data is synchronized to disk - eventually or immediately
โ— Pick your risk level Vs. performance
โ— Data is either dumped in a forked process, or written as a
  append-only change-log (AOF)
โ— Append-only mode supports transactional disk writes so you
  can lose no data (cost: 99% speed loss :) )
โ— AOF files get huge, but redis can minimize them on the fly.
โ— You can save the state explicitly, background or blocking

โ— Default configuration:
   โ—‹ Save after 900 sec (15 min) if at least 1 key changed
   โ—‹ Save after 300 sec (5 min) if at least 10 keys changed
   โ—‹ Save after 60 sec if at least 10000 keys changed
Virtual Memory

โ— 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 IO happens in separate threads

โ— But if you need this - don't use redis, or get a bigger
  machine ;)
Show me the features!

Now let's see the key featurs:

 โ— Get/Set/Incr - strings/numbers
 โ— Lists
 โ— Sets
 โ— Sorted Sets
 โ— Hash Tables
 โ— PubSub
 โ— SORT
 โ— Transactions

We'll use redis-cli for the examples.
Some of the output has been modified for readability.
The basics...
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"

Keys are lazily expired
redis> EXPIRE foo 1
(integer) 1
redis> GET foo
(nil)
Be careful with EXPIRE - re-setting a value without re-expiring it will remove the
expiration!
Atomic Operations
GETSET puts a different value inside a key, retriving the old one
redis> SET foo bar
OK
redis> GETSET foo baz
"bar"
redis> GET foo
"baz"

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.
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) 1

redis> LPUSH foo baz
(integer) 2

redis> LRANGE foo 0 2
1. "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!
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) 1
redis> SADD foo baz
(integer) 1
redis> SMEMBERS foo
["baz", "bar"]

redis> SADD foo2 baz // << another set
(integer) 1
redis> SADD foo2 raz
(integer) 1

redis> SINTER foo foo2 // << only one common element
1. "baz"
redis> SUNION foo foo2 // << UNION
["raz", "bar", "baz"]
Sorted Sets
 โ— Same as sets, but with score per element
 โ— Ranked ranges, aggregation of scores on INTERSECT
 โ— Can be used as ordered keys in complex schemata
 โ— Think timestamps, inverted index, geohashing, ip ranges
 redis> ZADD foo 1337 hax0r       redis> ZRANGE foo 0 10
 (integer) 1                      1. "luser"
 redis> ZADD foo 100 n00b         2. "hax0r"
 (integer) 1                      3. "n00b"
 redis> ZADD foo 500 luser
 (integer) 1                      redis> ZREVRANGE foo 0 10
                                  1. "n00b"
 redis> ZSCORE foo n00b           2. "hax0r"
 "100"                            3. "luser"

 redis> ZINCRBY foo 2000 n00b
 "2100"

 redis> ZRANK foo n00b
 (integer) 2
Hashes
 โ— Hash tables as values
 โ— Think of an object store with atomic access to object
   members

 redis> HSET foo bar 1             redis> HINCRBY foo bar 1
 (integer) 1                       (integer) 2
 redis> HSET foo baz 2
 (integer) 1                       redis> HGET foo bar
 redis> HSET foo foo foo           "2"
 (integer) 1
                                   redis> HKEYS foo
 redis> HGETALL foo                1. "bar"
 {                                 2. "baz"
   "bar": "1",                     3. "foo"
   "baz": "2",
   "foo": "foo"
 }
PubSub - Publish/Subscribe
 โ— Clients can subscribe to channels or patterns and receive
   notifications when messages are sent to channels.
 โ— Subscribing is O(1), posting messages is O(n)
 โ— Think chats, Comet applications: real-time analytics, twitter
 redis> subscribe feed:joe feed:moe feed:
 boe

 //now we wait
 ....                                        redis> publish feed:joe "all your base are
                           <<<<<----------   belong to me"
 1. "message"                                (integer) 1 //received by 1
 2. "feed:joe"
 3. "all your base are belong to me"
SORT FTW!
  โ— Key redis awesomeness
  โ— Sort SETs or LISTS using external values, and join values
    in one go:

SORT key
SORT key BY pattern (e.g. sort userIds BY user:*->age)
SORT key BY pattern GET othervalue

SORT userIds BY user:*->age GET user:*->name

  โ— ASC|DESC, LIMIT available, results can be stored, sorting
    can be numeric or alphabetic

  โ— Keep in mind that it's blocking and redis is single threaded.
    Maybe put a slave aside if you have big SORTs
Transactions
  โ— MULTI, ...., EXEC: Easy because of the single thread.
  โ— All commands are executed after EXEC, block and return
    values for the commands as a list.
  โ— Example:
redis> MULTI
OK
redis> SET "foo" "bar"
QUEUED
redis> INCRBY "num" 1
QUEUED
redis> EXEC
1) OK
2) (integer) 1

  โ— Transactions can be discarded with DISCARD.

  โ— WATCH allows you to lock keys while you are queuing your
    transaction, and avoid race conditions.
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
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']
Other use case ideas
โ— Geo Resolving with geohashing
โ— Implemented and opened by yours truly https://github.com/doat/geodis

โ— Real time analytics
โ— use ZSET, SORT, INCR of values

โ— API Key and rate management
โ— Very fast key lookup, rate control counters using INCR

โ— Real time game data
โ— ZSETs for high scores, HASHES for online users, etc

โ— Database Shard Index
โ— map key => database id. Count size with SETS

โ— Comet - no polling ajax
โ— use BLPOP or pub/sub

โ— Queue Server
โ— resque - a large portion of redis' user base
Melt - My little evil master-plan
โ— We wanted freakin' fast access to data on the front-end.

โ— but our ability to cache personalized and query bound data
  is limited.

โ— Redis to the rescue!

โ— But we still want the data to be in an RDBMs.

โ— So we made a framework to "melt the borders" between
  them...
Introducing melt
โ— ALL front end data is in RAM, denormalized and optimized for
  speed. Front end talks only to Redis.

โ— We use Redis' set features as keys and scoring vectors.

โ— All back end data is on mysql, with a manageable normalized
  schema. The admin talks only to MySQL.

โ— A sync queue in the middle keeps both ends up to date.

โ— A straightforward ORM is used to manage and sync the data.

โ— Automates indexing in Redis, generates models from MySQL.

โ— Use the same model on both ends, or create conversions.

โ— Central Id generator.
Melt - an example:
#syncing objects:
with MySqlStore:
  users = Users.get({Users.id: Int(1,2,3,4)})
  with RedisStore:
     for user in users:
        Users.save(user)


#pushing a new feed item from front to back:
with RedisStore:
  #create an object - any object!
  feedItem = FeedItem(userId, title, time.time())
  #use the model to save it
  Feed.save(feedItem)
  #now just tell the queue to put it on the other side
  SyncQueue.pushItem(action = 'update', model = FeedItem,
    source = 'redis', dest = 'mysql',
     id = feedItem.id)

Coming soon to a github near you! :)
More resources

Redis' website:
http://redis.io

Excellent and more detailed presentation by Simon Willison:
http://simonwillison.net/static/2010/redis-tutorial/

Much more complex twitter clone:
http://code.google.com/p/redis/wiki/TwitterAlikeExample

Full command reference:
http://code.google.com/p/redis/wiki/CommandReference

More Related Content

What's hot

Intro to HBase
Intro to HBaseIntro to HBase
Intro to HBasealexbaranau
ย 
Etsy Activity Feeds Architecture
Etsy Activity Feeds ArchitectureEtsy Activity Feeds Architecture
Etsy Activity Feeds ArchitectureDan McKinley
ย 
Stability Patterns for Microservices
Stability Patterns for MicroservicesStability Patterns for Microservices
Stability Patterns for Microservicespflueras
ย 
From cache to in-memory data grid. Introduction to Hazelcast.
From cache to in-memory data grid. Introduction to Hazelcast.From cache to in-memory data grid. Introduction to Hazelcast.
From cache to in-memory data grid. Introduction to Hazelcast.Taras Matyashovsky
ย 
HBase and HDFS: Understanding FileSystem Usage in HBase
HBase and HDFS: Understanding FileSystem Usage in HBaseHBase and HDFS: Understanding FileSystem Usage in HBase
HBase and HDFS: Understanding FileSystem Usage in HBaseenissoz
ย 
Geospatial Indexing at Scale: The 15 Million QPS Redis Architecture Powering ...
Geospatial Indexing at Scale: The 15 Million QPS Redis Architecture Powering ...Geospatial Indexing at Scale: The 15 Million QPS Redis Architecture Powering ...
Geospatial Indexing at Scale: The 15 Million QPS Redis Architecture Powering ...Daniel Hochman
ย 
Secrets of Performance Tuning Java on Kubernetes
Secrets of Performance Tuning Java on KubernetesSecrets of Performance Tuning Java on Kubernetes
Secrets of Performance Tuning Java on KubernetesBruno Borges
ย 
Top 5 Mistakes When Writing Spark Applications
Top 5 Mistakes When Writing Spark ApplicationsTop 5 Mistakes When Writing Spark Applications
Top 5 Mistakes When Writing Spark ApplicationsSpark Summit
ย 
Optimizing Hive Queries
Optimizing Hive QueriesOptimizing Hive Queries
Optimizing Hive QueriesOwen O'Malley
ย 
InfluxDB IOx Tech Talks: Query Engine Design and the Rust-Based DataFusion in...
InfluxDB IOx Tech Talks: Query Engine Design and the Rust-Based DataFusion in...InfluxDB IOx Tech Talks: Query Engine Design and the Rust-Based DataFusion in...
InfluxDB IOx Tech Talks: Query Engine Design and the Rust-Based DataFusion in...InfluxData
ย 
RocksDB Performance and Reliability Practices
RocksDB Performance and Reliability PracticesRocksDB Performance and Reliability Practices
RocksDB Performance and Reliability PracticesYoshinori Matsunobu
ย 
Deep Dive on ClickHouse Sharding and Replication-2202-09-22.pdf
Deep Dive on ClickHouse Sharding and Replication-2202-09-22.pdfDeep Dive on ClickHouse Sharding and Replication-2202-09-22.pdf
Deep Dive on ClickHouse Sharding and Replication-2202-09-22.pdfAltinity Ltd
ย 
redis ์†Œ๊ฐœ์ž๋ฃŒ - ๋„ค์˜คํด๋กœ๋ฐ”
redis ์†Œ๊ฐœ์ž๋ฃŒ - ๋„ค์˜คํด๋กœ๋ฐ”redis ์†Œ๊ฐœ์ž๋ฃŒ - ๋„ค์˜คํด๋กœ๋ฐ”
redis ์†Œ๊ฐœ์ž๋ฃŒ - ๋„ค์˜คํด๋กœ๋ฐ”NeoClova
ย 
Producer Performance Tuning for Apache Kafka
Producer Performance Tuning for Apache KafkaProducer Performance Tuning for Apache Kafka
Producer Performance Tuning for Apache KafkaJiangjie Qin
ย 
The Impala Cookbook
The Impala CookbookThe Impala Cookbook
The Impala CookbookCloudera, Inc.
ย 
RocksDB detail
RocksDB detailRocksDB detail
RocksDB detailMIJIN AN
ย 
Facebook Messages & HBase
Facebook Messages & HBaseFacebook Messages & HBase
Facebook Messages & HBaseๅผบ ็Ž‹
ย 

What's hot (20)

Intro to HBase
Intro to HBaseIntro to HBase
Intro to HBase
ย 
Etsy Activity Feeds Architecture
Etsy Activity Feeds ArchitectureEtsy Activity Feeds Architecture
Etsy Activity Feeds Architecture
ย 
Stability Patterns for Microservices
Stability Patterns for MicroservicesStability Patterns for Microservices
Stability Patterns for Microservices
ย 
From cache to in-memory data grid. Introduction to Hazelcast.
From cache to in-memory data grid. Introduction to Hazelcast.From cache to in-memory data grid. Introduction to Hazelcast.
From cache to in-memory data grid. Introduction to Hazelcast.
ย 
HBase and HDFS: Understanding FileSystem Usage in HBase
HBase and HDFS: Understanding FileSystem Usage in HBaseHBase and HDFS: Understanding FileSystem Usage in HBase
HBase and HDFS: Understanding FileSystem Usage in HBase
ย 
MyRocks Deep Dive
MyRocks Deep DiveMyRocks Deep Dive
MyRocks Deep Dive
ย 
Geospatial Indexing at Scale: The 15 Million QPS Redis Architecture Powering ...
Geospatial Indexing at Scale: The 15 Million QPS Redis Architecture Powering ...Geospatial Indexing at Scale: The 15 Million QPS Redis Architecture Powering ...
Geospatial Indexing at Scale: The 15 Million QPS Redis Architecture Powering ...
ย 
Secrets of Performance Tuning Java on Kubernetes
Secrets of Performance Tuning Java on KubernetesSecrets of Performance Tuning Java on Kubernetes
Secrets of Performance Tuning Java on Kubernetes
ย 
Top 5 Mistakes When Writing Spark Applications
Top 5 Mistakes When Writing Spark ApplicationsTop 5 Mistakes When Writing Spark Applications
Top 5 Mistakes When Writing Spark Applications
ย 
Optimizing Hive Queries
Optimizing Hive QueriesOptimizing Hive Queries
Optimizing Hive Queries
ย 
InfluxDB IOx Tech Talks: Query Engine Design and the Rust-Based DataFusion in...
InfluxDB IOx Tech Talks: Query Engine Design and the Rust-Based DataFusion in...InfluxDB IOx Tech Talks: Query Engine Design and the Rust-Based DataFusion in...
InfluxDB IOx Tech Talks: Query Engine Design and the Rust-Based DataFusion in...
ย 
RocksDB Performance and Reliability Practices
RocksDB Performance and Reliability PracticesRocksDB Performance and Reliability Practices
RocksDB Performance and Reliability Practices
ย 
Presto
PrestoPresto
Presto
ย 
Deep Dive on ClickHouse Sharding and Replication-2202-09-22.pdf
Deep Dive on ClickHouse Sharding and Replication-2202-09-22.pdfDeep Dive on ClickHouse Sharding and Replication-2202-09-22.pdf
Deep Dive on ClickHouse Sharding and Replication-2202-09-22.pdf
ย 
redis ์†Œ๊ฐœ์ž๋ฃŒ - ๋„ค์˜คํด๋กœ๋ฐ”
redis ์†Œ๊ฐœ์ž๋ฃŒ - ๋„ค์˜คํด๋กœ๋ฐ”redis ์†Œ๊ฐœ์ž๋ฃŒ - ๋„ค์˜คํด๋กœ๋ฐ”
redis ์†Œ๊ฐœ์ž๋ฃŒ - ๋„ค์˜คํด๋กœ๋ฐ”
ย 
Producer Performance Tuning for Apache Kafka
Producer Performance Tuning for Apache KafkaProducer Performance Tuning for Apache Kafka
Producer Performance Tuning for Apache Kafka
ย 
The Impala Cookbook
The Impala CookbookThe Impala Cookbook
The Impala Cookbook
ย 
RocksDB detail
RocksDB detailRocksDB detail
RocksDB detail
ย 
Facebook Messages & HBase
Facebook Messages & HBaseFacebook Messages & HBase
Facebook Messages & HBase
ย 
Hive: Loading Data
Hive: Loading DataHive: Loading Data
Hive: Loading Data
ย 

Similar to Introduction to Redis

Introduction to redis - version 2
Introduction to redis - version 2Introduction to redis - version 2
Introduction to redis - version 2Dvir Volk
ย 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to RedisRizky Abdilah
ย 
REDIS intro and how to use redis
REDIS intro and how to use redisREDIS intro and how to use redis
REDIS intro and how to use redisKris Jeong
ย 
Redis SoCraTes 2014
Redis SoCraTes 2014Redis SoCraTes 2014
Redis SoCraTes 2014steffenbauer
ย 
Paris Redis Meetup Introduction
Paris Redis Meetup IntroductionParis Redis Meetup Introduction
Paris Redis Meetup IntroductionGregory Boissinot
ย 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to RedisSaeid Zebardast
ย 
MongoDB for Time Series Data Part 3: Sharding
MongoDB for Time Series Data Part 3: ShardingMongoDB for Time Series Data Part 3: Sharding
MongoDB for Time Series Data Part 3: ShardingMongoDB
ย 
Managing terabytes: When Postgres gets big
Managing terabytes: When Postgres gets bigManaging terabytes: When Postgres gets big
Managing terabytes: When Postgres gets bigSelena Deckelmann
ย 
BlueStore: a new, faster storage backend for Ceph
BlueStore: a new, faster storage backend for CephBlueStore: a new, faster storage backend for Ceph
BlueStore: a new, faster storage backend for CephSage Weil
ย 
Managing terabytes: When PostgreSQL gets big
Managing terabytes: When PostgreSQL gets bigManaging terabytes: When PostgreSQL gets big
Managing terabytes: When PostgreSQL gets bigSelena Deckelmann
ย 
MySQL 5.7 in a Nutshell
MySQL 5.7 in a NutshellMySQL 5.7 in a Nutshell
MySQL 5.7 in a NutshellEmily Ikuta
ย 
Redis modules 101
Redis modules 101Redis modules 101
Redis modules 101Dvir Volk
ย 
Programar para GPUs
Programar para GPUsProgramar para GPUs
Programar para GPUsAlcides Fonseca
ย 
What's new in Redis v3.2
What's new in Redis v3.2What's new in Redis v3.2
What's new in Redis v3.2Itamar Haber
ย 
Redis - Usability and Use Cases
Redis - Usability and Use CasesRedis - Usability and Use Cases
Redis - Usability and Use CasesFabrizio Farinacci
ย 
BlueStore, A New Storage Backend for Ceph, One Year In
BlueStore, A New Storage Backend for Ceph, One Year InBlueStore, A New Storage Backend for Ceph, One Year In
BlueStore, A New Storage Backend for Ceph, One Year InSage Weil
ย 

Similar to Introduction to Redis (20)

Introduction to redis - version 2
Introduction to redis - version 2Introduction to redis - version 2
Introduction to redis - version 2
ย 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
ย 
REDIS intro and how to use redis
REDIS intro and how to use redisREDIS intro and how to use redis
REDIS intro and how to use redis
ย 
Redis SoCraTes 2014
Redis SoCraTes 2014Redis SoCraTes 2014
Redis SoCraTes 2014
ย 
Paris Redis Meetup Introduction
Paris Redis Meetup IntroductionParis Redis Meetup Introduction
Paris Redis Meetup Introduction
ย 
Bluestore
BluestoreBluestore
Bluestore
ย 
Bluestore
BluestoreBluestore
Bluestore
ย 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
ย 
Redis introduction
Redis introductionRedis introduction
Redis introduction
ย 
MongoDB for Time Series Data Part 3: Sharding
MongoDB for Time Series Data Part 3: ShardingMongoDB for Time Series Data Part 3: Sharding
MongoDB for Time Series Data Part 3: Sharding
ย 
Kyotoproducts
KyotoproductsKyotoproducts
Kyotoproducts
ย 
Managing terabytes: When Postgres gets big
Managing terabytes: When Postgres gets bigManaging terabytes: When Postgres gets big
Managing terabytes: When Postgres gets big
ย 
BlueStore: a new, faster storage backend for Ceph
BlueStore: a new, faster storage backend for CephBlueStore: a new, faster storage backend for Ceph
BlueStore: a new, faster storage backend for Ceph
ย 
Managing terabytes: When PostgreSQL gets big
Managing terabytes: When PostgreSQL gets bigManaging terabytes: When PostgreSQL gets big
Managing terabytes: When PostgreSQL gets big
ย 
MySQL 5.7 in a Nutshell
MySQL 5.7 in a NutshellMySQL 5.7 in a Nutshell
MySQL 5.7 in a Nutshell
ย 
Redis modules 101
Redis modules 101Redis modules 101
Redis modules 101
ย 
Programar para GPUs
Programar para GPUsProgramar para GPUs
Programar para GPUs
ย 
What's new in Redis v3.2
What's new in Redis v3.2What's new in Redis v3.2
What's new in Redis v3.2
ย 
Redis - Usability and Use Cases
Redis - Usability and Use CasesRedis - Usability and Use Cases
Redis - Usability and Use Cases
ย 
BlueStore, A New Storage Backend for Ceph, One Year In
BlueStore, A New Storage Backend for Ceph, One Year InBlueStore, A New Storage Backend for Ceph, One Year In
BlueStore, A New Storage Backend for Ceph, One Year In
ย 

More from Dvir Volk

RediSearch
RediSearchRediSearch
RediSearchDvir Volk
ย 
Searching Billions of Documents with Redis
Searching Billions of Documents with RedisSearching Billions of Documents with Redis
Searching Billions of Documents with RedisDvir Volk
ย 
Boosting Machine Learning with Redis Modules and Spark
Boosting Machine Learning with Redis Modules and SparkBoosting Machine Learning with Redis Modules and Spark
Boosting Machine Learning with Redis Modules and SparkDvir Volk
ย 
Tales Of The Black Knight - Keeping EverythingMe running
Tales Of The Black Knight - Keeping EverythingMe runningTales Of The Black Knight - Keeping EverythingMe running
Tales Of The Black Knight - Keeping EverythingMe runningDvir Volk
ย 
10 reasons to be excited about go
10 reasons to be excited about go10 reasons to be excited about go
10 reasons to be excited about goDvir Volk
ย 
Kicking ass with redis
Kicking ass with redisKicking ass with redis
Kicking ass with redisDvir Volk
ย 
Introduction to Thrift
Introduction to ThriftIntroduction to Thrift
Introduction to ThriftDvir Volk
ย 

More from Dvir Volk (7)

RediSearch
RediSearchRediSearch
RediSearch
ย 
Searching Billions of Documents with Redis
Searching Billions of Documents with RedisSearching Billions of Documents with Redis
Searching Billions of Documents with Redis
ย 
Boosting Machine Learning with Redis Modules and Spark
Boosting Machine Learning with Redis Modules and SparkBoosting Machine Learning with Redis Modules and Spark
Boosting Machine Learning with Redis Modules and Spark
ย 
Tales Of The Black Knight - Keeping EverythingMe running
Tales Of The Black Knight - Keeping EverythingMe runningTales Of The Black Knight - Keeping EverythingMe running
Tales Of The Black Knight - Keeping EverythingMe running
ย 
10 reasons to be excited about go
10 reasons to be excited about go10 reasons to be excited about go
10 reasons to be excited about go
ย 
Kicking ass with redis
Kicking ass with redisKicking ass with redis
Kicking ass with redis
ย 
Introduction to Thrift
Introduction to ThriftIntroduction to Thrift
Introduction to Thrift
ย 

Recently uploaded

Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
ย 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
ย 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
ย 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
ย 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
ย 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024SynarionITSolutions
ย 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
ย 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
ย 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
ย 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vรกzquez
ย 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
ย 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
ย 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
ย 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
ย 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
ย 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
ย 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
ย 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
ย 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
ย 

Recently uploaded (20)

Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
ย 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
ย 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
ย 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
ย 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
ย 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
ย 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
ย 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
ย 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
ย 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
ย 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
ย 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
ย 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
ย 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
ย 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ย 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
ย 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
ย 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
ย 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
ย 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
ย 

Introduction to Redis

  • 1. "Little Server of Awesome" 2011 Dvir Volk Software Architect, Do@ dvir@doat.com http://doat.com
  • 2. What is redis โ— Memcache-ish in-memory key/value store โ— But it's also persistent! โ— And it also has very cool value types: โ—‹ lists โ—‹ sets โ—‹ sorted sets โ—‹ hash tables โ—‹ append-able buffers โ— Open source; very helpful and friendly community. Development is very active and responsive to requests. โ— Sponsored by VMWare โ— Used in the real world: github, craigslist, engineyard, ... โ— Used heavily in do@ as a front-end database, search, geo resolving
  • 3. Key Features and Cool Stuff โ— All data is in memory (almost) โ— 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 pub/sub functionality โ— Tons of client libraries for all major languages โ— Single threaded, uses aync. IO โ— Internal scripting with LUA coming soon
  • 4. A little benchmark This is on my laptop (core i7 @2.2Ghz) โ— SET: 187265.92 requests per second โ— GET: 185185.17 requests per second โ— INCR: 190114.06 requests per second โ— LPUSH: 190114.06 requests per second โ— LPOP: 187090.73 requests per second โ— โ— SADD: 186567.16 requests per second โ— SPOP: 185873.61 requests per second
  • 5. Scaling it up โ— Master-slave replication out of the box โ— Slaves can be made masters on the fly โ— Currently does not support "real" clustered mode.... โ— ... But Redis-Cluster to be released soon โ— You can manually shard it client side โ— Single threaded - run num_cores/2 instances on the same machine
  • 6. Persistence โ— All data is synchronized to disk - eventually or immediately โ— Pick your risk level Vs. performance โ— Data is either dumped in a forked process, or written as a append-only change-log (AOF) โ— Append-only mode supports transactional disk writes so you can lose no data (cost: 99% speed loss :) ) โ— AOF files get huge, but redis can minimize them on the fly. โ— You can save the state explicitly, background or blocking โ— Default configuration: โ—‹ Save after 900 sec (15 min) if at least 1 key changed โ—‹ Save after 300 sec (5 min) if at least 10 keys changed โ—‹ Save after 60 sec if at least 10000 keys changed
  • 7. Virtual Memory โ— 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 IO happens in separate threads โ— But if you need this - don't use redis, or get a bigger machine ;)
  • 8. Show me the features! Now let's see the key featurs: โ— Get/Set/Incr - strings/numbers โ— Lists โ— Sets โ— Sorted Sets โ— Hash Tables โ— PubSub โ— SORT โ— Transactions We'll use redis-cli for the examples. Some of the output has been modified for readability.
  • 9. The basics... 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" Keys are lazily expired redis> EXPIRE foo 1 (integer) 1 redis> GET foo (nil) Be careful with EXPIRE - re-setting a value without re-expiring it will remove the expiration!
  • 10. Atomic Operations GETSET puts a different value inside a key, retriving the old one redis> SET foo bar OK redis> GETSET foo baz "bar" redis> GET foo "baz" 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.
  • 11. 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) 1 redis> LPUSH foo baz (integer) 2 redis> LRANGE foo 0 2 1. "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!
  • 12. 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) 1 redis> SADD foo baz (integer) 1 redis> SMEMBERS foo ["baz", "bar"] redis> SADD foo2 baz // << another set (integer) 1 redis> SADD foo2 raz (integer) 1 redis> SINTER foo foo2 // << only one common element 1. "baz" redis> SUNION foo foo2 // << UNION ["raz", "bar", "baz"]
  • 13. Sorted Sets โ— Same as sets, but with score per element โ— Ranked ranges, aggregation of scores on INTERSECT โ— Can be used as ordered keys in complex schemata โ— Think timestamps, inverted index, geohashing, ip ranges redis> ZADD foo 1337 hax0r redis> ZRANGE foo 0 10 (integer) 1 1. "luser" redis> ZADD foo 100 n00b 2. "hax0r" (integer) 1 3. "n00b" redis> ZADD foo 500 luser (integer) 1 redis> ZREVRANGE foo 0 10 1. "n00b" redis> ZSCORE foo n00b 2. "hax0r" "100" 3. "luser" redis> ZINCRBY foo 2000 n00b "2100" redis> ZRANK foo n00b (integer) 2
  • 14. Hashes โ— Hash tables as values โ— Think of an object store with atomic access to object members redis> HSET foo bar 1 redis> HINCRBY foo bar 1 (integer) 1 (integer) 2 redis> HSET foo baz 2 (integer) 1 redis> HGET foo bar redis> HSET foo foo foo "2" (integer) 1 redis> HKEYS foo redis> HGETALL foo 1. "bar" { 2. "baz" "bar": "1", 3. "foo" "baz": "2", "foo": "foo" }
  • 15. PubSub - Publish/Subscribe โ— Clients can subscribe to channels or patterns and receive notifications when messages are sent to channels. โ— Subscribing is O(1), posting messages is O(n) โ— Think chats, Comet applications: real-time analytics, twitter redis> subscribe feed:joe feed:moe feed: boe //now we wait .... redis> publish feed:joe "all your base are <<<<<---------- belong to me" 1. "message" (integer) 1 //received by 1 2. "feed:joe" 3. "all your base are belong to me"
  • 16. SORT FTW! โ— Key redis awesomeness โ— Sort SETs or LISTS using external values, and join values in one go: SORT key SORT key BY pattern (e.g. sort userIds BY user:*->age) SORT key BY pattern GET othervalue SORT userIds BY user:*->age GET user:*->name โ— ASC|DESC, LIMIT available, results can be stored, sorting can be numeric or alphabetic โ— Keep in mind that it's blocking and redis is single threaded. Maybe put a slave aside if you have big SORTs
  • 17. Transactions โ— MULTI, ...., EXEC: Easy because of the single thread. โ— All commands are executed after EXEC, block and return values for the commands as a list. โ— Example: redis> MULTI OK redis> SET "foo" "bar" QUEUED redis> INCRBY "num" 1 QUEUED redis> EXEC 1) OK 2) (integer) 1 โ— Transactions can be discarded with DISCARD. โ— WATCH allows you to lock keys while you are queuing your transaction, and avoid race conditions.
  • 18. 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
  • 19. 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']
  • 20. Other use case ideas โ— Geo Resolving with geohashing โ— Implemented and opened by yours truly https://github.com/doat/geodis โ— Real time analytics โ— use ZSET, SORT, INCR of values โ— API Key and rate management โ— Very fast key lookup, rate control counters using INCR โ— Real time game data โ— ZSETs for high scores, HASHES for online users, etc โ— Database Shard Index โ— map key => database id. Count size with SETS โ— Comet - no polling ajax โ— use BLPOP or pub/sub โ— Queue Server โ— resque - a large portion of redis' user base
  • 21. Melt - My little evil master-plan โ— We wanted freakin' fast access to data on the front-end. โ— but our ability to cache personalized and query bound data is limited. โ— Redis to the rescue! โ— But we still want the data to be in an RDBMs. โ— So we made a framework to "melt the borders" between them...
  • 22. Introducing melt โ— ALL front end data is in RAM, denormalized and optimized for speed. Front end talks only to Redis. โ— We use Redis' set features as keys and scoring vectors. โ— All back end data is on mysql, with a manageable normalized schema. The admin talks only to MySQL. โ— A sync queue in the middle keeps both ends up to date. โ— A straightforward ORM is used to manage and sync the data. โ— Automates indexing in Redis, generates models from MySQL. โ— Use the same model on both ends, or create conversions. โ— Central Id generator.
  • 23. Melt - an example: #syncing objects: with MySqlStore: users = Users.get({Users.id: Int(1,2,3,4)}) with RedisStore: for user in users: Users.save(user) #pushing a new feed item from front to back: with RedisStore: #create an object - any object! feedItem = FeedItem(userId, title, time.time()) #use the model to save it Feed.save(feedItem) #now just tell the queue to put it on the other side SyncQueue.pushItem(action = 'update', model = FeedItem, source = 'redis', dest = 'mysql', id = feedItem.id) Coming soon to a github near you! :)
  • 24. More resources Redis' website: http://redis.io Excellent and more detailed presentation by Simon Willison: http://simonwillison.net/static/2010/redis-tutorial/ Much more complex twitter clone: http://code.google.com/p/redis/wiki/TwitterAlikeExample Full command reference: http://code.google.com/p/redis/wiki/CommandReference