mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-09-08 22:58:59 +00:00
add context to keyvaluemodule get/set
This commit is contained in:
@@ -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 {
|
||||||
|
|||||||
@@ -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")
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -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)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user