Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
233 views16 pages

Redis

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1/ 16

Redis

Abhishek Thulasi – 18103607


Shail Patel – 18103624
What is redis?
● In-memory key-value pair storage
● Open source
● Written in C
● Can handle up to 232 keys, and was tested in practice to handle at
least 250 million of keys per instance.
● Most popular key-value store

History:
● REmote DIctionary Server
● released in March 2009
● built in order to scale
Features
● Abstract data types - Lists, Sets, Sorted sets of strings (collections of
non-repeating elements ordered by a floating-point number called
score), Hashes
● Two kinds of persistence mechanisms
● Replication
● Publish subscribe
● Transactions (with optimistic locking)
● Lua scripting
● Command line tool
Redis protocol
Logical Data Model

Data Model
• Key
o Printable ASCII
• Value
o Strings
o Hashes
o Lists
o Sets
o Sorted Sets
Shopping Cart Example
Relational Model Redis Model
carts set carts_james ( 1 3 )
CartID User set carts_chris ( 2 )
1 james hash cart_1 {
2 chris user : "james"
product_28 : 1
3 james
product_372: 2
}
cart_lines hash cart_2 {
Cart Product Qty user : "chris"
1 28 1 product_15 : 1
1 372 2 product_160: 5
2 15 1 product_201: 7
2 160 5 }
2 201 7
HINCRBY cart_1 product_28 2
UPDATE cart_lines
SET Qty = Qty + 2
WHERE Cart=1 AND Product=28
Persistence mechanism
RDB(Redis snapshotting) and AOF(Append-only file)
● The RDB persistence performs point-in-time snapshots of dataset
at specified intervals.
● The AOF persistence logs every write operation received by the
server, that will be played again at server startup, reconstructing
the original dataset. Commands are logged using the same format
as the Redis protocol itself, in an append-only fashion.
Data Persistence
Periodic Dump ("Background Save")
fork() with Copy-on-Write, write entire DB to disk
When?
After every X seconds and Y changes, or,
BGSAVE command

Append Only File


On every write, append change to log
file Flexible fsync() schedule:
Always, Every second, or, Never
Must compact with BGREWRITEAOF
Replication
● redis master - handles all
reads/ writes
● slave - hot standby - can
also be configured for
scalability to serve reads
● sentinels - mechanism for
monitoring, failover - uses
pub/sub, gossip and
agreement protocols
Replication Process
Chronology
SLAVE: Connects to master, sends "SYNC" command
MASTER: Begins "background save" of DB to disk
MASTER: Begins recording all new writes
MASTER: Transfers DB snapshot to slave
SLAVE: Saves snapshot to disk
SLAVE: Loads snapshot into RAM
MASTER: Sends recorded write commands
SLAVE: Applies recorded write commands
SLAVE: Goes live, begins accepting requests
Transactions
To redis or not?
● Counting Downloads
● High Score tables
● Caching
● Queues
● coupling with other databases

My two cents :)
● using resque for managing background jobs
● jobs placed on queues
● used sentinels for HA
So who is using redis?

Source: http://redis.io/topics/whos-using-redis
Comparison
Redis Mongodb Couchdb

Stock prices. Analytics. For most things that CRM, CMS systems.
Real-time data you would do with For accumulating,
collection. Real-time MySQL or PostgreSQL, occasionally changing
communication. And but having predefined data, on which pre-
wherever you used columns really holds defined queries are to
memcached before. you back. be run. Places where
versioning is important.
References
http://nosqlberlin.de/slides/NoSQLBerlin-Redis.pdf
http://stackoverflow.com/questions/7888880/what-is-redis-and-what-do-i-use-it-
for
http://highscalability.com/blog/2011/7/6/11-common-web-use-cases-solved-in-
redis.html
http://openmymind.net/redis.pdf
http://oldblog.antirez.com/post/redis-persistence-demystified.html
http://redis4you.com/articles.php?id=003
http://blog.siyelo.com/redis-in-the-nosql-ecosystem
http://www.slideshare.net/tim.lossen.de/cassandra-vs-redis

You might also like