Introduction to Redis

What is Redis?

http://blog.newrelic.com/wp-content/uploads/redis.png

Redis, standing for REmote DIctionary Server is a NoSQL databases Server. Written in ANSI C by Salvatore Sanfilippo in early 2009 and quickly become the most popular key-value store.
Similar to Memcache, Redis has in-memory key/value store but with extra features like: persistence, more value types(lists, sets, sorted sets, hash table..), open source with large community and of course, it’s FREE !

Key features:

  • Get/Set/Incr strings or numbers
  • Lists
    Redis Lists are simply lists of strings, sorted by insertion order. It is possible to add elements to a Redis List pushing new elements on the head (on the left) or on the tail (on the right) of the list.

    http://s24.postimg.org/afq4ccxlh/redis_lists.jpg
    Simple Redis list

  • Sets
    Redis Sets are an unordered collection of Strings. It is possible to add, remove, and test for existence of members Set
  • Sorted sets
    Redis Sorted Sets are, similarly to Redis Sets, non repeating collections of Strings. The difference is that every member of a Sorted Set is associated with score, that is used in order to take the sorted set ordered, from the smallest to the greatest score. While members are unique, scores may be repeated
  • Hash
    Redis Hashes are maps between string fields and string values, so they are the perfect data type to represent objects
  • Pub/Subs supported
  • Multiple databases
  • Transactions

 

Why Redis?

It’s fast, almost data is in memory so we can access them instantly, master/slave replication – any slaves can become masters on the fly. With tons of features, we can implement Redis in many cases.

Sample Redis query:

SET name "John"
Result: OK
GET name
Result: John

Easy huh? 😉

 

When using Redis?

Redis is good for many cases, and below is list of some cases that was implemented by big companies like Twitted, Pinterest, Disqus, Instagram..

  • Analytics
  • Task queues
  • Distributed locks
  • Caching
  • Data that expires
  • Cookie storage
  • Search engines
  • Ad targeting
  • Forums
  • Messaging
  • High-IO workloads

 

Who is using Redis?

  • Pinterest
  • Rackspace
  • Blizzard Entertainment
  • Digg
  • Stackoverflow
  • Craigslist
  • Twitter
  • Github

 

Install Redis

For CentOS

wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
rpm -Uvh remi-release-6*.rpm epel-release-6*.rpm
yum install redis -y

For Windows

Download Redis for Windows at: https://github.com/dmajkic/redis/downloads

For Mac OS

The instructions will stay pretty much same for CentOS or you can try:

curl -O http://download.redis.io/redis-stable.tar.gz
tar -xvzf redis-stable.tar.gz
rm redis-stable.tar.gz
cd redis-stable
make
sudo make install

References
http://redis.io/topics/quickstart

Add a Comment

Scroll Up