Monday, 25 May 2015

Getting started with Redis


        Redis is a really fast and useful NoSQL database. It's used by many large web companies like StackOverflow, Twitter and Instagram.
       
        But if you are reading about it for the first time it can be pretty confusing about what Redis does and how can it be used. Also why do we need to use Redis instead of relational databases like MySQL or SQLServer. This post is meant to give you a brief introduction about Redis and how it differs from relational databases and NoSQL.
       
        Redis is an Open Source database that stores data in the form of a key value pair. Each type of data is associated with a key. You might think of Redis as a dictionary in C# or Map in Java, but the value in Redis is a structured data type consisting of lists, set and hashes.
        The key point about Redis is it stores data in the main memory i.e in the RAM of the computer it is running on. You can persist the data to disk, but the in-memory dataset and the key value pair is what makes Redis extremely fast.

        Redis is built with LUA support. If you are totally new to LUA, you can read about it at http://www.lua.org/start.html. Basically it's a lightweight scripting language. You don't necessarily need to know LUA for working with Redis, but Redis provides support for lua scripts similar to stored procedures for SQL.

        Also Redis can be replicated i.e you can have Redis installed on different machines to read data and a master controlling these nodes. It is highly recommended to deploy Redis on linux machines.

Note: As per the Redis official website, there is no official support for Windows builds, but Microsoft maintains a Win-64 port of Redis.

        You might feel this post being too theoretical but believe me these points will help you decide the usage of Redis in your scenario. So just take a deep breath and continue reading.

        Next we will talk about Sentinel. Pay some attention here because it's kinda senti! Sentinel is a feature that provides an automatic failover mechanism. It's a built-in feature in v2.6+. It automatically promotes a slave to replace a failing master, also reconfigures other slaves to use the new master and informs about it to the client applications. Thus it provides high availability. 
        
       Generally when you're working with a database it's always difficult to monitor and configure it. But Redis Sentinel provides with tasks such as monitoring, notifications and acts as a configuration provider for clients. All in one! Isn't it???

Note: A prerequisite for using Sentinel for automatic failover is to have a master-slave replication setup

         Now lets talk more about Redis. Redis is a NoSQL database as you must be knowing till now i.e it has no schema and is much more flexible in its structure. But Redis actually is quite a bit different from other NoSQL databases such as mongodb or ravendb. These databases focus is to create documents which can be persisted on disk and can be indexed and hence these are known as document databases. 
       On the other hand, Redis stores its data using keys and the data stores can be in the form of different data structures not just a document. There is no kind of indexing in Redis. Offcourse you can implement it yourself but Redis does not provide any support as such. Redis only lets you get data by specifying the key. But it's very fast speed and less overhead over less query capability makes it suitable for certain conditions.





No comments:

Post a Comment