Redis is open-source NOSQL advanced Key-value database, which is written in C. ReDiS is the short form of “Remote Dictionary Server”, so you can write itRediS too based on the short form of Redis. It also referred to as a data structure server. This is more than the distributed key-value, in-memory , replication of key, for caching server.
Redis is not only used for cache solutions and Session Management but you can say, this is more than caching. Redis is most widely used in caching solution space. Here, I’m going to share with you high level stuff about Redis one by one. I know, explaining all the things in one post is not feasible, it’s only high level.
1. Feature of Redis
- Data is being persistent in-memory as well as stored on disk that’s make Redis fast.
- Redis supports simple master-slave replication.
- Redis can execute 1,00,000 queries per second.
- Redis can be used for PUB/SUB or QUEUE .
2. Advantages of using Redis
- High speed
- Support pub/sub , queue, durability
- Server-side locking
- Rich Client Side Library
- Support Atomic Operation
3. Limitations of Redis
- Single threaded
- It has got limited client support for consistent hashing
- It has significant overhead for persistence
4. Which one you choose Speed OR Durability?
If you ask yourself , Redis gives you which one , Speed or Durability or both? Answer is NO, Redis purposely compromise the durability to enhance the speed. In Redis, in the event of system failure or crash, Redis writes to disk but may fall behind and lose the data which is not stored.
In order to improve durability in Redis, or you can say, to improve the durability of Redis, uses “append only file” strategu, which can be configured by using
fsync data on disk. But be careful when you configure
Fsync()every time : a new command is added to the append log file: It is safe but very slow.
Fysnc()one time every second: It is fast, but you may lose 1 second of data if system fails.
fsync(): It is an unsafe method, and your data is in hand of Operating System.
5. List of operation keys of Redis
Key operations of Redis includes:
- TYPE key
- TTL key
- KEYS pattern
- EXPIRE key seconds
- EXPIREAT key timestamp
- EXISTS key
- DEL key
6. Few use case of Redis
- For Distributed Caching
- for storing of app session
- for pub/sub
- for Que
7. Why one should use Redis?
Following are the list of reasons to use
Redis in your distributed Application but this is not final.
- Data Replication: by supporting multilevel master-slave cluster set up Replication supports multiple & multilevel slaves.
– Automatically restores & partially (re)synchronizes the master-slave connections on outrage.
- Publish-Subscribe Interface: designed over the paradigm of high decoupling, it facilitates user by providing a ready to use publication & subscription interface
- Expiry with TTL: Redis keys could be configured/set to automatically expire on specified time interval for each key.
- LRU (Least Recently Used) Capabilities: the ‘maxmemory’ directive is used in order to limit the memory usage to a fixed amount. On reaching at max memory usage, it evicts the keys as per specified LRU policies among 6 available options.
- Ease of Use: easy to use commands. It supports high-level, atomic & server-side operations (no need to write code) like intersection, union between sets or Sorting of lists, sets etc.
- Automatic Failover & Highly Available (HA): it supports clustering via Redis Sentinel, a system designed to monitor cluster-instances, notify user if something goes wrong, handle failover by electing new master and act as configuration provider.
- Partially Transactional: it supports partially ACID (atomic, consistent, isolated, durable) transactions. A transaction would start by executing MULTI command and flush then exit by executing DISCARD. The transaction supports CAS (check-and-set) behavior but can’t roll-back.
- Great Performance: when get/set keys during heavy load time. Though it works in single-threaded model, it offers faster read/writes than any RDBMS due to its in-memory nature. it serves One lac of key in a sec if you required more than this then you have to configure cluster.
- Database as a Service: it is deployed & available as a managed service on all leading cloud providers like Amazon, Rackspace …
- Partially Secure: it is designed to be accessed by trusted clients inside trusted environments only. While it does not try to implement Access Control, it provides authentication layer that could be turned on by editing the ‘redis.conf’ file. In secure mode, it is required by client to authenticate itself by sending the ‘AUTH’ command followed by the password before executing any data request.
- Persistence by Snapshotting: perform point-in-time snapshots of your dataset at specified intervals (configurable) in a binary file called ‘dump.rdb’. It is configurable to take snapshot at specified intervals or can be done manually by executing ‘SAVE’ or ‘BGSAVE’ commands.
- Persistence by Append Only File (AOF) & Log Rewriting: every time ReDiS receives a command that changes the dataset/value, it will append it to the AOF. When you restart Redis it will re-play the AOF to rebuild the state.
- Supported programming languages: JAVA, C, C#, PHP, Python, JS, Perl, Ruby etc.
- Scripting Support: it supports LUA Scripting. LUA is a cross platform & light weight language