REDIS is one the most popular Cloud storage Open Source software with wide ranging applications. This first part puts forth the data model and a few essential algorithms of the REDIS designBANGALORE, INDIA: REDIS is an advanced key-value store that has a number of useful structures that directly help in writing several class of distributed computing applications. In this article, we will focus on REDIS, its architecture and the data model. In the subsequent issue, we will dig deep on how REDIS can be used from a .NET client.
Traditionally, REDIS is actually more than a data structure server and sometimes it is also referred to as the remote data structure server. It has a simplified and clean implementation of Hash Table, Doubly Link List, Un-Sorted and Sorted Sets.
The core server itself is a Hash Table server where the keys are strings and values could be of any types from the above data structures. That is, in REDIS, you have a key where values can be a list or a sorted set or a Hash Table. And like the usual data structure operations, you have ample operations that are provided to manipulate the remote structure. Working with REDIS is very simple. If you have not installed REDIS, go forth and grab the source.
The REDIS server includes a group of databases and it's default configuration supports up to 16 of them. By default when you connect to the REDIS server, you always connect to the database numbered '0'. To override and use a different database, a simple 'SELECT' command is used.
In this example, I created a key with 'key1' and value as 'hello world'. To create the key, we use SET and to retrieve the value we use GET. According to REDIS, keys are always strings and they are binary safe. Binary safe is a class of string functions which doesn't decipher any special character in a string and hence in REDIS you can have keys of any type.White space, null, carriage return, etc can also be included in a key.
Thus 'key1', 'key/crlf1', etc are allowed. When you try to enter a new key-value pair, REDIS server first looks for the key in the hash table; if at all it exists, the new value is overwritten else a new key is created in the hash table and corresponding value is set. Since, the server is a hash table implementation, the complexity of GET and SET is no more than O(1). Since the value stored is a string, therefore like your usual string operations as supported in Java, C#, you can manipulate by inserting, deleting, iterating and find the length of the stored value.
However, unlike our programming language class libraries, REDIS supports a special set of functions called INCR, DECR, INCRBY, DECRBY. These functions operate when the stored value is an integer or a double. However, important to note is that all operations that you perform on the server are atomic and at a time only one thread acts on a key.
This feature has the advantage of keep things simple but indicates that only a single client operating on a key can work at a time. Inherently, there is no support for concurrency and updates from multiple clients to the same key may overwrite the values stored earlier. In the simplest usage of a REDIS key-value pair, the last write wins and there is no way you can retrieve the previous values. To circumvent, however, there are a few primitives that are designed and we shall discuss them later.
Click here to read more!