Blocks · Databases

db/redis

Redis. Independent Redis servers used as a cache; nothing is kept across restarts.

Overview

Runs the upstream redis-server with a generated configuration that sets the port, maxmemory and maxmemory-policy, and binds every address. Each replica is an independent Redis: the runtime does not set up replication between them, and its data directory is private to the unit, so data does not survive a restart. Treat it as a cache.

Shape
Replicas, independent
Reached at
Node port, or a VIP
Node package
pkgs.redis

Fetched on demand: the first time a block of this type is placed on a node, its agent fetches pkgs.redis, built from the node's own nixpkgs so the NixOS binary cache serves it. That first placement needs network access (or a binary cache on the LAN) and waits for the download; later placements on that node start at once.

Example

redis.yaml
apiVersion: expanse.io/v1
kind: Block
metadata:
  name: cache
  namespace: default
spec:
  type: db/redis
  replicas: 1
  resources:
    requests:
      cpu: 100m
      memory: 128Mi
  config:
    port: 16379
    maxMemory: 64mb
    maxMemoryPolicy: allkeys-lru
$ expanse ctl block apply -f redis.yaml --dry-run   # validate only
$ expanse ctl block apply -f redis.yaml

Configuration

Keys go under spec.config and are checked against the type's JSON Schema when the block is applied. A default is what the block uses when the key is unset.

KeyDefaultMeaning
portnone: always set itTCP port Redis listens on. Unset, the runtime writes port 0, which turns off the TCP listener. The deploy form sets 16379 and puts 6379 on the VIP.
maxMemory256mbmaxmemory.
maxMemoryPolicynone: always set itmaxmemory-policy, one of noeviction, allkeys-lru, volatile-lru, allkeys-random, volatile-random, volatile-ttl.
appendOnlynoneAccepted by the schema but not applied.
replicaOfnoneAccepted by the schema but not applied.
passwordnoneAccepted by the schema but not applied: there is no requirepass, so anyone who reaches the port can connect. Sealed: kept out of the stored block (block secrets).

Using it

$ redis-cli -h <node address> -p 16379 ping
PONG

Keep the port on a network you trust: the server has no password.

When a node fails

A failed node's replica is placed again on another node after the unreachable grace (30 s) and starts empty.

Limits

  • No persistence: the data directory is private to the unit and is discarded when it stops.
  • No replication or failover between replicas, although the type's description mentions a primary-replica strategy.
  • No authentication: password is ignored.

Source

All block types · Fields every block shares