Skip to content

Commit fde8176

Browse files
authored
Merge pull request #60 from monkey92t/new_cmd
feat: add LMPop,BLMPop command
2 parents e2deefa + e3d7310 commit fde8176

File tree

6 files changed

+88
-11
lines changed

6 files changed

+88
-11
lines changed

commands_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,14 @@ var _ = Describe("Commands", func() {
943943
})
944944
})
945945

946+
It("BLMPop", func() {
947+
operationKeyValuesCmd(clientMock, func() *ExpectedKeyValues {
948+
return clientMock.ExpectBLMPop(1*time.Second, "left", 3, "key1", "key2")
949+
}, func() *redis.KeyValuesCmd {
950+
return client.BLMPop(ctx, 1*time.Second, "left", 3, "key1", "key2")
951+
})
952+
})
953+
946954
It("BRPop", func() {
947955
operationStringSliceCmd(clientMock, func() *ExpectedStringSlice {
948956
return clientMock.ExpectBRPop(1*time.Second, "key1", "key2")
@@ -1015,6 +1023,14 @@ var _ = Describe("Commands", func() {
10151023
})
10161024
})
10171025

1026+
It("LMPop", func() {
1027+
operationKeyValuesCmd(clientMock, func() *ExpectedKeyValues {
1028+
return clientMock.ExpectLMPop("left", 3, "key1", "key2")
1029+
}, func() *redis.KeyValuesCmd {
1030+
return client.LMPop(ctx, "left", 3, "key1", "key2")
1031+
})
1032+
})
1033+
10181034
It("LPos", func() {
10191035
operationIntCmd(clientMock, func() *ExpectedInt {
10201036
return clientMock.ExpectLPos("list", "b", redis.LPosArgs{Rank: 2})

expect.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ type baseMock interface {
123123
ExpectHRandFieldWithValues(key string, count int) *ExpectedKeyValueSlice
124124

125125
ExpectBLPop(timeout time.Duration, keys ...string) *ExpectedStringSlice
126+
ExpectBLMPop(timeout time.Duration, direction string, count int64, keys ...string) *ExpectedKeyValues
126127
ExpectBRPop(timeout time.Duration, keys ...string) *ExpectedStringSlice
127128
ExpectBRPopLPush(source, destination string, timeout time.Duration) *ExpectedString
128129
ExpectLIndex(key string, index int64) *ExpectedString
@@ -132,6 +133,7 @@ type baseMock interface {
132133
ExpectLLen(key string) *ExpectedInt
133134
ExpectLPop(key string) *ExpectedString
134135
ExpectLPopCount(key string, count int) *ExpectedStringSlice
136+
ExpectLMPop(direction string, count int64, keys ...string) *ExpectedKeyValues
135137
ExpectLPos(key string, value string, args redis.LPosArgs) *ExpectedInt
136138
ExpectLPosCount(key string, value string, count int64, args redis.LPosArgs) *ExpectedIntSlice
137139
ExpectLPush(key string, values ...interface{}) *ExpectedInt
@@ -1109,6 +1111,27 @@ func (cmd *ExpectedGeoSearchLocation) inflow(c redis.Cmder) {
11091111

11101112
// ------------------------------------------------------------
11111113

1114+
type ExpectedKeyValues struct {
1115+
expectedBase
1116+
1117+
key string
1118+
val []string
1119+
}
1120+
1121+
func (cmd *ExpectedKeyValues) SetVal(key string, val []string) {
1122+
cmd.setVal = true
1123+
cmd.key = key
1124+
cmd.val = make([]string, len(val))
1125+
copy(cmd.val, val)
1126+
}
1127+
1128+
func (cmd *ExpectedKeyValues) inflow(c redis.Cmder) {
1129+
inflow(c, "key", cmd.key)
1130+
inflow(c, "val", cmd.val)
1131+
}
1132+
1133+
// ------------------------------------------------------------
1134+
11121135
type ExpectedSlowLog struct {
11131136
expectedBase
11141137

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.18
55
require (
66
github.com/onsi/ginkgo v1.16.5
77
github.com/onsi/gomega v1.25.0
8-
github.com/redis/go-redis/v9 v9.0.3-0.20230207104127-9d5e48507ef3
8+
github.com/redis/go-redis/v9 v9.0.3-0.20230217130544-3b5361dc1067
99
)
1010

1111
require (

go.sum

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
github.com/bsm/ginkgo/v2 v2.7.0 h1:ItPMPH90RbmZJt5GtkcNvIRuGEdwlBItdNVoyzaNQao=
2+
github.com/bsm/gomega v1.26.0 h1:LhQm+AFcgV2M0WyKroMASzAzCAJVpAxQXv4SaI9a69Y=
13
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
24
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
35
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -38,16 +40,8 @@ github.com/onsi/gomega v1.25.0 h1:Vw7br2PCDYijJHSfBOWhov+8cAnUf8MfMaIOV323l6Y=
3840
github.com/onsi/gomega v1.25.0/go.mod h1:r+zV744Re+DiYCIPRlYOTxn0YkOLcAnW8k1xXdMPGhM=
3941
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
4042
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
41-
github.com/redis/go-redis/v9 v9.0.0-rc.4 h1:JUhsiZMTZknz3vn50zSVlkwcSeTGPd51lMO3IKUrWpY=
42-
github.com/redis/go-redis/v9 v9.0.0-rc.4/go.mod h1:Vo3EsyWnicKnSKCA7HhgnvnyA74wOA69Cd2Meli5mmA=
43-
github.com/redis/go-redis/v9 v9.0.0 h1:r2ctp2J2+TcXTVIyPU6++FniED/Nyo4SDMKvLtpszx0=
44-
github.com/redis/go-redis/v9 v9.0.0/go.mod h1:/xDTe9EF1LM61hek62Poq2nzQSGj0xSrEtEHbBQevps=
45-
github.com/redis/go-redis/v9 v9.0.1 h1:L1B0L2Y7dQMnKxwfzSwemceGlQwVUsqJ1kjkdaoNhts=
46-
github.com/redis/go-redis/v9 v9.0.1/go.mod h1:/xDTe9EF1LM61hek62Poq2nzQSGj0xSrEtEHbBQevps=
47-
github.com/redis/go-redis/v9 v9.0.2 h1:BA426Zqe/7r56kCcvxYLWe1mkaz71LKF77GwgFzSxfE=
48-
github.com/redis/go-redis/v9 v9.0.2/go.mod h1:/xDTe9EF1LM61hek62Poq2nzQSGj0xSrEtEHbBQevps=
49-
github.com/redis/go-redis/v9 v9.0.3-0.20230207104127-9d5e48507ef3 h1:kyVjUJXiL4ucwG4wEw/JcvSUOeG4foJO1c1J0GecWo0=
50-
github.com/redis/go-redis/v9 v9.0.3-0.20230207104127-9d5e48507ef3/go.mod h1:/xDTe9EF1LM61hek62Poq2nzQSGj0xSrEtEHbBQevps=
43+
github.com/redis/go-redis/v9 v9.0.3-0.20230217130544-3b5361dc1067 h1:e+fsCwY18jOIumrC71yG6ZcLUB7AwyS/GX+bspxzaOs=
44+
github.com/redis/go-redis/v9 v9.0.3-0.20230217130544-3b5361dc1067/go.mod h1:6kjiKPy72LcR7xJX4bMLuf+2Rd/tpBFk4YKJTZ1jTNA=
5145
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
5246
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
5347
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=

mock.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,13 @@ func (m *mock) ExpectBLPop(timeout time.Duration, keys ...string) *ExpectedStrin
10891089
return e
10901090
}
10911091

1092+
func (m *mock) ExpectBLMPop(timeout time.Duration, direction string, count int64, keys ...string) *ExpectedKeyValues {
1093+
e := &ExpectedKeyValues{}
1094+
e.cmd = m.factory.BLMPop(m.ctx, timeout, direction, count, keys...)
1095+
m.pushExpect(e)
1096+
return e
1097+
}
1098+
10921099
func (m *mock) ExpectBRPop(timeout time.Duration, keys ...string) *ExpectedStringSlice {
10931100
e := &ExpectedStringSlice{}
10941101
e.cmd = m.factory.BRPop(m.ctx, timeout, keys...)
@@ -1152,6 +1159,13 @@ func (m *mock) ExpectLPopCount(key string, count int) *ExpectedStringSlice {
11521159
return e
11531160
}
11541161

1162+
func (m *mock) ExpectLMPop(direction string, count int64, keys ...string) *ExpectedKeyValues {
1163+
e := &ExpectedKeyValues{}
1164+
e.cmd = m.factory.LMPop(m.ctx, direction, count, keys...)
1165+
m.pushExpect(e)
1166+
return e
1167+
}
1168+
11551169
func (m *mock) ExpectLPos(key string, value string, args redis.LPosArgs) *ExpectedInt {
11561170
e := &ExpectedInt{}
11571171
e.cmd = m.factory.LPos(m.ctx, key, value, args)

mock_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,3 +1336,33 @@ func operationSlowLogCmd(base baseMock, expected func() *ExpectedSlowLog, actual
13361336
},
13371337
}))
13381338
}
1339+
1340+
func operationKeyValuesCmd(base baseMock, expected func() *ExpectedKeyValues, actual func() *redis.KeyValuesCmd) {
1341+
var (
1342+
setErr = errors.New("key values cmd error")
1343+
key string
1344+
val []string
1345+
err error
1346+
)
1347+
1348+
base.ClearExpect()
1349+
expected().SetErr(setErr)
1350+
key, val, err = actual().Result()
1351+
Expect(err).To(Equal(setErr))
1352+
Expect(key).To(Equal(""))
1353+
Expect(val).To(Equal([]string(nil)))
1354+
1355+
base.ClearExpect()
1356+
expected()
1357+
key, val, err = actual().Result()
1358+
Expect(err).To(HaveOccurred())
1359+
Expect(key).To(Equal(""))
1360+
Expect(val).To(Equal([]string(nil)))
1361+
1362+
base.ClearExpect()
1363+
expected().SetVal("key1", []string{"v1", "v2"})
1364+
key, val, err = actual().Result()
1365+
Expect(err).NotTo(HaveOccurred())
1366+
Expect(key).To(Equal("key1"))
1367+
Expect(val).To(Equal([]string{"v1", "v2"}))
1368+
}

0 commit comments

Comments
 (0)