2. Redis Introduction
• Redis is the leading opensource in-memory database
platform, supporting any high performance operational,
analytics or hybrid use case.
• Redislabs also offers commercial product called Redis
Enterprise.
• Redis is not a replacement for Relational Databases nor
Document Stores.
• Key characteristics – NoSql, Key value, In Memory, Open
source.
• Redis is an advanced key-value store, where keys can
contain data structures as values supporting a set of
atomic operations on these data types.
8. Redis Advantages
• Technology
• Procedure
• Policies
• Benefits
• No Schemas & column names.
• Support for complex datatypes &
structures.
• Atomic operations.
• Scalability.
• CLI availability.
• Performance.
• Availability.
• Fault Tolerance.
• Portability.
• Pipelining.
• Simple to install , setup and manage
• Highly Configurable
• Supported on many languages
• Straightforward and well
documented API
• Open source
• Available on Azure and AWS.
• LRU(Least Recently Used) eviction
of keys.
• Keys with limited time to live.
• LUA scripting support
11. Redis Vs Memcached
• Read/write speed:
– Both are extremely fast. Benchmarks vary by workload, versions, and
many other factors but Redis and Memcached are comparable in
terms of speed.
• Memory usage:
– Redis is better.
• Usability
– Memcached:
• We specify the cache size and as we insert items the daemon quickly grows
to a little more than this size.
• There is never really a way to reclaim any of that space, short of restarting
memcached. All our keys could be expired, you could flush the database,
and it would still use the full chunk of RAM you configured it with.
– Redis:
• Setting a max size is up to you. Redis will never use more than it has to
and will give us back memory it is no longer using.
12. Redis Vs Memcached
• Persistence:
– A clear win for Redis since it does this by default and has very configurable
persistence. Memcached has no mechanisms for dumping to disk without 3rd
party tools.
• Scaling:
– Redis provides tools to help for scaling while memcached does not.
• Documentation:
– Redis is better documented than memcached.
• Datatypes:
– Redis provides support for multiple data types however memcached does not.
13. Redis Vs MongoDB
• Read/write speed:
– Being in memory database Redis is faster than MongoDB.
• Usability:
– Redis is typically not a company’s only database but a faster alternative to an
existing database when they need more speed. MongoDB is more frequently
used as company’s only database.
– Redis is a great choice if we have a clearly defined data design and need very
fast access.
– MongoDB is great choice if we have structured and/or unstructured data
without clear definition of the data structure.
• Scalability:
– Because of MongoDB’s flexible design it scales better than Redis.
• Datatypes:
– Redis has multiple datatypes however MongoDB always stores data as
documents which can be modified on the fly.
14. Scaling Redis
Redis topologies
Standalone
– The master data is optionally replicated to slaves.
– The slaves provides data redundancy, reads off loading and save-to-disk
offloading.
– Clients can connect to the Master for read/write operations or to the slaves for
read operations.
– Slaves can also replicate to its own slaves.
– There is no automatic failover.
Sentinel (Automatic Failover)
– Redis Sentinel provides a reliable automatic failover in a master/slave topology,
automatically promoting a slave to master if existing master fails.
– Sentinel does not distribute data across nodes.
– Sentinel does the monitoring of master and slave nodes.
15. Scaling Redis
Twemproxy (Distribute Data)
– It works as a proxy between the clients and multiple Redis instances.
– It is able to automatically distribute data among different standalone Redis
Instances.
– Supports consistent hashing with different strategies and hashing functions.
– Multi-Key commands and transactions are not supported.
Cluster (Automatic Failover and distribute data)
– Redis Cluster distributes the data across different Redis instances and
perform automatic failover if any problem happens to any master instance.
– All nodes are directly connected with service channel.
– The keyspace is divided into hash slots. Different nodes will hold a subset of
hash slots.
– Multi-key commands are only allowed for keys in the same hash slot.
17. Redis Persistence
• Persistence in Redis is a matter of configuration, balancing trade off
between performance , disk I/O and data durability.
– RDB is a very compact single-file point-in-time representation of the
Redis dataset.
– AOF is a simple text log of write operations.
• RDB Advantages-
– RDB is compact and perfect for backups and for disaster recovery.
– RDB allows faster restarts with big datasets as compared to AOF.
– RDB maximizes Redis performance since only work the Redis parent
process needs to do in order to persist is forking a child that will do
all the rest.
18. Redis Persistence
• RDB Disadvantages-
– RDB is not good to minimize the chance for data loss in case Redis
stops working. In this case the last minutes data can be lost.
– RDB needs to fork a child process to persist on disk. Fork can be time
consuming if the dataset is big and the CPU performance not great.
This may result in Redis to stop serving clients for few milliseconds.
– RDB snapshoting generates a higher volume of disk writes because
whole file is being rewritten each time.
19. Redis Persistence
• AOF Advantages-
– AOF log is an append only log, there are no corruption problems if
there is a power outage.
– AOF generates less blocks writes to disk because data is only
appended to file.
– Redis is able to automatically rewrite to AOF in background.
• AOF Disadvantages-
– AOF takes more time to load in memory on server restart.
– AOF can be slower than RDB
– AOF files are usually bigger than the equivalent RDB files for the
same dataset.
20. Redis and Security
Network Security
– It is possible to just listen to one or multiple interfaces using “bind” configuration
directive followed by one or more IP addresses.
– Designed to be accessed by trusted clients inside trusted environments.
– Does not allow external access / Internet exposure.
– Redis is not optimized for maximum security but for maximum performance and
simplicity.
Authentication Feature
– Redis provides a layer of authentication that can be turned on by updating the
configuration file. Client can authenticate itself by sending AUTH command followed
by password.
Data Encryption
– Data encryption is not supported
Disabling Specific Commands
– It is possible to disable commands in Redis or to rename them into an un-guessable
name so that clients are limited to a specified list of commands.
String Escaping and No SQL Injection
– Redis protocol has no concept of string escaping so injection is impossible.
– The protocol uses prefixed length strings and is completely binary safe.
21. Redis Application
• Redis POC Application
– Spring Boot app to do basic CRUD operation for a sample Data in Redis.
– Tech stack Spring Boot ,Thymeleaf library, Java 8,Gson library, Spring Data Redis.
• Following Steps were done for the application-
– Installed Redis on Linux Redhat OS/Windows as well as created instance on Microsoft
Azure.
– Created the REST Web service application to do basic CRUD operation for a sample
Data in Redis.
– Secured the Web service with MFA using Okta.
– Installed and setup Redis GUI for viewing the data stored in Redis datastore.
– Experimented with Redis GUI- Redis Desktop manager.
23. About me
• Nikhil Dole
• nik_dole@yahoo.com
• https://www.linkedin.com/in/nikhil-dole-
96bb2015/
• @NikhilDole
• https://github.com/NikhilDole
Notes de l'éditeur
Summarize presentation content by restating the important points from the lessons.
What do you want the audience to remember when they leave your presentation?
Save your presentation to a video for easy distribution (To create a video, click the File tab, and then click Share. Under File Types, click Create a Video.)