Skip to content

Commit

Permalink
test patch cluster support for scan operation
Browse files Browse the repository at this point in the history
  • Loading branch information
ns-ofang committed Oct 29, 2024
1 parent 1ed936e commit 51db7cb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions generic_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package redis
import (
"context"
"time"

"github.com/redis/go-redis/v9/internal/hashtag"
)

type GenericCmdable interface {
Expand Down Expand Up @@ -363,6 +365,9 @@ func (c cmdable) Scan(ctx context.Context, cursor uint64, match string, count in
args = append(args, "count", count)
}
cmd := NewScanCmd(ctx, c, args...)
if hashtag.Present(match) {
cmd.SetFirstKeyPos(3)
}
_ = c(ctx, cmd)
return cmd
}
Expand Down
12 changes: 12 additions & 0 deletions internal/hashtag/hashtag.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ func Key(key string) string {
return key
}

func Present(key string) bool {
if key == "" {
return false
}
if s := strings.IndexByte(key, '{'); s > -1 {
if e := strings.IndexByte(key[s+1:], '}'); e > 0 {
return true
}
}
return false
}

func RandomSlot() int {
return rand.Intn(slotNumber)
}
Expand Down

0 comments on commit 51db7cb

Please sign in to comment.