Skip to main content
Aiven for Valkey is a fully managed in-memory NoSQL database service that offers high performance, scalability, and security. As an open-source Redis-compatible alternative under the Linux Foundation, Valkey ensures freedom from restrictive licensing while maintaining full compatibility with Redis OSS 7.2.4.

Overview

Valkey is an open-source fork of Redis designed to provide a seamless and reliable alternative to Redis OSS. With Aiven for Valkey, you can leverage high-performance in-memory data storage for caching, session management, real-time analytics, and more.

Why Choose Aiven for Valkey

Open Source

Licensed under permissive BSD-3 license, ensuring open-source availability and freedom

Redis Compatible

Fully compatible with Redis OSS 7.2.4 for seamless migration

High Performance

In-memory data store with microsecond latency for real-time applications

Rich Data Structures

Strings, hashes, lists, sets, sorted sets, bitmaps, hyperloglogs, and streams

Key Features

Valkey supports multiple data structures:
  • Strings: Simple key-value pairs
  • Hashes: Field-value pairs (like objects)
  • Lists: Ordered collections
  • Sets: Unordered unique collections
  • Sorted Sets: Ordered sets with scores
  • Bitmaps: Bit-level operations
  • HyperLogLogs: Probabilistic counting
  • Geospatial: Location-based data
  • Streams: Log-like data structures
Built-in replication and failover:
  • Primary-replica replication
  • Automatic failover
  • Sentinel for monitoring
  • Persistence options (RDB, AOF)
  • Business and Premium plans
Real-time messaging capabilities:
  • Channel-based messaging
  • Pattern-based subscriptions
  • Message broadcasting
  • Event-driven architectures
Server-side scripting:
  • Atomic operations
  • Complex logic execution
  • Reduced network overhead
  • Custom commands
Durable data storage options:
  • RDB: Point-in-time snapshots
  • AOF: Append-only file logging
  • Automatic backups every 24 hours
  • Configurable retention periods

Getting Started

1

Create Valkey Service

Deploy a Valkey service:
avn service create my-valkey \
  --service-type valkey \
  --cloud aws-us-east-1 \
  --plan business-4
2

Get Connection URI

Retrieve connection details:
avn service get my-valkey --format '{service_uri}'
Format: valkeys://default:password@host:port
3

Connect with CLI

Using valkey-cli or redis-cli:
valkey-cli -h valkey-service.aivencloud.com \
  -p 12345 \
  -a your-password \
  --tls
4

Run Commands

# Set a key
SET mykey "Hello Valkey"

# Get a key
GET mykey

# Set with expiration (60 seconds)
SETEX session:user123 60 "user_data"

# Check TTL
TTL session:user123

Connection Examples

import valkey
import ssl

# Create SSL context
ssl_context = ssl.create_default_context()

# Connect to Valkey
client = valkey.Valkey(
    host='valkey-service.aivencloud.com',
    port=12345,
    password='your-password',
    ssl=True,
    ssl_cert_reqs='required',
    ssl_ca_certs='/path/to/ca.pem'
)

# String operations
client.set('user:1:name', 'John Doe')
name = client.get('user:1:name')
print(name.decode('utf-8'))

# Hash operations
client.hset('user:1', mapping={
    'name': 'John Doe',
    'email': '[email protected]',
    'age': 30
})
user_data = client.hgetall('user:1')

# List operations
client.lpush('queue:tasks', 'task1', 'task2', 'task3')
task = client.rpop('queue:tasks')

# Set operations
client.sadd('tags:post:1', 'python', 'valkey', 'database')
tags = client.smembers('tags:post:1')

# Sorted set operations
client.zadd('leaderboard', {
    'player1': 1000,
    'player2': 1500,
    'player3': 1200
})
top_players = client.zrevrange('leaderboard', 0, 2, withscores=True)

# Expiration
client.setex('session:abc123', 3600, 'session_data')

# Pipeline for batch operations
pipe = client.pipeline()
pipe.set('key1', 'value1')
pipe.set('key2', 'value2')
pipe.get('key1')
results = pipe.execute()

client.close()

Common Use Cases

Improve application performance with caching:
import valkey
import json

client = valkey.Valkey(host='valkey-service', port=12345, password='pwd', ssl=True)

def get_user_profile(user_id):
    cache_key = f\"user:profile:{user_id}\"
    
    # Try cache first
    cached = client.get(cache_key)
    if cached:
        return json.loads(cached)
    
    # Fetch from database
    user_profile = fetch_from_database(user_id)
    
    # Cache for 1 hour
    client.setex(
        cache_key,
        3600,
        json.dumps(user_profile)
    )
    
    return user_profile

Performance Tips

Use connection pools to reuse connections:
from valkey import ConnectionPool, Valkey

pool = ConnectionPool(
    host='valkey-service.aivencloud.com',
    port=12345,
    password='your-password',
    ssl=True,
    max_connections=50
)

client = Valkey(connection_pool=pool)
Batch multiple commands:
pipe = client.pipeline()
for i in range(1000):
    pipe.set(f'key:{i}', f'value:{i}')
pipe.execute()
Choose the right data structure:
  • Use hashes for objects (more memory efficient than multiple keys)
  • Use sorted sets for rankings
  • Use bitmaps for boolean flags
  • Use HyperLogLog for approximate counting
Set expiration to manage memory:
# Set expiration on key creation
client.setex('temp_data', 3600, 'value')

# Set expiration on existing key
client.expire('existing_key', 7200)

# Get TTL
ttl = client.ttl('temp_data')

Monitoring and Maintenance

Key Metrics

Performance

  • Operations per second
  • Hit rate
  • Latency (avg, p95, p99)
  • Network throughput

Memory

  • Used memory
  • Memory fragmentation
  • Evicted keys
  • Key count

Replication

  • Replication lag
  • Connected replicas
  • Replication offset

Connections

  • Connected clients
  • Blocked clients
  • Connection errors

Monitoring Commands

# Server info
INFO

# Memory stats
INFO memory

# Replication status
INFO replication

# Client list
CLIENT LIST

# Slow log
SLOWLOG GET 10

# Monitor commands in real-time
MONITOR

Migration from Redis

1

Compatibility Check

Valkey is fully compatible with Redis OSS 7.2.4. Most applications work without changes.
2

Update Connection Strings

Simply point your application to the new Valkey service URI.
3

Test Your Application

Verify all functionality works as expected with Valkey.
4

Monitor Performance

Compare performance metrics to ensure expected behavior.

Apache Kafka

Use Valkey for Kafka consumer offset caching

PostgreSQL

Cache PostgreSQL query results in Valkey

Grafana

Monitor Valkey metrics in Grafana

Dragonfly

Alternative in-memory store for higher scale

Resources

Redis Compatibility: Valkey is fully compatible with Redis OSS 7.2.4, ensuring a smooth transition for existing Redis applications.

Build docs developers (and LLMs) love