Download presentation
Presentation is loading. Please wait.
1
A persistent key-value database
redis A persistent key-value database
2
MySQL & memcache It’s common to use MySQL as the backend for storing and retrieving what are essentially key/value pairs. In some scenario, we needs to maintain a bit of state, session data, counters, small lists, and so on. When MySQL isn’t able to keep up with the volume, we often turn to memcached* as a write-thru cache. But there’s a bit of a mis-match at work here. Memcached doesn’t have much in the way of a query language or server-side operations it can perform on the data. MySQL lies at the other end of the spectrum. It has a rich query language and support for all sorts of server-side processing on the dataSo when we combine the two, our app has to know it’s talking to both and deal with coordinating data changes between the cache and the back-end server. *memcached is a high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load.
3
redis A fast, efficient key/value store that provides a reasonable set of server-size operations aimed at making the most common operations trivial.
4
on our badger [kuthuv@slcd3edip12 ~]$ tar -zxvf redis-0.900_2.tar.gz
redis-0.900/.gitignore redis-0.900/00-RELEASENOTES redis-0.900/adlist.c redis-0.900/adlist.h ... ~]$ cd redis-0.900 redis-0.900]$ make cc -c -std=c99 -pedantic -O2 -Wall -W -g -rdynamic -ggdb adlist.c cc -c -std=c99 -pedantic -O2 -Wall -W -g -rdynamic -ggdb ae.c cc -c -std=c99 -pedantic -O2 -Wall -W -g -rdynamic -ggdb anet.c cc -c -std=c99 -pedantic -O2 -Wall -W -g -rdynamic -ggdb dict.c
5
getting into ., redis-0.900]$ ./redis-server >& /tmp/redis.log & [2] 29719 redis-0.900]$ telnet localhost 6379 Trying Connected to demo.connectivedi.com ( ). Escape character is '^]'. SET mykey 20 ConnectivityDirector +OK GET mykey $20 GET nonkey $-1 EXISTS nonkey :0 EXISTS mykey :1 QUIT Connection closed by foreign host. redis-0.900]$
6
datatypes and operations
Strings SET, GET, EXISTS etc Lists RPUSH, LPUSH Sets SADD, SREM Others KEYS: list all keys matching a pattern RANDOMKEY RENAME EXPIRE: set expiration time (in seconds) of a key TTL: get the time-to-live of a key
7
why redis? readily available client APIs available for a number of languages, including: Ruby Python Perl PHP Erlang TCL Lua Java Performance the overriding focus for redis is performance 80, ,000 (or more) operations per second on modest modern hardware is likely enough to make a dramatic difference to most applications. much of this performance comes from it’s minimal feature set. carefully chosen features that can be supported by very fast algorithms and, in come cases, even lock-free atomic operations.
8
why redis? Durability and Availability
Unlike memcached, redis can save its state to disk so that you can shut down a server without losing all the data. SAVE: save data to disk (synchronously) BGSAVE: save data to disk (asynchronously) LASTSAVE: get timestamp of last saved data For performance reasons, redis doesn’t log every change to disk as it happens (then it’d be a lot more like a database). Instead, it can be configured to save a copy of the database to disk after a certain amount of time has passed or a certain threshold of changes have occurred in the data. The method of writing to disk requires no locking and has no consistency problems. The server simply forks a child which inherits a copy of the data it can write to disk. That process of writing to disk should take somewhere from a few seconds to maybe a minute or two. Uses Copy-on-write optimization technique. redis also has built-in support for master/slave replication, so it’s possible to scale in read-heavy environments simplicity + functionality+ performance = redis
9
what next? Central lib: PHP lib : http://code.google.com/p/redis/
10
Quezions? Thanks
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.