instalar-redis-en-raspberry-pi

How to Install Redis on Raspberry Pi

  • 5 min

Redis is an in-memory, key-value data structure database, widely used for caching, session storage, and other applications requiring high speed and performance.

Unlike traditional disk-based databases, Redis stores all information in RAM, providing ultra-fast access to data.

Redis is known for its low latency and high performance, making it ideal for home automation projects, web application development, and distributed systems on the Raspberry Pi.

Some of its main features are,

  • Persistence: Although it’s an in-memory database, Redis can persist data to disk via snapshots or transaction logs.
  • Replication: Supports master-follower replication and cluster creation.
  • Pub/Sub: Allows inter-process communication using a publish-subscribe model.
  • Atomicity: Offers atomic operations and transactions to ensure data integrity.

Installing Redis on Raspberry Pi

Before starting the installation, we ensure the system is up to date. Run the following commands to update our system:

sudo apt update sudo apt upgrade

Now we can install Redis from the official repositories. Redis is available in the Debian repositories, so the installation is quite simple. Simply run the following command to install Redis:

sudo apt install redis-server

Start and Enable the Redis Service

Redis starts automatically after installation. To make sure the service is running, use the following command:

sudo systemctl status redis-server

To start or restart Redis, you can use the following commands:

sudo systemctl start redis-server sudo systemctl restart redis-server

Also, enable the service to start automatically on boot:

sudo systemctl enable redis-server

Basic Redis Configuration

Redis is primarily configured through its configuration file, located at /etc/redis/redis.conf. You can modify this file to adjust Redis’s configuration according to your needs.

By default, Redis runs on port 6379 and listens only on the local interface (localhost). You can change network, persistence, and security settings by modifying the configuration file.

To edit the configuration file, use the nano editor:

sudo nano /etc/redis/redis.conf

After making changes to the configuration file, save and close the file.

Testing the Redis Installation

To verify that Redis is working correctly, you can use the redis-cli command-line tool to connect to the Redis server:

redis-cli

Inside the Redis CLI, you can test basic commands like PING to verify connectivity:

127.0.0.1:6379> PING PONG

You can also perform basic operations, such as storing and retrieving values:

127.0.0.1:6379> SET mykey “luisllamas_es!” OK 127.0.0.1:6379> GET mykey “luisllamas_es!”

Redis also provides many other useful features, such as lists, sets, hashes, etc. These features can be used to store and retrieve data efficiently.