Skip to content

Commit ab02d5d

Browse files
Updated Redis module for subscribe and hast get all
1 parent 5e1c5eb commit ab02d5d

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

internal/redis/redis.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ type RedisClient interface {
1616
HSet(ctx context.Context, key string, values ...interface{}) *redis.IntCmd
1717
RPush(ctx context.Context, key string, value interface{}) *redis.IntCmd
1818
LRange(ctx context.Context, key string, start, stop int64) *redis.StringSliceCmd
19+
PSubscribe(ctx context.Context, patterns ...string) (*redis.PubSub, error)
20+
HGetAll(ctx context.Context, key string) *redis.MapStringStringCmd
1921
FlushAll(ctx context.Context) error
2022
}
2123

@@ -72,6 +74,21 @@ func (r *redisClient) HSet(ctx context.Context, key string, values ...interface{
7274
return r.client.HSet(ctx, key, values...)
7375
}
7476

77+
/* subscribe to redis keyspace notifications */
78+
func (r *redisClient) PSubscribe(ctx context.Context, patterns ...string) (*redis.PubSub, error) {
79+
pubsub := r.client.PSubscribe(ctx, patterns...)
80+
_, err := pubsub.Receive(ctx)
81+
if err != nil {
82+
return nil, fmt.Errorf("failed to subscribe to patterns: %w", err)
83+
}
84+
return pubsub, nil
85+
}
86+
87+
/* hash get all the data associated with the key */
88+
func (r *redisClient) HGetAll(ctx context.Context, key string) *redis.MapStringStringCmd {
89+
return r.client.HGetAll(ctx, key)
90+
}
91+
7592
/* flush all data from Redis */
7693
func (r *redisClient) FlushAll(ctx context.Context) error {
7794
return r.client.FlushAll(ctx).Err()

0 commit comments

Comments
 (0)