Configure Redis Cache

Set up Redis as your query cache store for shared caching across processes.

Prerequisites

  • CQL installed

  • Redis server running

  • crystal-redis shard installed

Install Redis Shard

Add to your shard.yml:

dependencies:
  redis:
    github: stefanwille/crystal-redis
    version: ~> 2.8.0

Run shards install.

Basic Configuration

require "cql"
require "redis"

MyDB = CQL::Schema.define(
  :my_db,
  adapter: CQL::Adapter::Postgres,
  uri: ENV["DATABASE_URL"]
) do
  cache_store CQL::Cache::Redis.new(
    host: "localhost",
    port: 6379
  )
end

Connection Options

Using Redis URL

Key Prefixing

Namespace your cache keys:

All keys will be prefixed: myapp:cache:users:1

TTL Configuration

Connection Pooling

For high-traffic apps:

Cluster Support

For Redis Cluster:

Cache Operations

Monitoring

Check Redis cache stats:

Direct Redis monitoring:

Verify Configuration

Troubleshooting

Connection refused:

  • Verify Redis is running: redis-cli ping

  • Check host/port configuration

  • Check firewall rules

Authentication failed:

  • Verify password is correct

  • Check Redis requirepass configuration

Memory issues:

  • Set maxmemory in Redis config

  • Use maxmemory-policy volatile-lru

See Also

Last updated

Was this helpful?