๐Ÿง  KVUpdater

Step 2 in the Redis-first architecture chain. This Python service listens to a Redis pub/sub channel, extracts structured data from incoming messages, and persists it to the Redis key-value store. Data Architecture Overview

๐Ÿ“ฆ Overview

KVUpdater is designed to handle real-time updates in a Redis-first system. It subscribes to a Redis pub/sub channel, receives JSON-formatted messages, and stores them in Redis using the type field as the key. Optionally, it can validate that the data was correctly written.

๐Ÿงญ Architecture Diagram

flowchart LR
  subgraph Kubernetes
    Microservice -- PUB update --> Redis
    Redis -- SUB update --> KV-Updater
    KV-Updater -- WRITE KV --> Redis
    Redis -- SUB update --> APIServer
    APIServer -- READ KV --> Redis
  end
  Client -- READ API --> APIServer
  APIServer -- SSE update --> Client
style Microservice fill:#08f,color:#fff
style Redis fill:#e22,color:#fff
style KV-Updater fill:#eea,color:#000
style APIServer fill:#3d3,color:#fff
style Client fill:#fe1,color:#000
style Kubernetes fill:#fff,stroke:eea,stroke-width:1px,color:#444
linkStyle 4,5 stroke:#00F,color:blue

๐Ÿ”„ Flow Summary

๐Ÿ” Data Flow

Incoming Message Format (via pub/sub)

{
  "type": "key",
  "updated": "2023-10-01T12:00:00Z",
  "valid": "2023-10-01T12:05:32Z",
  "values": {
    "field1": "value1",
    "field2": "value2"
  }
}

Stored Format (Redis KV)

key = {
  "updated": "2023-10-01T12:00:00Z",
  "valid": "2023-10-01T12:05:32Z",
  "values": {
    "field1": "value1",
    "field2": "value2"
  }
}

๐Ÿš€ Features

โš™๏ธ Configuration

Configuration is loaded from a config.py file. Example:

config = {
    "redis_url": "redis://redis.redis:6379/0",
    "channel": "update",
    "validate": True
}

๐Ÿงช Usage

  1. Install dependencies
pip install redis
  1. Run the service
python kv_updater.py

Make sure your config.py is present in the same directory or adjust the import path accordingly.

๐Ÿ› ๏ธ Class Overview

KVUpdater

Method Description
init Initializes Redis client and sets channel and validation flag
persist_data Parses incoming message and stores it in Redis KV store
run Subscribes to Redis pub/sub and listens for messages indefinitely

๐Ÿ““ Logging

๐Ÿงฉ Integration Notes

This service is intended to be used as part of a Redis-first microservice chain. It assumes that upstream services publish structured messages to the configured Redis channel.

๐Ÿ“š License

MIT License โ€” feel free to use, modify, and contribute.