Redis is an in-memory key-value data structure store. It often used as a database, cache, and message broker. It supports various data structures, including strings, lists, sets, hashes, and sorted sets, making it useful for building fast and scalable applications. This tutorial demonstrates how to install Redis on Ubuntu 26.04.
Install Redis
Add the official APT repository and signing key:
sudo tee /etc/apt/sources.list.d/redis.sources >/dev/null <<EOF
Types: deb
URIs: https://packages.redis.io/deb
Suites: $(lsb_release -sc)
Components: main
Signed-By:
$(curl -sS https://packages.redis.io/gpg | sed "s/^/ /")
EOF
Update the package lists:
sudo apt update
Install Redis:
sudo apt install -y redis
Once installation is completed, we can check Redis version:
redis-server --version
You can check whether Redis service is running with command:
sudo service redis-server status
We can also stop, start and restart the Redis service:
sudo service redis-server stop
sudo service redis-server start
sudo service redis-server restart
Testing Redis
Connect to the Redis server with client:
redis-cli
For connectivity testing, use PING command. Server returns PONG.
127.0.0.1:6379> PING
PONG
SET and GET commands can be used to store and retrieve value by key.
127.0.0.1:6379> SET message "Hello"
OK
127.0.0.1:6379> GET message
"Hello"
Type QUIT command to exit the Redis prompt.
127.0.0.1:6379> QUIT
Uninstall Redis
Remove Redis by using the following command:
sudo apt purge --autoremove -y redis
Remove the repository configuration file:
sudo rm -rf /etc/apt/sources.list.d/redis.sources
You can also remove a history of commands executed with Redis client:
rm -rf ~/.rediscli_history
Leave a Comment
Cancel reply