Beginners guide to REDIS

Welcome to this blog. We shall be looking at following topics in this blog :-

  • Fundamentals of Redis.

Question :- Which language is Redis written into ?

Answer :- Redis is an open source data-structure server written in NCC, which makes it friendly with Unix-based systems like Mac or Linux without any other dependencies. But for Windows, it is a different story, because we need a special port of Redis.

Question :- What’s the primary purpose of using Redis ? Quote an example.

Answer :-

  • We can store multiple data types like strings, hashes, and streams, and access them by a unique key name.

Question :- Are there any keySpaces or schemas in Redis ?

Answer :-

  • All keys in the Redis database are stored in a flat key space.

Question :- Can you now introduce Redis in layman’s language ?

Answer:- Redis is an open-source, in-memory data structure store which supports saving/retrieving variety of data, through Key-Value Pairs. Redis also has high availability, replication, and automatic-partitioning.

Question:- What are Keys and Values in Redis ?

Answer:-

  • Keys in Redis are pretty much like keys that you see in any other language i.e. objects with a key-value pair approach.

Question :- Which data-structures are supported easily for the Values ?

Answer:- Variety of data-structures are supported, namely :-

  • Strings → Setting value as a string. In above example, we have set the value as a String only.

Question :- Why Redis is so popular about the Speed ?

Answer :- The speed Redis is famous for is mostly due to the fact that :-

  • Redis stores and serves data entirely from RAM-Memory instead of disk, as most other databases do.

Question :- Can Redis NOT take advantage of multiple CPU-cores ?

Answer :- Indeed, this means that open source Redis can’t take advantage of the processing power of multiple CPU cores, although CPU is rarely the bottleneck with Redis. We are more likely to bump up against memory or network limitations before hitting any CPU limitations.

Question :- What happens behind the scenes with every Redis request ?

Answer:- When a client sends a request to a Redis server :-

  • The request is first read from the socket.

Note that, the reading and especially writing to a socket are expensive operations.

Question :- Has there any optimisations not been done to parallelise these expensive operations (i.e. Read & Write into Socket) ?

Answer:- Yes, In Redis version 6.0, multi-threaded I/O was introduced. When this feature is enabled, Redis can delegate the time spent reading and writing to I/O sockets over to other threads, freeing up cycles for storing and retrieving data, and boosting overall performance by up to a factor of two for some workloads.

Question :- Can you talk something about the Redis Client-Server architecture ?

Answer:- Redis has a client-server architecture and uses a request-response model.

  • Applications send requests to the Redis server,

Question :- What’s the role of a Redis client library ?

Answer:- Redis Client Library acts as an intermediary between our application and the Redis server. Client libraries perform the following duties :-

  • Implement the Redis wire protocol, the format used to send requests and receive responses from the Redis server.

Question :- How does Redis Clients communicates with Redis-Server ?

Answer:- Redis clients communicate with the Redis server over TCP using a protocol called RESP, Redis Serialisation Protocol, designed specifically for Redis.

  • The RESP protocol is simple and text based, so it is easily read by humans as well as machines.

Question :- What’s the problem with creating new connections each time ?

Answer:- Creating and recreating new connections over and over again, creates a lot of unnecessary load on the server. Therefore, a good client library will offer some way of optimising connection management, by setting up a connection pool, for example.

Question :- How does Connection-Pooling helps ?

Answer:- With connection pooling, the client library will instantiate a series of (persistent) connections to the Redis server and keep them open.

  • When the application needs to send a request, the current thread will get one of these connections from the pool, use it, and return it when done.

Question :- What’s the usual process of interacting with Redis ?

Answer:- Each client does a (typically blocking) read on a socket and waits for the server response.

  • The server reads the request from the socket, parses it, processes it, and writes the response to the socket.

Now, say for example, you needed to execute 50 commands, you would have to send a request and wait for the response 50 times, paying the RTT cost every single time.

Question :- Can we optimise the aforementioned approach ?

Answer:- To tackle this problem, Redis can process new requests even if the client hasn’t already read the old responses. This way, you can send multiple commands to the server without waiting for the replies at all; the replies are read in the end, in a single step. This technique is called pipelining and is another good way to improve the performance of your system. Most Redis libraries support this technique out of the box.

Question :- What’s the main advantage of Pipelining ?

Answer:- Pipelining reduces the network round trip time by sending multiple commands to the server in a single round trip.

References :-

--

--

Software Engineer for Big Data distributed systems

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store