在看一个slideshare的PPT结果没有下载,只好做下笔记了
key-value store
all data lives in memory
keys can expire(or not)
fast,light-weight
persistence
multiple databases
Queryable keyspace
Support for integer counters
higher level data structures
atomic operations
ability to paginate lists without mutating them
master-slave replication
Optional VM feature(new)
ervery write command is logged ASAP
Commands replayed when the server is restarted
Configurable speed/safety(safest by default)
use the select command;0-15 are valid by default,but you can add more in redis.conf
useful for segmemting key namespaces,especially when key queries are needed
MOVE command can be used as a locking primitive
Data Structures
Strings
Strings-as-integers(used by INCR/DECR)
List of Strings
Set of Strings(unique list)
Sorted Set of String(and weights)(ZSET)
Command overview
strings:get,set,increment,decrement
Lists:lrpush,lpop,llen,lrange,ltrim
sets:add,remove,move,length,intersect,union,diff,random
others:save,lastsave can be used to force&verify disk persistence
Atomic Operations
LPUSH/RPUSH:append to head/tail of list
LPOP/RPOP:return & remove first/last element of list
RPOPLPUSH:return & remove the last element of source list and push to the head of the destination list
GETSET:set a key to a new value and return the old value
MGET/MSET:get or set multiple keys to multiple values
SMOVE:move a value from one set to another
Replication
Slave can be used for scalability or redundancy
A master can have multiple slaves.
Slaves are able to accept other slave connections
Redis replication is non-blocking on the master,but blocking on the slave(can't respond to uqeries during initial sync)
Slaves are able to automatically reconnect after an outage
Memcache Replacement
Why? Same as Memcached,but you get more "for free";
Many databases from a single instance of REdis(instead of using namespaces)
Ability to easily backup/transfer state(dump.rdb)
Watch live command on a running instance with the MONITOR command (instead of restarting with -v)
Opportunity to use Redis for other things once you've switched
Work Queue
LPUSH and RPOP were made for this
Resque
Created by Chris Wanstrath.Heavily inspired by DelayedJob.Currently used by GitHub.
Provides:
A Ruby library for creating,querying,and processing jobs
A Rake task for starting a worker which processes jobs
A Sinatra app for monitoring queues,jobs,and workers.
Replace MySQL ORDER BY RAND()
ORDER BY RAND() is very slow(even with a LIMIT clause)
DUplicating the list of IDs as a Redis set is relatively cheap
SRANDMEMBER is fast
Other Interesting Uses of Redis
Nginx HTTP Redis module for cacheing with Redis(ngx_http_redis)
LLOOG.com:Realtime site usage statistics,use alongside Google analytics
EZMobius'Fair Work Scheduler example
Sikwamic:Simple Redis-backend Comet server
RestMQ-A REST/JSON/HTTP based message queue built on Redis
redis-textsearch A simple full-text search for multiple data stores