Nov 05, 2020 Installing Redis from scratch. Using package management software, like Homebrew. Homebrew automates most of the installation process, making it quick and easy to add Redis to your system. It also provides more options when configuring Redis, and makes uninstalling it a lot simpler. Install Redis via Homebrew. GitHub Gist: instantly share code, notes, and snippets. Homebrew’s package index. Also known as: redis@6.2 Persistent key-value database, with built-in net interface.
Introduction
Redis is an in-memory key-value store that can execute millions of requests per second for running real-time applications. While the program can be used as a cache or message broker, Redis is most often used as a database. It supports basic and advanced data structures from strings, list and sets to geospatial indexes. The Redis CLI, an acronym for command line interface, is a straightforward program that allows users to communicate with Redis directly from the terminal. This tutorial will provide an overview and instructions on how to use the Redis CLI.
Prerequisites
- Redis must be properly installed and configured on the local device. Executing the
sudo systemctl status redis
command in Linux distros that use systemd will display the current status of the Redis database on the local machine.
Install Redis
Install Redis on machines having a Windows or Mac OS by downloading the file here. Homebrew on Mac OS can also be used to install Redis.
Install Redis on Linux
For Debian-based Linux distros, such as Ubuntu or Linux Mint, execute the following APT-GET Update command on the local machine to get the current version of Redis:
sudoapt-get update |
Once updated, execute the following command to install Redis: Lilo and stitch games speed chase.
Now execute the following command to set Redis to run automatically on the local machine:
sudo systemctl enable redis-server |
Install Redis using Homebrew
To install Redis on a Mac OS with the Homebrew package manager, first update the package to get the latest version of the Redis database. Once the update is completed, then execute the following command to install the updated package:
After installation, execute the following command to start the database:
brew services start redis |
Now execute the following command to have Redis continually run in the background:
Now use the Redis-command line interface to confirm the program is working properly:
redis-cli 127.0.0.1:6379>ping PONG |
Redis command line usage
Redis use a straightforward command-line interface to provide features that can work around database functionality and other issues.
Begin by executing the following command to create a connection:
linux@linux-NECq:~$ redis-cli -h 127.0.0.1 -p6379-a mypassword |
NOTE: The -a
option will perform the authentication of the password.
The next two examples will cover two of the basic commands in the Redis command-line interface.
This first example uses the INCR
operator:
linux@linux-NECq:~$ redis-cli incr count (integer)3 |
Here the function displays an integer value of 3
, but it can also be used to list the returned value of a string, arrays, the null or any errors.
The next example will create an output of the Redis CLI in a file that is readable to humans:
linux@linux-NECq:~$ redis-cli incr count >/tmp/output.txt linux@linux-NECq:~$ cat/tmp/output.txt 4 |
Here the INCR
key operation causes the integer value to increase incrementally. Note the value is shown in the output, and not in the terminal. However, executing the following --raw
option will force the output to display on the terminal:
Redis host and password
The Redis command-line interface can be used to change the default value of Redis to the default host 127.0.0.1
and the default port 6379
. This will permit an easier connection to the server to Redis.
The next example shows how to connect to and use the Redis instance in the command line:
linux@linux-NECq:~$ redis-cli -h 127.0.0.1 -p6379-a mypassword ping PONG |
Now execute the INCR
key function, covered earlier, to produce the values that will be inserted into five rows of data: Stickys mixmaster.
linux@linux-NECq:~$ redis-cli -r5 incr count (integer)6 (integer)7 (integer)8 (integer)9 (integer)10 |
Now execute the following operation to confirm the status of the Redis database was properly set:
linux@linux-NECq:~$ redis-cli -h 127.0.0.1 -p6379-a mypassword --stat ------- data --------------------------- load -------------------- - child - keys mem clients blocked requests connections 36 887.05K 405315(+0)6 36 887.02K 405317(+2)6 36 887.02K 405321(+4)6 36 887.02K 405323(+2)6 36 887.05K 405326(+3)6 36 887.02K 405328(+2)6 36 887.05K 405331(+3)6 36 887.02K 405333(+2)6 36 887.05K 405336(+3)6 36 887.02K 405338(+2)6 36 887.05K 405341(+3)6 36 887.02K 405343(+2)6 36 887.05K 405347(+4)6 36 887.02K 405349(+2)6 36 923.04K 405352(+3)6 36 887.02K 405354(+2)6 36 923.02K 405356(+2)6 36 923.02K 405359(+3)6 36 887.02K 405360(+1)6 36 887.05K 405363(+3)6 |
This gives an overview of how many of the keys are set in the Redis database, the total memory usage and generates an overall view of Redis, as a whole.
Conclusion
This tutorial provided a basic overview of how to use the Redis CLI. The tutorial explained how to install Redis on machines with Windows and Mac OS, Debian-based Linux distros and how to use Homebrew to install Redis on Mac. The article also covered how to start the database and set Redis to continually run in the background. The tutorial then explained how to use the Redis command-line interface to confirm the program is working, how to change the default value of Redis for easier connection and then how to confirm that the status of the Redis database was properly set. Remember that the INCR
key operation will causes the integer value to increase incrementally, but the value is not displayed in the terminal unless the --raw
option is used.
You can download the latest version of Redis from https://redis.io/download.
Redis can be installed on any server. In this case we’ll install it locally for testing.
Homebrew Redis
On macOS, installation is simpler using Homebrew. Run:
Then run
to make Redis start automatically, and re-start when the computer reboots.
You can also start it manually using:
Homebrew Redis Game
On Linux Ubuntu you’ll need to run
and Redis will automatically be up and running.
Once it’s started, Redis listens on port 6379.
On a local server it’s fine to keep it running without a password. But when Redis is exposed to the Internet, make sure you configure a password in the redis.conf
configuration file, whose location depends on your Operating System.