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 of Dictionary types.
It is open-source software with an active community.
All the databases such as MySQL and oracle 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.
Redis is a memory cache server, It supports deploying in a single or cluster node architecture, 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
Redis use case application
Let’s see where Redis is fit into Multi layer database.
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(User Login Details,) 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 Login 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
- User can add or modify employee data on the tenant.
For each employee processing, you need to make two SQL query to get tenant details. Two database calls(Login Call, All Employees per Tenant) need to be made for every operation. For each tenant, Database call is an DISK operation, and expensive operation. Multiple tenants users makes multiple calls, which is expensive opration
To avoid this, Move the tenant details to the
in-memory database for faster retrieval and the employee to the database. It
This reduces the loading time to improve the performance.
Following are use cases in Enterprise applications
- Login Session or Cookie in Enterprise Applications
- Shopping Cart In Enterprise Applications
- Generated Web page caching
- Web Page Visits
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 and Faster access
- 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