Distributed Cache Example
Demonstrates a Redis-backed distributed cache using RedisStore.
What it shows
- Connecting to Redis via the
rueidis client
- Creating a
RedisStore with a key prefix for namespacing
- Wrapping it in a type-safe
Cache[Order] with a default TTL
Set, Get, Delete operations against Redis
- TTL expiration behaviour
Prerequisites
A running Redis instance (default: localhost:6379).
# Start Redis with Docker
docker run --rm -p 6379:6379 redis:7-alpine
Override the address with the REDIS_ADDR environment variable:
REDIS_ADDR=redis.example.com:6379 go run ./examples/distributed/
Run
go run ./examples/distributed/