What is Redis?
Redis an is a data structure server, Remote Data Server written in C Language.It is an in-memory database cache for storing and retrieving data. It is open-source software with an active community.
All the databases stores and retrieve the data from disk. Operation such as disk reading and writing is costly on a database. In the case of Redis, Data is read and store in the memory cache and gives the best performance.
It is easy to read and write from a programming language with few lines of code.
Even though Redis is a memory cache server, It supports deploying in a single or cluster node architecture and provides horizontal and vertical scaling. Because of this, it is highly available.
Data also can be replicated across multiple nodes in big data architecture.
It supports a different kinds of data such as String, Sets, Lists, SortedSet, Hashes, and Bitmaps
Redis use case application
For example, You are developing a multi-tenant hr sass application for the web.
In this application, Each tenant can hold details such as company name, security as well as company employee information.
Usually, store this company metadata as well as the employee in the database.
In the HR application,
multiple tenants log in to application and do the below steps
- Login to hr application with tenant user details, need to make SQL query for every operation to get tenant details
- once the login is successful, Application has the below operations
- Show a list of employees for each tenant
- He can add or modify employee data on the tenant.
For each employee processing, you need to SQL query to get tenant details. Two database calls need to be made for every operation.
To avoid this, Move the tenant details to the in-memory database and the employee to the database.
This reduces the loading time.
Is Redis a cache only?
Redis stores the key and value pairs. It support different types of value objects datatypes.
It is not simple cache to store in memory, But lot of useful features It provides operations to How to process from the collections and provides the model schema for any type of application.
It supports plain strings, collection of strings such as List and set, and object hierarchy to store in the in memory.
It also supports persist the data to disk to have reliability. Also provides replication to have master slave to not loose data in case of failures.
Server with pub/sub commands
- stores key and value pairs in memory cache
- Support multiple data types data as values in pairs
- Supports to store data into disk for persistence
- publish and subscribe model
- Master Slave Replication to have a better read access and automatic failover
- Sharding for better write access
- Supports scripting to have more advanced usage on how to manipulate data in memory
- API to Query GEO features such as Radius
When to use Redis database over SQL Database?
Redis db is used in following applications
- Storing user session information
- short lived personized data
- Shopping cart data
- Logged in user preferences