How to Install Redis in Debian 13 (trixie)
This guide covers installing and configuring Redis on Debian 13 (Trixie) using the Debian package repository.
Debian 13 currently provides Redis through the redis-server package.
1. Update the System
sudo apt update
sudo apt upgrade -y
2. Install Redis
Install Redis Server:
sudo apt install redis-server -y
The package also installs Redis command-line tools such as redis-cli.
Verify the installation:
redis-server --version
Check the CLI version:
redis-cli --version
3. Enable Redis Service
Enable Redis to automatically start during boot:
sudo systemctl enable redis-server
Start Redis:
sudo systemctl start redis-server
Check its status:
sudo systemctl status redis-server
You should see:
Active: active (running)
The Debian package provides the systemd service:
redis-server.service
and the main configuration file:
/etc/redis/redis.conf
4. Test Redis
Run:
redis-cli ping
Expected response:
PONG
You can also enter the Redis CLI:
redis-cli
Then test:
SET test "Hello Redis"
GET test
Expected:
"Hello Redis"
Exit:
exit
Configuration
The main Redis configuration file is:
/etc/redis/redis.conf
Edit it with:
sudo nano /etc/redis/redis.conf
After changing the configuration, restart Redis:
sudo systemctl restart redis-server
Network Configuration
Local-Only Redis
For applications running on the same server, Redis should normally only listen on localhost.
Check:
bind 127.0.0.1 -::1
and:
protected-mode yes
Then applications can connect using:
127.0.0.1:6379
This is the preferred configuration when Redis does not need to be accessed from another machine.
Allow Redis Access from Other Servers
If Redis needs to be accessed from another application server, Kubernetes node, or internal VM, edit:
sudo nano /etc/redis/redis.conf
Find:
bind 127.0.0.1 -::1
For example, if the Redis server has an internal network IP:
10.10.10.20
you can use:
bind 127.0.0.1 10.10.10.20
This is preferable to:
bind 0.0.0.0
because Redis will only listen on the interfaces that actually need it.
Restart Redis:
sudo systemctl restart redis-server
Verify listening ports:
sudo ss -lntp | grep 6379
Example:
LISTEN 0 511 127.0.0.1:6379
LISTEN 0 511 10.10.10.20:6379
Security: Do not expose Redis port
6379directly to the public Internet.
Use a private network, VPN, firewall, or other trusted network boundary.
Authentication
For a simple single-password installation, Redis supports password authentication.
Edit:
sudo nano /etc/redis/redis.conf
Find:
# requirepass foobared
Change it to:
requirepass YOUR_STRONG_PASSWORD
For example:
requirepass ChangeThisToAVeryStrongPassword
Restart:
sudo systemctl restart redis-server
Now:
redis-cli ping
will return an authentication error.
Authenticate using:
redis-cli -a 'YOUR_STRONG_PASSWORD' ping
Expected:
PONG
You can also connect first:
redis-cli
Then:
AUTH YOUR_STRONG_PASSWORD
Redis also supports ACL-based users, which are preferable when multiple applications or services require different Redis permissions.
Test Redis from Another Server
From another Debian/Linux machine:
sudo apt install redis-tools -y
Then connect:
redis-cli \
-h 10.10.10.20 \
-p 6379 \
-a 'YOUR_STRONG_PASSWORD'
Test:
PING
Expected:
PONG
Firewall
If ufw is being used, do not simply expose:
sudo ufw allow 6379/tcp
to everyone.
Instead, allow only the application network or specific server.
For example:
sudo ufw allow from 10.10.10.0/24 to any port 6379 proto tcp
Or allow only a specific application server:
sudo ufw allow from 10.10.10.30 to any port 6379 proto tcp
Check:
sudo ufw status
Enable Persistence
Redis can persist data using RDB snapshots, AOF, or a combination of both.
For applications where losing Redis data during a restart is undesirable, enabling AOF is a common configuration.
Edit:
sudo nano /etc/redis/redis.conf
Set:
appendonly yes
appendfsync everysec
Restart:
sudo systemctl restart redis-server
Redis documents appendfsync everysec as a good balance between performance and durability. With this mode, approximately one second of recent writes can potentially be lost during a catastrophic failure.
Configure Maximum Memory
For a dedicated Redis server, it is usually useful to explicitly limit how much memory Redis may consume.
For example, on a server with enough RAM to allocate 4 GB to Redis:
maxmemory 4gb
You should leave sufficient memory for:
- Debian
- Redis process overhead
- fork/COW operations during persistence
- filesystem cache
- monitoring agents
- other services
Do not normally configure Redis to consume 100% of available system RAM.
Configure Eviction Policy
If Redis is primarily being used as a cache, configure an eviction policy.
For example:
maxmemory-policy allkeys-lru
This allows Redis to evict less-recently-used keys when the configured memory limit is reached.
A cache-oriented configuration might therefore look like:
maxmemory 4gb
maxmemory-policy allkeys-lru
For Redis being used as persistent application storage, the appropriate eviction policy depends on the application and should be chosen carefully.
Linux Memory Configuration
Redis benefits from Linux memory overcommit being enabled.
Check the current value:
sysctl vm.overcommit_memory
Set it immediately:
sudo sysctl vm.overcommit_memory=1
Make it persistent:
sudo nano /etc/sysctl.d/99-redis.conf
Add:
vm.overcommit_memory = 1
Apply:
sudo sysctl --system
Redis recommends correctly configuring overcommit_memory on Linux and having enough memory to avoid swapping.
Recommended Basic Production Configuration
A simple Redis server on a private network might have:
bind 127.0.0.1 10.10.10.20
protected-mode yes
port 6379
requirepass YOUR_LONG_RANDOM_PASSWORD
appendonly yes
appendfsync everysec
maxmemory 4gb
maxmemory-policy allkeys-lru
The exact maxmemory and eviction policy should be selected based on the Redis workload.
Restart Redis
Whenever /etc/redis/redis.conf is changed:
sudo systemctl restart redis-server
Check status:
sudo systemctl status redis-server
Check logs:
sudo journalctl -u redis-server
Follow logs continuously:
sudo journalctl -u redis-server -f
Useful Commands
Server Information
redis-cli INFO
With authentication:
redis-cli -a 'YOUR_STRONG_PASSWORD' INFO
Memory Information
redis-cli -a 'YOUR_STRONG_PASSWORD' INFO memory
Connected Clients
redis-cli -a 'YOUR_STRONG_PASSWORD' CLIENT LIST
Current Database Size
redis-cli -a 'YOUR_STRONG_PASSWORD' DBSIZE
Redis Configuration
redis-cli -a 'YOUR_STRONG_PASSWORD' CONFIG GET '*'
Monitor Commands
For temporary debugging:
redis-cli -a 'YOUR_STRONG_PASSWORD' MONITOR
MONITORcan have significant performance impact on busy Redis servers. Use it only for short debugging sessions.
Check Redis Memory
redis-cli -a 'YOUR_STRONG_PASSWORD' INFO memory
Important values include:
used_memory
used_memory_human
used_memory_rss
maxmemory
maxmemory_human
mem_fragmentation_ratio
Check Persistence
redis-cli -a 'YOUR_STRONG_PASSWORD' INFO persistence
Important values include:
rdb_last_save_time
rdb_last_bgsave_status
aof_enabled
aof_last_write_status
aof_last_bgrewrite_status
Backup
Redis persistence data is normally stored under the directory configured by:
dir
Check it:
redis-cli -a 'YOUR_STRONG_PASSWORD' CONFIG GET dir
Check the RDB filename:
redis-cli -a 'YOUR_STRONG_PASSWORD' CONFIG GET dbfilename
Do not blindly copy an actively changing Redis persistence file as a backup strategy without understanding the selected RDB/AOF persistence configuration.
Connection String Examples
Without Authentication
localhost:6379
With Authentication
10.10.10.20:6379,password=YOUR_PASSWORD
The exact connection-string syntax depends on the Redis client library.
ASP.NET Core Example
For StackExchange.Redis, an application configuration could look like:
{
"Redis": {
"ConnectionString": "10.10.10.20:6379,password=YOUR_PASSWORD,abortConnect=false"
}
}
Registration example:
using StackExchange.Redis;
builder.Services.AddSingleton<IConnectionMultiplexer>(_ =>
{
return ConnectionMultiplexer.Connect(
builder.Configuration["Redis:ConnectionString"]!);
});
A single shared ConnectionMultiplexer is generally used rather than creating a new Redis connection for each operation.
Basic Health Check
redis-cli \
-h 127.0.0.1 \
-p 6379 \
-a 'YOUR_STRONG_PASSWORD' \
ping
Expected:
PONG
Uninstall Redis
Stop Redis:
sudo systemctl stop redis-server
Remove the package:
sudo apt remove redis-server redis-tools -y
To also remove configuration files:
sudo apt purge redis-server redis-tools -y
Then:
sudo apt autoremove -y
Quick Installation Summary
For a simple local Redis installation:
sudo apt update
sudo apt install redis-server -y
sudo systemctl enable redis-server
sudo systemctl start redis-server
redis-cli ping
Expected:
PONG
For a production Redis instance, additionally configure:
/etc/redis/redis.conf
with:
protected-mode yes
requirepass YOUR_LONG_RANDOM_PASSWORD
appendonly yes
appendfsync everysec
maxmemory 4gb
maxmemory-policy allkeys-lru
and configure Linux:
echo "vm.overcommit_memory = 1" | \
sudo tee /etc/sysctl.d/99-redis.conf
sudo sysctl --system
sudo systemctl restart redis-server
References
- Redis officially supports installation on Debian/Ubuntu using APT.
- Debian 13 (Trixie) provides
redis-serverandredis-toolspackages. - Redis persistence documentation describes RDB/AOF persistence and the
appendfsync everysecdurability/performance trade-off.





