Redis (stands for Remote Directory Server) is a data structure store that runs in memory. It's a disk-persistent key-value database that can handle a variety of Data Structures or data types.
In addition to mapping key-value-based strings for storing and retrieving data (similar to the data model offered by traditional types of databases), Redis supports other complicated data structures such as lists, sets, and so on. As we go forward, we'll look into the tools that Redis supports.
Tools that Redis uses
There are broadly three tools that can be discussed briefly to understand why they are necessary. Namely, they are CLI, GUI, and PROXY. Let's learn more about them in brief.
What is CLI?
The redis-cli (Redis-command line interface) is a terminal tool used to send commands to the Redis server and read responses from it. It has two primary modes: interactive REPL (Read Eval Print Loop) mode, in which the user enters Redis commands and receives responses, and command mode, in which redis-cli is executed with additional arguments and the response is displayed to standard output.
Redis-cli includes basic line editing features in interactive mode to provide a familiar typing experience.
Use the command to execute as separate arguments of redis-cli to run a Redis command and receive its response as standard output to the terminal.
$ redis-cli INCR mycounter
>(integer) 7
The command's response is "7." Because Redis responses are typed (strings, arrays, integers, nil, errors, and so on), the type of the response is shown between parenthesis. This extra information may be inconvenient if the output of redis-cli is to be utilized as the input of another command or routed into a file.
When redis-cli recognizes that the standard output is a tty or terminal, it only displays additional information for human readability. It will automatically enable the raw output mode for all other outputs, as shown in the following example:
Because redis-cli identified that the output was no longer being written to the terminal, (integer) was excluded from the output. With the —raw option, you can force raw output even on the terminal:
$ redis-cli --raw INCR mycounter
>9
Also, you can force to output the human-readable output when writing to a file or in pipe to other commands by using --no-raw.
SSL/TLS in CLI
By default, redis-cli connects to Redis through a standard TCP connection. To configure a trusted root certificate bundle or directory, use the —tls option in combination with —cacert or —cacertdir. If the target server requires client-side certificate authentication, use —cert and —key to specify a certificate and corresponding private key.
Insertion of Data
You can use redis-cli in two ways to receive input from other commands via standard input. The target payload can be used as the last parameter from stdin. For example, use the -x option to configure the Redis key net_services to the content of the file /etc/services from a local file system:
$ redis-cli -x SET net_services < /etc/services
OK
$ redis-cli GETRANGE net_services 0 50
"#\n# Network services, Internet style\n#\n# Note that "
The above session's first line ran redis-cli with the -x option, and a file was routed to the CLI's standard input as the value to meet the SET net_services command phrase. This is beneficial for scripting.
Another approach would be to feed redis-cli a sequence of commands written in a text file:
$ cat /tmp/commands.txt
SET item:3374 100
INCR item:3374
APPEND item:3374 xxx
GET item:3374
$ cat /tmp/commands.txt | redis-cli
OK
>(integer) 101
>(integer) 6
>"101xxx"
Redis-cli executes all of the commands in commands.txt in the same order as if the user in interactive mode typed them. Strings can be quoted within the file if necessary, allowing for single arguments with spaces, newlines, or other special characters:
$ cat /tmp/commands.txt
SET arg_example "This is a single argument"
STRLEN arg_example
$ cat /tmp/commands.txt | redis-cli
OK
>(integer) 25
We looked at running the Redis CLI as a command-line program. This is helpful for scripts and certain types of testing, but most people will use redis-interactive cli mode most of the time.
The user enters Redis commands at the prompt in interactive mode. The command is transferred to the server, which processes it, and the response is parsed and converted into a more readable format.
Nothing unusual is required to run the redis-cli in interactive mode; simply run it without any arguments.
$ redis-cli
127.0.0.1:6378> PING
PONG
The string 127.0.0.1:6378> is prompted. It displays the connected Redis server's instance's hostname and port.
In interactive mode, you can perform the same command many times by prefixing the command name with a number:
The CLI can publish messages in Redis Pub/Sub channels using the PUBLISH command. Subscribing to channels to receive messages is different since the terminal is blocked and waits for messages. Hence redis-cli implements this as a unique mode. Unlike previous special modes, this mode is activated by simply using the SUBSCRIBE or PSUBSCRIBE commands, which are available in interactive or command mode:
This is quite beneficial for debugging Pub/Sub bugs. To quit the Pub/Sub mode, simply press CTRL-C.
Replica Mode
The CLI's replica mode is advanced functionality useful for Redis developers and debugging actions. It enables the inspection of the content that a primary provides to its replicas in the replication stream to transmit writes to its replicas. The option is simply called —replica. As an example, consider the following:
$ redis-cli --replica
SYNC with master, discarding 13256 bytes of bulk transfer...
SYNC done. Logging commands from master.
"PING"
"SELECT","0"
"SET","last_name","Enigk"
"PING"
"INCR","mycounter"
The command begins by discarding the first synchronization's RDB file and then logs each command received in CSV format.
Suppose you think some of the commands are not being replicated correctly in your replicas. In that case, this is an excellent way to investigate what's going on and critical information for improving the bug report.
Let's move to learn about the GUI.
GUI
There are many tools available for Redis Graphical User Interface. We will discuss some of them.
RedisInsight
RedisInsight is a free Redis GUI that works with all Redis variations and is available on all platforms (Windows, Mac, Linux, and Docker). You may use RedisInsight to:
🛑The Overview tool displays performance information for your Redis instance.
🛑Using the Browser tool, you may see data structures visually.
🛑The Cluster Management tool allows you to manage basic Redis cluster properties such as cluster node timeout, IP address, and port.
🛑Use the CLI tool to run commands with a REPL (read-eval-print-loop).
🛑Utilize the Memory Analysis tool to examine memory utilization.
🛑Using the Slowlog tool, you can identify and troubleshoot bottlenecks.
🛑Using the Configuration Tool, you can modify the configuration of your Redis instance.
🛑RedisInsight also supports a number of Redis modules, such as RedisGraph, RedisTimeSeries, and RediSearch
Redis Desktop Manager
RESP.app or Redis Desktop Manager provides an easy-to-use graphical user interface (GUI) for accessing your Redis servers and performing some simple operations:
🔥Consider keys in the form of a tree.
🔥CRUD functions
🔥Analyze memory use for the entire database or a specific namespace in a tree-view (Redis >= 4.0 is required).
🔥List the connected clients, the Pub/Sub channels, and the Slow Log commands.
🔥RESP.app lets you do bulk processes, which simplifies developer's daily routines.
🔥Copying data from the production environment to the development environment for debugging, or migrate your project to a different cloud provider.
🔥Import data from RDB files - You may simply split huge rdb files into numerous smaller redis-servers or import only a subset of data.
🔥TTL can be set for multiple keys.
🔥Delete keys that match the glob-pattern
Redis Browser
This web-based explorer view of your Redis database is delivered as a Ruby gem. It is the youngest of the tools in this review and probably the simplest. Simplicity, however, is sometimes a virtue, especially when you need a no-frills, dead-simple GUI.
These are generally used for Redis GUI. Let's move on to discuss the proxy tool in redis.
Proxy
Redis Cluster Proxy is a Redis Cluster proxy. Redis can run in Cluster mode, which means that a group of Redis instances will handle failover and partitioning. This unique mode requires the usage of specific clients that understand the Cluster protocol: by using this Proxy instead, the Cluster is abstracted away, and you can communicate with a group of Redis Cluster instances as if they were a single instance. Redis Cluster Proxy is multi-threaded and currently employs a multiplexing communication mechanism by default. Each thread has its own connection with the Cluster, which is shared by all clients belonging to the thread itself. In any event, there are a few exceptions.
(for example, MULTI transactions or blocking instructions), multiplexing is disabled, and the client has its own cluster connection. Clients performing simple commands like GETs and SETs will no longer require a private set of connections to the Redis Cluster.
So, these are the main features of Redis Cluster Proxy:
🚥Routing: Each query is automatically routed to the correct cluster node.
🚥Multithreaded
🚥Both multiplexing and private connection models supported
🚥Even in multiplexing scenarios, query execution and response order are ensured.
🚥When ASK|MOVED errors occur in replies, the Proxy automatically updates its internal representation of the Cluster by requesting an updated configuration and remapping all the slots. All queries will be re-executed when the update is complete. Everything appears normal to the client (the clients will not receive the ASK|MOVED error: they will receive the expected replies after the cluster configuration has been updated).
🚥Cross-slot/cross-node queries: Many commands are supported that involve multiple keys belonging to separate slots (or even distinct cluster nodes). These commands will divide the query into many queries, which will be sent to a different slot/node. The handling of replies for those commands is command-specific. Some commands, such as MGET, will combine all responses into a single response. Other operations, such as MSET or DEL, will total the responses. Because some searches violate the command's atomicity, their use is optional (disabled by default).
🚥Some commands with no specific node/slot, such as DBSIZE, are issued to all nodes, and the replies are map-reduced to produce a sum of all the values contained in all the replies.
🚥The PROXY command is an additional command that can perform proxy-specific tasks.
🚥Redis Cluster Proxy should work fine on most POSIX systems (Linux, macOS/OSX, 🚥NetBSD, FreeBSD) and the platforms that Redis supports.
🚥It requires C11 and its atomic variables. Therefore make sure your compiler supports both C11 and atomic variables (_Atomic). Those features are supported by GCC version 4.9 or later.
Webdis
A small web server that provides an HTTP interface to Redis. It makes use of hiredis, jansson, libevent, and the http-parser. Webdis is reliant on libevent-dev. On Ubuntu, type sudo apt-get install libevent-dev, and on macOS, type brew install libevent.
Redsmin Proxy, tinywebdis were also used in Tool for Proxy in redis.
FAQs
What is Redis, and why do we use it?
Redis is typically used as a cache to store frequently accessed data in memory, allowing applications to respond to users. Redis provides a variety of intelligent caching patterns by allowing you to choose how long you want to hold data and which data to evict first.
How is data stored in the Redis?
Data is saved in memory because Redis is an in-memory database (or RAM). If a server fails, all data saved on it is gone. Redis has backup procedures in place for disc data. The data is loaded from the drive into memory when the server reboots.
What type of database Redis is?
Redis is a form of database that is also known as No SQL or non-relational. There are no tables in Redis, and there is no database-defined or -enforced method of linking Redis data to other Redis data.
Is Redis a Database or a Cache?
Redis was initially designed as a cache database, but it has subsequently developed into a primary database. Many modern applications use Redis as their primary database. However, most Redis service providers only provide Redis as a cache, not as a core database.
Why do we need the Redis cache?
Because Redis supports a wide range of value types and even value structures, several potential applications exist.
Conclusion
In this article, we have extensively discussed the three most essential tools in redis, namely, CLI, GUI, and PROXY. We have learned about their basic commands and how they differ from their subordinate service providers.
We hope that this blog has helped you enhance your knowledge regarding redis and if you would like to learn more, check out our articles on Code studio and our courses here.