Class: PatientHttp::PayloadStore::RedisStore
- Defined in:
- lib/patient_http/payload_store/redis_store.rb
Overview
Redis-based payload store for production deployments.
Stores payloads as JSON strings in Redis. This store is recommended for production environments where multiple processes need to share payload data.
Thread-safe: Redis clients handle their own thread safety.
Instance Attribute Summary collapse
-
#key_prefix ⇒ String
readonly
The key prefix used for all stored payloads.
-
#ttl ⇒ Float?
readonly
TTL in seconds for stored payloads.
Instance Method Summary collapse
-
#delete(key) ⇒ Boolean
Delete a payload from Redis.
-
#exists?(key) ⇒ Boolean
Check if a payload exists.
-
#fetch(key) ⇒ Hash?
Fetch data from Redis.
-
#initialize(redis:, ttl: nil, key_prefix: nil) ⇒ RedisStore
constructor
Initialize a new Redis store.
-
#store_json(key, json) ⇒ String
Store pre-serialized JSON string directly in Redis.
Methods inherited from Base
create, #generate_key, lookup, register, registered_adapters, #store
Constructor Details
#initialize(redis:, ttl: nil, key_prefix: nil) ⇒ RedisStore
Initialize a new Redis store.
33 34 35 36 37 38 39 |
# File 'lib/patient_http/payload_store/redis_store.rb', line 33 def initialize(redis:, ttl: nil, key_prefix: nil) raise ArgumentError, "redis client is required" unless redis @redis = redis @ttl = ttl @key_prefix = key_prefix || "patient_http:payloads:" end |
Instance Attribute Details
#key_prefix ⇒ String (readonly)
Returns The key prefix used for all stored payloads.
20 21 22 |
# File 'lib/patient_http/payload_store/redis_store.rb', line 20 def key_prefix @key_prefix end |
#ttl ⇒ Float? (readonly)
Returns TTL in seconds for stored payloads.
23 24 25 |
# File 'lib/patient_http/payload_store/redis_store.rb', line 23 def ttl @ttl end |
Instance Method Details
#delete(key) ⇒ Boolean
Delete a payload from Redis.
Idempotent - does not raise if key doesn’t exist.
76 77 78 79 80 |
# File 'lib/patient_http/payload_store/redis_store.rb', line 76 def delete(key) full_key = key_with_prefix(key) @redis.del(full_key) true end |
#exists?(key) ⇒ Boolean
Check if a payload exists.
86 87 88 89 |
# File 'lib/patient_http/payload_store/redis_store.rb', line 86 def exists?(key) full_key = key_with_prefix(key) @redis.exists(full_key) > 0 end |
#fetch(key) ⇒ Hash?
Fetch data from Redis.
62 63 64 65 66 67 68 |
# File 'lib/patient_http/payload_store/redis_store.rb', line 62 def fetch(key) full_key = key_with_prefix(key) json = @redis.get(full_key) return nil if json.nil? JSON.parse(json) end |
#store_json(key, json) ⇒ String
Store pre-serialized JSON string directly in Redis.
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/patient_http/payload_store/redis_store.rb', line 46 def store_json(key, json) full_key = key_with_prefix(key) if @ttl ttl_ms = (@ttl * 1000).round @redis.set(full_key, json, px: ttl_ms) else @redis.set(full_key, json) end key end |