Overview
Redis is an open-source, in-memory data structure store used as a database, cache, message broker, and streaming engine. It supports data structures such as strings, hashes, lists, sets, and sorted sets with range queries, bitmaps, and more. Redis delivers sub-millisecond response times, making it ideal for caching, session management, and real-time analytics.
Redis server is installed by default with Centmin Mod (REDIS_SERVER_INSTALL='y') via the REMI YUM repository. The PHP phpredis extension is available via Menu Option 13.
Key Benefits
- Sub-millisecond latency — In-memory operations deliver extremely fast data retrieval for caching and sessions.
- Rich data structures — Supports strings, hashes, lists, sets, sorted sets, streams, and more beyond simple key-value.
- Persistence options — RDB snapshots and AOF logging allow data to survive restarts.
-
Nginx integration — Centmin Mod includes
ngx_http_redis,redis2-nginx-module, andlua-resty-redismodules.
Installation
Redis server is installed by default during the initial Centmin Mod LEMP stack installation via the REMI YUM repository. No manual steps are required for a fresh install.
Automatic Installation (Default)
The variable REDIS_SERVER_INSTALL='y' in centmin.sh ensures Redis is installed automatically. The REMI repository provides Redis 7.2 as a module stream on EL8+ systems.
Manual Installation via Addon Script
If Redis was not installed during initial setup, use the addon script:
/usr/local/src/centminmod/addons/redis-server-install.sh install
Upgrading Redis
To upgrade Redis from an older REMI module stream (e.g., 6.2 to 7.2) on EL8+:
/usr/local/src/centminmod/addons/redis-server-install.sh upgrade
Source Compile Option
For a source-compiled Redis 6.2.6 installation (instead of REMI RPM):
/usr/local/src/centminmod/addons/redis-server-install.sh install-source
OS Support: Redis server installation is supported on AlmaLinux 8/9/10, Rocky Linux 8/9/10, CentOS 7 (EOL), and other RHEL-compatible distributions.
PHP Redis Extension
The phpredis PHP extension provides a PHP API for communicating with the Redis server. Install or reinstall it via centmin.sh Menu Option 13.
Menu Option 13 Submenu
| Option | Description |
|---|---|
| 1 | Install Redis Server + PHP Extension |
| 2 | Install PHP Extension Only |
phpredis Version by PHP Version
| PHP Version | phpredis Version | Variable |
|---|---|---|
| PHP 7.4+ and 8.x | 6.3.0 | REDISPHPSEVENFOUR_VER |
| PHP 7.2 – 7.3 | 6.0.2 | REDISPHPSEVENTWO_VER |
| PHP 7.0 – 7.1 | 5.3.7 | REDISPHPSEVEN_VER |
| PHP < 7.0 | 4.3.0 | REDISPHP_VER |
Compression Support
The phpredis extension is compiled with support for multiple compression algorithms:
- zstd — Zstandard compression for efficient data storage
- LZ4 — Fast lossless compression
- LZF — Lightweight LZF compression
igbinary Serialization
The igbinary binary serializer is enabled for phpredis on PHP 7.x to reduce serialized data size. It is disabled on PHP 8.0+ due to known segfault risks with certain workloads.
igbinary serialization is automatically disabled for PHP 8.0+ builds to prevent potential segfaults. On PHP 7.x, it is enabled by default for better performance.
Configuration
Redis server configuration is managed through configuration files and systemd service settings.
Configuration Files
| File | Purpose |
|---|---|
/etc/redis/redis.conf |
Main Redis configuration (EL8+) |
/etc/redis.conf |
Main Redis configuration (CentOS 7 (EOL)) |
/etc/sysconfig/redis |
Systemd environment variables |
I/O Threads Auto-Scaling
Centmin Mod automatically configures Redis I/O threads based on CPU count:
| CPU Cores | I/O Threads |
|---|---|
| 1 – 3 | 1 (default, no threading) |
| 4 – 7 | 2 threads |
| 8 – 15 | 4 threads |
| 16+ | 8 threads |
System Tweaks
The Redis installer applies system optimizations:
vm.overcommit_memory=1— Allows background saves without memory allocation failures- Transparent Huge Pages (THP) disabled — Prevents latency spikes during forking
- Systemd
LimitNOFILE=524288— High file descriptor limit for busy servers
Service Management
# EL8/EL9/EL10 (systemd)
systemctl start redis
systemctl stop redis
systemctl restart redis
systemctl status redis
# CentOS 7 (EOL)
service redis start
service redis stop
service redis restart
Nginx Redis Integration
Centmin Mod compiles Nginx with several Redis-related modules for direct Redis integration at the web server level:
| Module | Version | Purpose |
|---|---|---|
ngx_http_redis |
0.4.0-cmm | Centmin Mod fork — direct Redis queries from Nginx config |
redis2-nginx-module |
0.15 | OpenResty Redis 2.0 protocol support for Nginx |
lua-resty-redis |
0.29 | Lua scripting Redis client for OpenResty/Nginx |
The ngx_http_redis module (0.4.0-cmm) is a Centmin Mod maintained fork that allows Nginx to query Redis directly for cached content, bypassing PHP entirely for cached pages.
Usage Examples
PHP Caching Example
<?php
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
// Store a value with 300-second TTL
$redis->setex('mykey', 300, 'cached_value');
// Retrieve the value
$value = $redis->get('mykey');
echo $value; // outputs: cached_value
?>
PHP Session Storage
Configure PHP to use Redis for session storage by adding to your php.ini or /etc/centminmod/php.d/ scan directory:
session.save_handler = redis
session.save_path = "tcp://127.0.0.1:6379"
WordPress Object Cache
For WordPress sites, Redis can be used as a persistent object cache via plugins like Redis Object Cache or Object Cache Pro. These plugins store WordPress transients, options, and database query results in Redis for faster page loads.
Monitoring
Use redis-cli to monitor Redis server status and performance:
# Full server info
redis-cli INFO
# Memory usage
redis-cli INFO memory
# Connected clients and stats
redis-cli INFO clients
# Real-time command monitoring (Ctrl+C to stop)
redis-cli MONITOR
# Key statistics
redis-cli INFO keyspace
# Latency check
redis-cli --latency
High used_memory relative to maxmemory indicates Redis may be evicting keys. Monitor evicted_keys in redis-cli INFO stats and increase maxmemory in redis.conf if needed.