What is Redis

W

Redis is a different data storage paradigm when compared to SQL data systems. The Redis developers are calling it a data structures server, an excellent naming convention because the Redis philosophy starts from the idea that data should be stored in RAM. In this way, Redis can perform high-speed operations in principle, eliminating the tedious process we encounter, for example, in SQL, where data is written on the disk.

It is considered to be the most important NoSQL model, based on key-value items. It proves to be superior in scalable applications, especially in machine clusters, where it is more flexible than the tables of a relational database.

Redis has three characteristics

1. Redis keeps the entire database in memory but uses the HDD as a backup.
2. It has an extensive set of data types: strings, hashes, lists, sets.
3. Redis can replicate the data to any number of workers.

Because data structures are used with values ​​that can contain complex data types, atomic operations can be defined on these types.
Even though data is stored in volatile memory, it is persistent on disk. The idea is that asynchronous write and read operations are made into the RAM, is made much faster and with obvious advantages, and persistence is a background process distinct from the two elementary operations.

It is also important to note that Redis works only on UNIX-based systems.

Installing Redis on Ubuntu

sudo apt-get update
sudo apt-get install redis-server
redis-server
redis-cliredis 127.0.0.1:6379> Test

Being a system based on the key-value duality, they occupy a central place in the system architecture. Keys are secure from a binary standpoint, which means that any binary sequence can be used as a key, from a string like a foo to the contents of a JPEG file. An empty string is also a valid key.

Major recommendations on how keys should be:
1. It should not be very long, because finding them in the data set requires a series of costly comparisons.
2. Very short keys are not helpful because they are hard to handle and memory gain is not significant.
3. It is recommended to follow a scheme, so there may be a set of rules by which a key can easily be found.

The String type is the simplest type of value that can be associated with a Redis key. The string type is useful in multiple cases, for example, for storing some HTML fragments.
Redis uses linked lists to manage items in a set. The advantage is that adding new items is done in constant time. A new item is added to a list of 10 items at the same time as added to a list of one million. The main drawback occurs when accessing items where access time is proportional to the number of nodes in the list.
The main reason Redis uses linked lists is that it is crucial for a database to be able to add new records very quickly.

LPUSH adds a new item to the top of the list
RPUSH adds a new item to the list queue
LRANGE extracts the range of elements from a list (0 first element, -1 last)

Redis hashes are only field-value pairs

Hash is very useful for representing objects where we have properties and values. It is good to know that a hash has no limit on the number of fields.
Sets are stringless collections of strings. The SADD command tests adding new items to the set. Several other operations on sets such since testing whether an element already exists, making a junction, union, or difference between multiple sets are allowed.

Redis vs. MySQL

Redis philosophy starts from the idea of ​​storing data in memory for rapid and easy management through value key relationships. MySQL, on the other hand, is more rigid, but it has the advantage of scalability.
Most current systems have little volatile memory compared to external storage media, and for many applications, this limitation could lead to essential problems along the way without complex mechanisms that can properly store data.
Redis is an ideal mechanism for small applications or tasks that need to be very fast. For example, storing Cookies or Sessions or other computational operations is easier to control from internal memory.
Redis is an innovative NoSQL system that offers unmatched speed compared to other relational systems based on Codd’s model. This speed comes mainly from the way information is stored, but also from the simplicity of calling it. In Redis, all operations are reduced to the modeling of key pairs – volatile memory value.

Recent Posts

Archives

Categories