mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-02-03 00:38:40 +08:00
chore: refactor to reduce duplicated code (#2477)
This commit is contained in:
parent
4b9066eda6
commit
1bc138bd34
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user