1 / 10

redis

redis. A persistent key-value database. kesavan.muthuvel@ingenix.com. MySQL & memcache. It’s common to use MySQL as the backend for storing and retrieving what are essentially key/value pairs.

helena
Download Presentation

redis

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. redis A persistent key-value database kesavan.muthuvel@ingenix.com

  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/ redis-0.900/.gitignore redis-0.900/00-RELEASENOTES redis-0.900/adlist.c redis-0.900/adlist.h ... [kuthuv@slcd3edip12 ~]$ cd redis-0.900 [kuthuv@slcd3edip12 redis-0.900]$ make cc -c -std=c99 -pedantic -O2 -Wall -W -g -rdynamic -ggdbadlist.c cc -c -std=c99 -pedantic -O2 -Wall -W -g -rdynamic -ggdbae.c cc -c -std=c99 -pedantic -O2 -Wall -W -g -rdynamic -ggdbanet.c cc -c -std=c99 -pedantic -O2 -Wall -W -g -rdynamic -ggdbdict.c ...

  5. getting into ., [kuthuv@slcd3edip12 redis-0.900]$ ./redis-server >& /tmp/redis.log & [2] 29719 [kuthuv@slcd3edip12 redis-0.900]$ telnet localhost 6379 Trying 127.0.0.1... Connected to demo.connectivedi.com (127.0.0.1). Escape character is '^]'. SETmykey 20 ConnectivityDirector +OK GETmykey $20 ConnectivityDirector GETnonkey $-1 EXISTSnonkey :0 EXISTSmykey :1 QUIT Connection closed by foreign host. [kuthuv@slcd3edip12 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-100,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: http://code.google.com/p/redis/ • PHP lib : http://code.google.com/p/redis/source/browse/#svn/trunk/client-libraries/php

  10. Quezions? • Thanks

More Related