浏览代码

chore: refactor to reduce duplicated code (#2477)

Kevin Wan 2 年之前
父节点
当前提交
1bc138bd34
共有 1 个文件被更改,包括 3 次插入15 次删除
  1. 3 15
      core/stores/redis/redis.go

+ 3 - 15
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
 	}