From 1bc138bd349e19c3459c46bdad63247b3a9dc058 Mon Sep 17 00:00:00 2001 From: Kevin Wan Date: Sat, 1 Oct 2022 21:45:53 +0800 Subject: [PATCH] chore: refactor to reduce duplicated code (#2477) --- core/stores/redis/redis.go | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/core/stores/redis/redis.go b/core/stores/redis/redis.go index 535f523a..9cd47d2e 100644 --- a/core/stores/redis/redis.go +++ b/core/stores/redis/redis.go @@ -226,20 +226,7 @@ func (s *Redis) Blpop(node RedisNode, key string) (string, error) { // BlpopCtx uses passed in redis connection to execute blocking queries. // Doesn't benefit from pooling redis connections of blocking queries func (s *Redis) BlpopCtx(ctx context.Context, node RedisNode, key string) (string, error) { - if node == nil { - return "", ErrNilNode - } - - vals, err := node.BLPop(ctx, blockingQueryTimeout, key).Result() - if err != nil { - return "", err - } - - if len(vals) < 2 { - return "", fmt.Errorf("no value on key: %s", key) - } - - return vals[1], nil + return s.BlpopWithTimeoutCtx(ctx, node, blockingQueryTimeout, key) } // BlpopEx uses passed in redis connection to execute blpop command. @@ -275,7 +262,8 @@ func (s *Redis) BlpopWithTimeout(node RedisNode, timeout time.Duration, key stri // BlpopWithTimeoutCtx uses passed in redis connection to execute blpop command. // Control blocking query timeout -func (s *Redis) BlpopWithTimeoutCtx(ctx context.Context, node RedisNode, timeout time.Duration, key string) (string, error) { +func (s *Redis) BlpopWithTimeoutCtx(ctx context.Context, node RedisNode, timeout time.Duration, + key string) (string, error) { if node == nil { return "", ErrNilNode }