Skip to content

Commit 6dd52de

Browse files
authored
Merge pull request #93 from rueian/multiplex-single-client
feat: multiplex single/sentinel client with default 4 connections to improve latencies
2 parents 2c16111 + 5ecbd52 commit 6dd52de

File tree

9 files changed

+1611
-446
lines changed

9 files changed

+1611
-446
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func main() {
5353

5454
## Auto Pipeline
5555

56-
All non-blocking commands sending to a single redis node are automatically pipelined through one tcp connection,
56+
All non-blocking commands sending to a single redis node are automatically pipelined through connections,
5757
which reduces the overall round trips and system calls, and gets higher throughput.
5858

5959
### Benchmark comparison with go-redis v8.11.4

hack/cmds/gen.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,12 @@ func printBuilder(w io.Writer, parent, next goStruct) {
628628

629629
if len(next.BuildDef.Parameters) == 1 && next.Variadic {
630630
if next.BuildDef.Parameters[0].Type == "key" {
631-
fmt.Fprintf(w, "\tif c.ks != NoSlot {\n")
631+
fmt.Fprintf(w, "\tif c.ks&NoSlot == NoSlot {\n")
632+
fmt.Fprintf(w, "\t\tfor _, k := range %s {\n", toGoName(next.BuildDef.Parameters[0].Name))
633+
fmt.Fprintf(w, "\t\t\tc.ks = NoSlot | slot(k)\n")
634+
fmt.Fprintf(w, "\t\t\tbreak\n")
635+
fmt.Fprintf(w, "\t\t}\n")
636+
fmt.Fprintf(w, "\t} else {\n")
632637
fmt.Fprintf(w, "\t\tfor _, k := range %s {\n", toGoName(next.BuildDef.Parameters[0].Name))
633638
fmt.Fprintf(w, "\t\t\tc.ks = check(c.ks, slot(k))\n")
634639
fmt.Fprintf(w, "\t\t}\n")
@@ -640,7 +645,9 @@ func printBuilder(w io.Writer, parent, next goStruct) {
640645
} else {
641646
for _, arg := range next.BuildDef.Parameters {
642647
if arg.Type == "key" {
643-
fmt.Fprintf(w, "\tif c.ks != NoSlot {\n")
648+
fmt.Fprintf(w, "\tif c.ks&NoSlot == NoSlot {\n")
649+
fmt.Fprintf(w, "\t\tc.ks = NoSlot | slot(%s)\n", toGoName(arg.Name))
650+
fmt.Fprintf(w, "\t} else {\n")
644651
fmt.Fprintf(w, "\t\tc.ks = check(c.ks, slot(%s))\n", toGoName(arg.Name))
645652
fmt.Fprintf(w, "\t}\n")
646653
}

internal/cmds/builder.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,12 @@ func (b Builder) Arbitrary(token ...string) (c Arbitrary) {
5050
// Users must use Keys to construct the key part of the command, otherwise
5151
// the command will not be sent to correct redis node.
5252
func (c Arbitrary) Keys(keys ...string) Arbitrary {
53-
if c.ks != NoSlot {
53+
if c.ks&NoSlot == NoSlot {
54+
for _, k := range keys {
55+
c.ks = NoSlot | slot(k)
56+
break
57+
}
58+
} else {
5459
for _, k := range keys {
5560
c.ks = check(c.ks, slot(k))
5661
}

internal/cmds/cmds.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ const (
99
noRetTag = uint16(1<<12) | readonly // make noRetTag can also be retried
1010
mtGetTag = uint16(1<<11) | readonly // make mtGetTag can also be retried
1111
// InitSlot indicates that the command be sent to any redis node in cluster
12-
InitSlot = uint16(1 << 15)
12+
InitSlot = uint16(1 << 14)
1313
// NoSlot indicates that the command has no key slot specified
14-
NoSlot = InitSlot + 1
14+
NoSlot = uint16(1 << 15)
1515
)
1616

1717
var (

0 commit comments

Comments
 (0)