add context to keyvaluemodule get/set

This commit is contained in:
Joel Wetzell
2026-05-27 18:30:23 -05:00
parent 3adbae8068
commit 52ca801fbd
5 changed files with 10 additions and 10 deletions
+2 -2
View File
@@ -17,8 +17,8 @@ type OutputModule interface {
} }
type KeyValueModule interface { type KeyValueModule interface {
Get(key string) (any, error) Get(ctx context.Context, key string) (any, error)
Set(key string, value any) error Set(ctx context.Context, key string, value any) error
} }
type DatabaseModule interface { type DatabaseModule interface {
+4 -4
View File
@@ -110,9 +110,9 @@ func (rc *RedisClient) Stop() {
rc.logger.Debug("done") rc.logger.Debug("done")
} }
func (rc *RedisClient) Get(key string) (any, error) { func (rc *RedisClient) Get(ctx context.Context, key string) (any, error) {
if rc.client != nil { if rc.client != nil {
val, err := rc.client.Get(rc.ctx, key).Result() val, err := rc.client.Get(ctx, key).Result()
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -121,9 +121,9 @@ func (rc *RedisClient) Get(key string) (any, error) {
return nil, errors.New("redis.client not setup") return nil, errors.New("redis.client not setup")
} }
func (rc *RedisClient) Set(key string, value any) error { func (rc *RedisClient) Set(ctx context.Context, key string, value any) error {
if rc.client != nil { if rc.client != nil {
status := rc.client.Set(rc.ctx, key, value, 0) status := rc.client.Set(ctx, key, value, 0)
return status.Err() return status.Err()
} }
return errors.New("redis.client not setup") return errors.New("redis.client not setup")
+1 -1
View File
@@ -77,7 +77,7 @@ func (kvg *KVGet) Process(ctx context.Context, wrappedPayload common.WrappedPayl
kvg.module = kvModule kvg.module = kvModule
} }
value, err := kvg.module.Get(kvg.Key) value, err := kvg.module.Get(ctx, kvg.Key)
if err != nil { if err != nil {
wrappedPayload.End = true wrappedPayload.End = true
return wrappedPayload, fmt.Errorf("kv.get error getting key: %w", err) return wrappedPayload, fmt.Errorf("kv.get error getting key: %w", err)
+1 -1
View File
@@ -78,7 +78,7 @@ func (kvs *KVSet) Process(ctx context.Context, wrappedPayload common.WrappedPayl
kvs.module = kvModule kvs.module = kvModule
} }
err := kvs.module.Set(kvs.Key, wrappedPayload.Payload) err := kvs.module.Set(ctx, kvs.Key, wrappedPayload.Payload)
if err != nil { if err != nil {
wrappedPayload.End = true wrappedPayload.End = true
return wrappedPayload, fmt.Errorf("kv.set error setting key: %w", err) return wrappedPayload, fmt.Errorf("kv.set error setting key: %w", err)
+2 -2
View File
@@ -89,7 +89,7 @@ func (m *TestKVModule) Id() string {
return m.id return m.id
} }
func (m *TestKVModule) Get(key string) (any, error) { func (m *TestKVModule) Get(ctx context.Context, key string) (any, error) {
if m.kvData == nil { if m.kvData == nil {
return nil, nil return nil, nil
} }
@@ -100,7 +100,7 @@ func (m *TestKVModule) Get(key string) (any, error) {
return value, nil return value, nil
} }
func (m *TestKVModule) Set(key string, value any) error { func (m *TestKVModule) Set(ctx context.Context, key string, value any) error {
if m.kvData == nil { if m.kvData == nil {
m.kvData = make(map[string]any) m.kvData = make(map[string]any)
} }