Valkey
Redis-compatible open-source in-memory data store. Community-driven development as Linux Foundation project. Stability based on Redis 7.2.
Cache Server
Valkey
Overview
Valkey is a Redis-compatible open-source in-memory data store supported by the Linux Foundation. Development began in March 2024 as a community-driven response to Redis's license changes, based on Redis 7.2.4. Supported by industry giants including AWS, Google Cloud, and Oracle, with development led by former Redis maintainers. It maintains complete compatibility with Redis API, CLI, and RESP protocol while remaining open source under the BSD-3-Clause license. Designed as a drop-in replacement, migration from Redis 7.2.4 to Valkey 7.2.5 can be achieved with minimal changes.
Details
Valkey 2024 edition has achieved rapid growth as a community-driven project ensuring Redis ecosystem continuity. Development under the Linux Foundation provides reliability and sustainability assurance, while collaboration between former Redis maintainers and enterprise partners maintains technical quality. Enhanced multithreaded I/O efficiently utilizes modern multi-core processors, solving the constraints of Redis's traditional single-threaded event loop. Supports multiple platforms including Linux, macOS, OpenBSD, NetBSD, and FreeBSD, providing extensibility through rich data types, Lua scripting, and module plugins.
Key Features
- Full Redis Compatibility: Complete API, CLI, and RESP protocol compatibility
- Linux Foundation Support: Sustainable development and community support
- Enhanced Multithreaded I/O: Efficient utilization of multi-core processors
- Open Source License: Unrestricted use under BSD-3-Clause license
- Enterprise Support: Backing from AWS, Google Cloud, Oracle, and others
- Rich Data Types: Strings, hashes, lists, sets, sorted sets, and more
Pros and Cons
Pros
- Extremely easy migration from existing Redis applications (drop-in replacement)
- Unrestricted commercial use under BSD-3-Clause license
- Long-term stability and continuity guaranteed by Linux Foundation support
- Enterprise-level technical support and ecosystem (AWS, Google, Oracle)
- Performance improvements through enhanced multithreaded I/O
- Active community development with rapid release cycles
Cons
- Relatively new project with limited long-term track record
- Smaller community size compared to original Redis
- Potential time lag in following latest Redis features
- Limited large-scale enterprise adoption cases yet
- Documentation and third-party tools still Redis-centric
- Uncertainty during ecosystem transition period
Reference Links
Code Examples
Installation and Basic Setup
# macOS (Homebrew)
brew install valkey
# Start as service
brew services start valkey
# Check service status
brew services info valkey
# Stop service
brew services stop valkey
# Alpine Linux
sudo apk update
sudo apk add valkey
# Install valkey-cli
sudo apk add valkey-cli
# Install Redis compatibility symlinks
sudo apk add valkey-compat
# CentOS/RHEL/Fedora
sudo yum install valkey
# Redis compatibility symlinks
sudo yum install valkey-compat
# Manual pages (man valkey.conf, etc.)
sudo yum install valkey-doc
# Ubuntu/Debian
sudo apt update
sudo apt install valkey
# Start Valkey server
valkey-server
# Start with configuration file
valkey-server /path/to/valkey.conf
# Test connection
valkey-cli ping
# PONG
Basic Configuration (valkey.conf)
# Network configuration
bind 127.0.0.1 # Allowed IP addresses
port 6379 # Listen port
tcp-backlog 511 # TCP connection queue
# Memory management
maxmemory 2gb # Maximum memory usage
maxmemory-policy allkeys-lru # Eviction policy when memory is full
# Persistence configuration
save 900 1 # Snapshot if 1+ changes in 900 seconds
save 300 10 # Snapshot if 10+ changes in 300 seconds
save 60 10000 # Snapshot if 10000+ changes in 60 seconds
# AOF persistence
appendonly yes # Enable AOF
appendfilename "appendonly.aof" # AOF filename
# Logging configuration
loglevel notice # Log level
logfile /var/log/valkey/valkey-server.log
# Security configuration
# requirepass your-password # Access password
# rename-command FLUSHDB "" # Disable dangerous commands
# rename-command FLUSHALL ""
# rename-command CONFIG ""
# Cluster configuration (when using cluster mode)
# cluster-enabled yes
# cluster-config-file nodes.conf
# cluster-node-timeout 5000
# Command line configuration examples
# ./valkey-server --port 6380 --replicaof 127.0.0.1 6379
Python redis-py Library Connection
import redis
import time
# Connect to Valkey server using Redis client (full compatibility)
valkey_client = redis.Redis(
host='localhost',
port=6379,
db=0,
decode_responses=True, # Return results as strings
socket_keepalive=True,
socket_keepalive_options={},
health_check_interval=30
)
# Test connection
try:
response = valkey_client.ping()
print(f"Valkey connection successful: {response}") # True
# Get server information
info = valkey_client.info()
print(f"Valkey version: {info.get('valkey_version', 'Unknown')}")
print(f"Used memory: {info['used_memory_human']}")
print(f"Connected clients: {info['connected_clients']}")
except redis.ConnectionError as e:
print(f"Valkey connection failed: {e}")
# Basic data operations
# String data operations
valkey_client.set('user:1:name', 'John Doe')
valkey_client.set('user:1:age', 30)
valkey_client.set('user:1:email', '[email protected]')
# Data with expiration
valkey_client.setex('session:abc123', 3600, 'session_data') # Expires in 1 hour
valkey_client.expire('user:1:name', 86400) # Expires in 24 hours
# Data retrieval
name = valkey_client.get('user:1:name')
age = valkey_client.get('user:1:age')
print(f"User: {name}, Age: {age}")
# Hash operations
user_data = {
'name': 'Jane Smith',
'age': '25',
'city': 'New York',
'job': 'Engineer',
'salary': '80000'
}
valkey_client.hset('user:2', mapping=user_data)
user_info = valkey_client.hgetall('user:2')
print(f"User info: {user_info}")
# Check field existence
if valkey_client.hexists('user:2', 'salary'):
salary = valkey_client.hget('user:2', 'salary')
print(f"Salary: {salary}")
# List operations
valkey_client.lpush('notifications', 'Message 1', 'Message 2', 'Message 3')
notifications_count = valkey_client.llen('notifications')
print(f"Notification count: {notifications_count}")
latest_notification = valkey_client.lpop('notifications')
print(f"Latest notification: {latest_notification}")
# Set operations
valkey_client.sadd('tags:python', 'web', 'api', 'automation', 'data-science')
valkey_client.sadd('tags:javascript', 'web', 'frontend', 'nodejs', 'api')
# Get common tags
common_tags = valkey_client.sinter('tags:python', 'tags:javascript')
print(f"Common tags: {common_tags}")
# Sorted set operations
valkey_client.zadd('leaderboard', {
'player1': 1000,
'player2': 1500,
'player3': 800,
'player4': 1200
})
# Get top players
top_players = valkey_client.zrevrange('leaderboard', 0, 2, withscores=True)
print(f"Top 3 players: {top_players}")
# Get players within score range
mid_range_players = valkey_client.zrangebyscore('leaderboard', 900, 1300, withscores=True)
print(f"Players with 900-1300 score: {mid_range_players}")
Valkey CLI Management Operations
# Connect with Valkey CLI
valkey-cli -h localhost -p 6379
# Interactive mode
valkey> PING
PONG
valkey> SET mykey "Hello Valkey"
OK
valkey> GET mykey
"Hello Valkey"
# Check server information
valkey> INFO server
# Valkey version, uptime, configuration info, etc.
valkey> INFO memory
# Memory usage, fragmentation ratio, etc.
valkey> INFO stats
# Statistics, connection count, processed commands, etc.
# Configuration check
valkey> CONFIG GET *
# Get all configuration parameters
valkey> CONFIG GET maxmemory
1) "maxmemory"
2) "2147483648"
# Monitor client connections
valkey> CLIENT LIST
# List of connected clients
valkey> CLIENT INFO
# Current client information
# Key operations
valkey> KEYS pattern* # Pattern matching for key search (not recommended for production)
valkey> SCAN 0 # Cursor-based key scanning (recommended)
valkey> EXISTS mykey # Check key existence
valkey> TYPE mykey # Check key data type
valkey> TTL mykey # Check remaining expiration time
# Multiple key existence check
valkey> MSET firstname Jack lastname Stuntman age 35
OK
valkey> EXISTS firstname lastname nonexistent
(integer) 2
# Database management
valkey> SELECT 1 # Switch database
valkey> FLUSHDB # Clear current DB
valkey> FLUSHALL # Clear all DBs (caution)
# Command information retrieval
valkey> COMMAND INFO get set eval
# Detailed information for specified commands
# ACL (Access Control List) management
valkey> ACL LIST
# User list
valkey> ACL USERS
# Username list
# Performance monitoring
valkey-cli --monitor # Real-time command monitoring
valkey-cli --latency # Latency monitoring
valkey-cli --stat # Statistics display
Cluster Configuration Example
# Cluster node configuration (valkey.conf)
port 6379
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
appendonly yes
# Create directories for multiple nodes
mkdir 7000 7001 7002 7003 7004 7005
# Create configuration files for each node
for port in 7000 7001 7002 7003 7004 7005; do
cat > $port/valkey.conf << EOF
port $port
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
appendonly yes
dir ./$port
EOF
done
# Start each node
for port in 7000 7001 7002 7003 7004 7005; do
cd $port
valkey-server ./valkey.conf &
cd ..
done
# Initialize cluster (using valkey-cli)
valkey-cli --cluster create 127.0.0.1:7000 127.0.0.1:7001 \
127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 \
--cluster-replicas 1
# Check cluster status
valkey-cli -c -h 127.0.0.1 -p 7000
127.0.0.1:7000> CLUSTER INFO
127.0.0.1:7000> CLUSTER NODES
System Service Configuration Example
# Create system directories
sudo mkdir /etc/valkey
sudo mkdir /var/valkey
# Copy configuration file
sudo cp valkey.conf /etc/valkey/6379.conf
# Copy init.d script (if provided)
sudo cp utils/valkey_init_script /etc/init.d/valkey_6379
# Grant execution permissions
sudo chmod +x /etc/init.d/valkey_6379
# Configure automatic startup on system boot
sudo update-rc.d valkey_6379 defaults
# Manual service start
sudo /etc/init.d/valkey_6379 start
# Check service status
sudo /etc/init.d/valkey_6379 status
# systemd configuration example
sudo tee /etc/systemd/system/valkey.service << EOF
[Unit]
Description=Valkey In-Memory Data Store
After=network.target
[Service]
User=valkey
Group=valkey
ExecStart=/usr/local/bin/valkey-server /etc/valkey/valkey.conf
ExecStop=/usr/local/bin/valkey-cli shutdown
Restart=always
[Install]
WantedBy=multi-user.target
EOF
# systemd management
sudo systemctl daemon-reload
sudo systemctl enable valkey
sudo systemctl start valkey
sudo systemctl status valkey
Replication Configuration Example
import redis
import time
# Primary server configuration check
primary = redis.Redis(host='127.0.0.1', port=6379, decode_responses=True)
# Replica server configuration
replica = redis.Redis(host='127.0.0.1', port=6380, decode_responses=True)
# Check replication status
def check_replication_status():
try:
# Set data on primary
primary.set('replication_test', f'data_{int(time.time())}')
# Check data on replica
time.sleep(0.1) # Wait for replication
replica_data = replica.get('replication_test')
print(f"Replication successful: {replica_data}")
# Get replication information
replication_info = replica.info('replication')
print(f"Replica role: {replication_info['role']}")
print(f"Master connection status: {replication_info.get('master_link_status', 'N/A')}")
except Exception as e:
print(f"Replication check error: {e}")
check_replication_status()
# Replication configuration change (from CLI)
# valkey-cli -p 6380
# 127.0.0.1:6380> REPLICAOF 127.0.0.1 6379
# 127.0.0.1:6380> REPLICAOF NO ONE # Stop replication