Skip to content

Commit 308c585

Browse files
authored
Merge pull request #169 from alicebob/int
more RESP3 preparations
2 parents eb01461 + 49b9ebf commit 308c585

33 files changed

+4222
-4267
lines changed

cmd_cluster.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,26 @@ func commandsCluster(m *Miniredis) {
1414
}
1515

1616
func (m *Miniredis) cmdCluster(c *server.Peer, cmd string, args []string) {
17-
if len(args) == 1 && strings.ToUpper(args[0]) == "SLOTS" {
17+
if !m.handleAuth(c) {
18+
return
19+
}
20+
21+
if len(args) < 1 {
22+
setDirty(c)
23+
c.WriteError(errWrongNumber(cmd))
24+
return
25+
}
26+
switch strings.ToUpper(args[0]) {
27+
case "SLOTS":
1828
m.cmdClusterSlots(c, cmd, args)
19-
} else if len(args) == 2 && strings.ToUpper(args[0]) == "KEYSLOT" {
29+
case "KEYSLOT":
2030
m.cmdClusterKeySlot(c, cmd, args)
21-
} else if len(args) == 1 && strings.ToUpper(args[0]) == "NODES" {
31+
case "NODES":
2232
m.cmdClusterNodes(c, cmd, args)
23-
} else {
24-
j := strings.Join(args, " ")
25-
err := fmt.Sprintf("ERR 'CLUSTER %s' not supported", j)
33+
default:
2634
setDirty(c)
27-
c.WriteError(err)
35+
c.WriteError(fmt.Sprintf("ERR 'CLUSTER %s' not supported", strings.Join(args, " ")))
36+
return
2837
}
2938
}
3039

@@ -55,4 +64,3 @@ func (m *Miniredis) cmdClusterNodes(c *server.Peer, cmd string, args []string) {
5564
c.WriteBulk("e7d1eecce10fd6bb5eb35b9f99a514335d9ba9ca 127.0.0.1:7000@7000 myself,master - 0 0 1 connected 0-16383")
5665
})
5766
}
58-

cmd_geo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ func (m *Miniredis) cmdGeopos(c *server.Peer, cmd string, args []string) {
165165
c.WriteLen(len(args))
166166
for _, l := range args {
167167
if !db.ssetExists(key, l) {
168-
c.WriteNull()
168+
c.WriteLen(-1)
169169
continue
170170
}
171171
score := db.ssetScore(key, l)

cmd_geo_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func TestGeopos(t *testing.T) {
7070
t.Run("no location", func(t *testing.T) {
7171
mustDo(t, c,
7272
"GEOPOS", "Sicily", "Corleone",
73-
proto.Array(proto.Nil),
73+
proto.Array(proto.NilList),
7474
)
7575
})
7676

cmd_list.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func (m *Miniredis) cmdBXpop(c *server.Peer, cmd string, args []string, lr leftr
110110
},
111111
func(c *server.Peer) {
112112
// timeout
113-
c.WriteNull()
113+
c.WriteLen(-1)
114114
},
115115
)
116116
}
@@ -132,7 +132,7 @@ func (m *Miniredis) cmdLindex(c *server.Peer, cmd string, args []string) {
132132
key, offsets := args[0], args[1]
133133

134134
offset, err := strconv.Atoi(offsets)
135-
if err != nil {
135+
if err != nil || offsets == "-0" {
136136
setDirty(c)
137137
c.WriteError(msgInvalidInt)
138138
return
@@ -721,7 +721,7 @@ func (m *Miniredis) cmdBrpoplpush(c *server.Peer, cmd string, args []string) {
721721
},
722722
func(c *server.Peer) {
723723
// timeout
724-
c.WriteNull()
724+
c.WriteLen(-1)
725725
},
726726
)
727727
}

cmd_list_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,7 +1018,7 @@ func TestBrpopTimeout(t *testing.T) {
10181018
got := goStrings(t, s, "BRPOP", "l1", "1")
10191019
select {
10201020
case have := <-got:
1021-
equals(t, proto.Nil, have)
1021+
equals(t, proto.NilList, have)
10221022
case <-time.After(1500 * time.Millisecond):
10231023
t.Error("BRPOP took too long")
10241024
}
@@ -1049,7 +1049,7 @@ func TestBrpopTx(t *testing.T) {
10491049
mustDo(t, c,
10501050
"EXEC",
10511051
proto.Array(
1052-
proto.Nil,
1052+
proto.NilList,
10531053
proto.Inline("OK"),
10541054
),
10551055
)
@@ -1222,7 +1222,7 @@ func TestBrpoplpushTimeout(t *testing.T) {
12221222
got := goStrings(t, s, "BRPOPLPUSH", "l1", "l2", "1")
12231223
select {
12241224
case have := <-got:
1225-
equals(t, proto.Nil, have)
1225+
equals(t, proto.NilList, have)
12261226
case <-time.After(1500 * time.Millisecond):
12271227
t.Error("BRPOPLPUSH took too long")
12281228
}

cmd_stream.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,9 +421,8 @@ parsing:
421421
res[stream] = entries
422422
}
423423

424-
// Real Redis returns Nil
425424
if len(res) == 0 {
426-
c.WriteNull()
425+
c.WriteLen(-1)
427426
return
428427
}
429428

cmd_stream_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ func TestStreamReadGroup(t *testing.T) {
385385
"XGROUP", "CREATE", "planets", "processing", "$", "MKSTREAM",
386386
)
387387

388-
mustNil(t, c,
388+
mustNilList(t, c,
389389
"XREADGROUP", "GROUP", "processing", "alice", "STREAMS", "planets", ">",
390390
)
391391

@@ -405,7 +405,7 @@ func TestStreamReadGroup(t *testing.T) {
405405
),
406406
)
407407

408-
mustNil(t, c,
408+
mustNilList(t, c,
409409
"XREADGROUP", "GROUP", "processing", "alice", "STREAMS", "planets", ">",
410410
)
411411

@@ -447,7 +447,7 @@ func TestStreamDelete(t *testing.T) {
447447
"XDEL", "planets", "0-1",
448448
)
449449

450-
mustNil(t, c,
450+
mustNilList(t, c,
451451
"XREADGROUP", "GROUP", "processing", "alice", "STREAMS", "planets", "0-0",
452452
)
453453
}
@@ -481,7 +481,7 @@ func TestStreamAck(t *testing.T) {
481481
"XACK", "planets", "processing", "0-1",
482482
)
483483

484-
mustNil(t, c,
484+
mustNilList(t, c,
485485
"XREADGROUP", "GROUP", "processing", "alice", "STREAMS", "planets", "0-0",
486486
)
487487
}

example_test.go

Lines changed: 0 additions & 54 deletions
This file was deleted.

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ module github.com/alicebob/miniredis/v2
22

33
require (
44
github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a
5-
github.com/gomodule/redigo v1.8.1
65
github.com/yuin/gopher-lua v0.0.0-20191220021717-ab39c6098bdb
76
)
87

go.sum

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,7 @@ github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a/go.mod h1:SGn
33
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
44
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
55
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
6-
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
7-
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
8-
github.com/gomodule/redigo v1.8.1 h1:Abmo0bI7Xf0IhdIPc7HZQzZcShdnmxeoVuDDtIQp8N8=
9-
github.com/gomodule/redigo v1.8.1/go.mod h1:P9dn9mFrCBvWhGE1wpxx6fgq7BAeLBk+UUUzlpkBYO0=
10-
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
11-
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
12-
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
13-
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
14-
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
156
github.com/yuin/gopher-lua v0.0.0-20191220021717-ab39c6098bdb h1:ZkM6LRnq40pR1Ox0hTHlnpkcOTuFIDQpZ1IN8rKKhX0=
167
github.com/yuin/gopher-lua v0.0.0-20191220021717-ab39c6098bdb/go.mod h1:gqRgreBUhTSL0GeU64rtZ3Uq3wtjOa/TB2YfrtkCbVQ=
178
golang.org/x/sys v0.0.0-20190204203706-41f3e6584952 h1:FDfvYgoVsA7TTZSbgiqjAbfPbK47CNHdWl3h/PJtii0=
189
golang.org/x/sys v0.0.0-20190204203706-41f3e6584952/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
19-
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
20-
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
21-
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
22-
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

0 commit comments

Comments
 (0)