What it is, Where does it come from & What is used for?
Redis - Stands for ‘Remote Dictionary Server’ it is an in-memory data structure project it implements a distributed, in-memory key-value database with optional durability. Redis’s developer is Salvatore Sanfilippo who was trying to improve the scalability of the startup.
Written in ANSI C.
Initial release |
May 10, 2009 |
Stable release |
6.0.9 / October 26, 2020 |
Redis supports different kinds of abstract data structures, such as:
- Strings
- Lists
- Maps
- Sets
- Sorted Sets
It's a fast, open-source in-memory key-value data store for use as a :
- Database
- Cache
- Message broker
- Queue
Redis delivers sub-millisecond response times enabling millions of requests per second for real-time applications:
- Gaming
- Ad-Tech
- Financial Services
- Healthcare
- IoT *Platform Allows For The Consumption Of External Data Sources To Enhance & Enrich Data.
How does Redis work?
Redis data resides in memory. The best thing I feel about ‘Redis’ from what I have learned is that it eliminates the need to access disks. Again, in contrast to databases that store data on disk or SSDs, as said before ‘Redis’ is in-memory.
Redis features:
- Abstract Data Structure
- High Availability
- Geospatial Transactions
- On-Disk Persistence
- Cluster Support *makes it simpler to build real-time internet-scale apps
Redis vs Memcached:
Redis and Memcached are in-memory, open-source data stores. Memcached is a high-performance distributed memory cache service, it's designed for simplicity and Redis offers a set of features that makes it more effective for a wide range of use cases.
It works in relational or key-value databases to improve performance, such as:
- MySQL
- Postgres
- Aurora
- Oracle
- SQL Server
- DynamoDB + more
Redis benefits:
Redis data resides in the server’s memory
- PostgreSQL
- Cassandra
- MongoDB
- Others *that store most data on a hard disk or on SSDs.
In-memory datastore
Most operations require a roundtrip to the disk compared to conventional disk-based, in-memory data stores, just like Redis, and it doesn't receive the same penalty.
Therefore, operations have faster response times to and from. The results are really quick on performance with the average read or write operations. It takes less than a millisecond and supports millions of operations per second.
Flexible data structures
Redis has a variety of data structures to meet application needs, not like simplistic key-value data stores which will offer limited data structures.
Redis data types include:
- Strings: Text or binary data up to 512MB in size;
- Lists: Collection of Strings in the order they were added;
- Sets: Un-Ordered collection of strings with the ability to intersect, union, and diff other Set types;
- Sorted Sets: Ordered by a value;
- Hashes: Data structures for storing a list of fields and values;
- Bitmaps: Data types that offer bit-level operations;
- HyperLogLogs: a complete probabilistic data structure to estimate the unique items it stores in a data set;
Simplicity does make things easier-to-use
Redis simplifies the codes enabling it to write fewer lines of code to the store access, it will use the data in your application/s. If your application has data stored in a *hashmap (*An instance of HashMap has two parameters that affect its performance: initially capacity and the load factor.
https://en.wikipedia.org/wiki/Hash_table), you will want to store that data in a data store. You can then simply use the Redis hash data structure to store the data.
Another task on the datastore with no 'hash' data structure would need many more lines of code just to convert it from one format to another format. Redis comes with a local or endemic data structure and many options to manipulate and interact with your data.
Replication and Persistence
Redis employs a primary-replica architecture and it supports asynchronous replication where the data can be replicated if needed to multiple replica servers. This will provide an improved read performance on requests and faster recovery when the primary server experiences any downtime. Redis requests can be split among the servers. So for persistence, Redis supports point-in-time backups, which just basically copies the Redis data set to disk.
High availability with ‘scalability’
Redis has a primary-replica architecture in a single primary node or a clustered topology. This will allow you to build highly available solutions while providing consistent performance and reliability. When needed to adjust your cluster size, many options are also available to scale up and scale in or out. This will also allow your cluster to grow with more demands.
Application has ‘extensibility’
Redis is an open-source project just like Magento and it’s supported by a lively community. No vendors or technology locks, as Redis is open standards-based, it supports open data formats and features with a great set of clients.
Redis Use Cases
Cache/ Caching
Redis is a great choice when choosing a highly available ‘in-memory cache’ to decrease data access latency, that increases through output, it eases the load off NoSQL database and /or application/s.
- Database Query results caching
- Persistent session caching
- Web page caching
Caching frequently used objects such as images, files, and metadata are all popular examples of caching with Redis.
Chat, Messaging, and Queues
Redis supports Pub/Sub and pattern matching plus a variety of data structures such as:
- Lists
- Sorted sets
- Hashes
This allows Redis to support high-performance for:
- Chat rooms
- Real-Time comment streams
- Social Media feeds
- Server Intercommunication
The Redis list data structure makes it easier to implement a lightweight queue. Lists offer operations with blocking capabilities, making them suitable for a variety of applications that need a reliable message broker.
Gaming leaderboards
Redis is a popular choice among game developers looking to build real-time leaderboards. They simply use the Redis 'Sorted Set' data structure, this provides unique elements while maintaining the list sorted by users' scores. Real-time rank lists are as easy as updating a user's score for each time it changes. Sorted Sets can also be used to handle time-series data by using timestamps for the score.
Rich media streaming
Offers in-memory data store to power live streaming use cases. It can be used to store metadata about users' profiles plus viewing histories, and authentication information for millions of users, the manifest files to enable CDNs to stream videos to millions of mobile and desktop users at a time.
Geospatial
Redis offers purpose-built in-memory data structures and operators to manage real-time geospatial data at scale and speed.
Commands such as:
- GEOADD
- GEODIST
- GEORADIUS
- GEORADIUSBYMEMBER
Plus the real-time analysis of ‘geospatial data’ makes geospatial easy and fast to a store.
Machine Learning
Modern data-driven applications do require machine learning to process a massive volume, variety, and velocity of data quickly. Use cases include fraud detection in gaming and financial services, real-time bidding in ad-tech, and matchmaking in dating, and the ability to process live data to make decisions within tens of milliseconds is very important. Redis provides a fast in-memory data store to build, train, and deploy machine learning models fast.
Real-time analytics
It can handle streaming solutions such as:
- Apache Kafka
- Amazon Kinesis
It is used as an in-memory data store to ingest, process, and analyze real-time data with sub-millisecond latency. Redis becomes the ideal choice for real-time analytics use cases such as:
- Social Media Analytics
- Ad Targeting
- Personalization
- IoT *Platform Allows For The Consumption Of External Data Sources To Enhance & Enrich Data.
Redis Modules
External modules are used to extend Redis functionality. Adding new Redis commands with features that are similar to what can be done to the core itself.
These Redis modules are dynamic libraries, which can be loaded at Redis startup or using the ‘MODULE LOAD’ command. Modules are supposed to be written in C, it will however be possible to use C++ or other languages that have C binding functionalities.
*Redis Modules https://redis.io/modules
Redis Installation
Download and extract Redis:
$ wget
https://download.redis.io/releases/redis-6.0.9.tar.gz
$ tar xzf redis-6.0.9.tar.gz
$ cd redis-6.0.9
$ make
The binaries that are compiled are now available in the src directory.
You Run Redis with:
$ src/redis-server
You can use the Redis built-in client:
$ src/redis-cli
redis> set foo bar
OK
redis> get foo
"bar"