Redis

What Redis is, the structures behind its keys, and where it sits next to PostgreSQL and Kafka on an OpenShift platform.

Updated CompTech Team

Redis is an in-memory data structure server. You give it a key, and the value is one of a small set of structures: a string, a list, a set, a sorted set, a hash, a stream. The working copy lives in RAM. A command on one shard runs to completion before the next command on that shard starts, so a single key update does not interleave with another.

That is a different job from PostgreSQL, which keeps the rows, the constraints and the joins, and from Kafka, which keeps an ordered log of events for as long as you configure. Redis keeps the value a pod needs again immediately, and the value several pods must see at once: a session, a cache entry, a counter, a lock, a short stream.

The wire protocol is RESP. Clients (redis-py, Lettuce, go-redis, StackExchange.Redis, redis-cli) speak it to port 6379. The same core commands work against community Redis, Valkey and Redis Enterprise. The OpenShift lab is where those three diverge.

Try the structures

Any current redis-cli is enough for this tour. A local container is fine; so is the Service from the next lab.

podman run --rm -p 6379:6379 docker.io/library/redis:8.2

In another shell, redis-cli with no arguments talks to 127.0.0.1:6379. Redis 8.2 is the long-term line. Valkey 9 (valkey/valkey:9.0) accepts the same commands below; its CLI is valkey-cli.

Strings

A string is bytes. Use it for a cached document, a counter, or a session blob.

redis-cli SET catalog:product:42 '{"sku":"42","price":120}' EX 300
redis-cli GET catalog:product:42
redis-cli TTL catalog:product:42
redis-cli INCR page:home:views

EX 300 sets a 300-second lifetime on the write. INCR is atomic: two pods can increment the same counter without a lock in the application.

Hashes

A hash is a handful of fields under one key. It fits a session or a product better than a new key per field.

redis-cli HSET session:7f3a user karim warehouse dac
redis-cli HGET session:7f3a user
redis-cli EXPIRE session:7f3a 1800

Lists, sets, sorted sets

redis-cli LPUSH user:karim:recent sku-42
redis-cli LRANGE user:karim:recent 0 9
redis-cli SADD sku:42:tags cotton export
redis-cli SISMEMBER sku:42:tags export
redis-cli ZADD ranking 10 karim 12 mina
redis-cli ZREVRANGE ranking 0 2 WITHSCORES

A list keeps order. A set keeps uniqueness. A sorted set keeps a score, which is how a ranking or a sliding window is stored. ZADD updates the score if the member is already there.

Streams

A stream is an append-only log inside one key, with consumer groups.

redis-cli XADD orders:placed '*' id 1001 sku 42
redis-cli XRANGE orders:placed - +

A stream is enough for a short buffer inside one application. It is the wrong tool for the event backbone: retention measured in days, several independent consumer groups across teams, and replay after a new service is deployed. That backbone is Kafka. The messaging lab draws the line, and the Kafka labs build the backbone on Streams for Apache Kafka.

Two commands are missing from this tour on purpose. KEYS walks every key and blocks the shard while it does. Use SCAN when you must search, and prefer a key scheme you can name exactly (catalog:product:42). Persistence (RDB snapshots and the append-only file) is the persistence lab, not a default you should assume here. A process with neither, and no replica, forgets everything when the pod exits.

One fact, one key

A shard runs a single command at a time. GET, HGET and INCR are short. KEYS, a huge SMEMBERS, or a Lua script that walks a large structure are not: every other client of that shard waits. Name a key so a writer can delete it without searching.

redis-cli TYPE catalog:product:42
redis-cli SCAN 0 MATCH 'catalog:*' COUNT 100

TYPE tells you which structure you stored. SCAN pages through the keyspace. The prefix is the whole invalidation plan: catalog: is a cache of Postgres, session: is a session, rate: is a counter. Those three do not belong in one TTL policy, which is why the caching lab separates them. A key that several commands must update together belongs on one shard. The curly-brace hash tag that forces that, {user}, is part of Cluster.

Next to PostgreSQL and Kafka

PostgreSQL Redis Kafka
Holds Current rows, constraints, joins Structures in memory, addressed by key An ordered log of events
A read SQL One key, or a range inside one structure The next records in a consumer group
After a pod restart The volume still has the rows The key is there only if a snapshot, the AOF or a replica had it The record is there if the topic was replicated and is inside retention
Typical owner The system of record A cache, a session, a counter, a lock The fact that something happened, for every subscriber

The catalog row is inserted and updated in PostgreSQL. Redis may hold a copy under catalog:product:42 so the next hundred reads skip the database. When the price changes, the application deletes that key. The caching lab is that pattern, including sessions shared by every pod behind a Route.

Kafka is how the change itself is announced. Debezium can read the PostgreSQL log and publish it, which is the path in the ingestion lab. Consumers update search indexes, caches and other databases at their own pace. Redis does not replace that log, and Kafka does not replace the row.

Red Hat Data Grid (Infinispan) is the other in-memory service we run on OpenShift, aimed at Java and .NET applications that want a clustered cache with its own client. The Data Grid labs cover it. Pick Redis when the clients are polyglot and the access is by key. Pick Postgres when the data must be the system of record. Pick Kafka when a later consumer must be able to replay.

Redis 8 also ships a JSON type and a query engine that can index vectors. Those belong to the vector-search lab. For a retrieval index that has to sit next to relational filters, the vector-databases lab uses pgvector and Milvus.

What this series runs

  1. Redis on OpenShift: an operator, then the choice between Redis Enterprise, community Redis and Valkey.
  2. Caching: cache-aside, expiry, invalidation, shared sessions.
  3. High availability: replication, Sentinel, Cluster, and a failover you can watch.
  4. Persistence and backup: RDB, AOF, restore, a second site.
  5. Pub/sub and streams: and when the bus should be Kafka.
  6. Vector search: Redis as a vector index, and a semantic cache.
  7. Security and monitoring: ACLs, TLS, Prometheus.