mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-08-15 03:13:38 +00:00
add context to keyvaluemodule get/set
This commit is contained in:
@@ -17,8 +17,8 @@ type OutputModule interface {
|
||||
}
|
||||
|
||||
type KeyValueModule interface {
|
||||
Get(key string) (any, error)
|
||||
Set(key string, value any) error
|
||||
Get(ctx context.Context, key string) (any, error)
|
||||
Set(ctx context.Context, key string, value any) error
|
||||
}
|
||||
|
||||
type DatabaseModule interface {
|
||||
|
||||
@@ -110,9 +110,9 @@ func (rc *RedisClient) Stop() {
|
||||
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 {
|
||||
val, err := rc.client.Get(rc.ctx, key).Result()
|
||||
val, err := rc.client.Get(ctx, key).Result()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -121,9 +121,9 @@ func (rc *RedisClient) Get(key string) (any, error) {
|
||||
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 {
|
||||
status := rc.client.Set(rc.ctx, key, value, 0)
|
||||
status := rc.client.Set(ctx, key, value, 0)
|
||||
return status.Err()
|
||||
}
|
||||
return errors.New("redis.client not setup")
|
||||
|
||||
@@ -77,7 +77,7 @@ func (kvg *KVGet) Process(ctx context.Context, wrappedPayload common.WrappedPayl
|
||||
kvg.module = kvModule
|
||||
}
|
||||
|
||||
value, err := kvg.module.Get(kvg.Key)
|
||||
value, err := kvg.module.Get(ctx, kvg.Key)
|
||||
if err != nil {
|
||||
wrappedPayload.End = true
|
||||
return wrappedPayload, fmt.Errorf("kv.get error getting key: %w", err)
|
||||
|
||||
@@ -78,7 +78,7 @@ func (kvs *KVSet) Process(ctx context.Context, wrappedPayload common.WrappedPayl
|
||||
kvs.module = kvModule
|
||||
}
|
||||
|
||||
err := kvs.module.Set(kvs.Key, wrappedPayload.Payload)
|
||||
err := kvs.module.Set(ctx, kvs.Key, wrappedPayload.Payload)
|
||||
if err != nil {
|
||||
wrappedPayload.End = true
|
||||
return wrappedPayload, fmt.Errorf("kv.set error setting key: %w", err)
|
||||
|
||||
@@ -89,7 +89,7 @@ func (m *TestKVModule) Id() string {
|
||||
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 {
|
||||
return nil, nil
|
||||
}
|
||||
@@ -100,7 +100,7 @@ func (m *TestKVModule) Get(key string) (any, error) {
|
||||
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 {
|
||||
m.kvData = make(map[string]any)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user