Skip to content

Commit 09ec5f0

Browse files
committed
Merge pull request redis#304 from go-redis/fix/rename-zrangebyscore
Rename ZRangeByScore to ZRange since it is used in ZRangeByLex.
2 parents 96650c0 + 51349cd commit 09ec5f0

File tree

2 files changed

+31
-32
lines changed

2 files changed

+31
-32
lines changed

commands.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,13 +1169,12 @@ func (c *commandable) ZRangeWithScores(key string, start, stop int64) *ZSliceCmd
11691169
return cmd
11701170
}
11711171

1172-
// TODO: Rename to something more generic in v4
1173-
type ZRangeByScore struct {
1172+
type ZRangeBy struct {
11741173
Min, Max string
11751174
Offset, Count int64
11761175
}
11771176

1178-
func (c *commandable) zRangeBy(zcmd, key string, opt ZRangeByScore, withScores bool) *StringSliceCmd {
1177+
func (c *commandable) zRangeBy(zcmd, key string, opt ZRangeBy, withScores bool) *StringSliceCmd {
11791178
args := []interface{}{zcmd, key, opt.Min, opt.Max}
11801179
if withScores {
11811180
args = append(args, "WITHSCORES")
@@ -1193,15 +1192,15 @@ func (c *commandable) zRangeBy(zcmd, key string, opt ZRangeByScore, withScores b
11931192
return cmd
11941193
}
11951194

1196-
func (c *commandable) ZRangeByScore(key string, opt ZRangeByScore) *StringSliceCmd {
1195+
func (c *commandable) ZRangeByScore(key string, opt ZRangeBy) *StringSliceCmd {
11971196
return c.zRangeBy("ZRANGEBYSCORE", key, opt, false)
11981197
}
11991198

1200-
func (c *commandable) ZRangeByLex(key string, opt ZRangeByScore) *StringSliceCmd {
1199+
func (c *commandable) ZRangeByLex(key string, opt ZRangeBy) *StringSliceCmd {
12011200
return c.zRangeBy("ZRANGEBYLEX", key, opt, false)
12021201
}
12031202

1204-
func (c *commandable) ZRangeByScoreWithScores(key string, opt ZRangeByScore) *ZSliceCmd {
1203+
func (c *commandable) ZRangeByScoreWithScores(key string, opt ZRangeBy) *ZSliceCmd {
12051204
args := []interface{}{"ZRANGEBYSCORE", key, opt.Min, opt.Max, "WITHSCORES"}
12061205
if opt.Offset != 0 || opt.Count != 0 {
12071206
args = append(
@@ -1263,7 +1262,7 @@ func (c *commandable) ZRevRangeWithScores(key string, start, stop int64) *ZSlice
12631262
return cmd
12641263
}
12651264

1266-
func (c *commandable) zRevRangeBy(zcmd, key string, opt ZRangeByScore) *StringSliceCmd {
1265+
func (c *commandable) zRevRangeBy(zcmd, key string, opt ZRangeBy) *StringSliceCmd {
12671266
args := []interface{}{zcmd, key, opt.Max, opt.Min}
12681267
if opt.Offset != 0 || opt.Count != 0 {
12691268
args = append(
@@ -1278,15 +1277,15 @@ func (c *commandable) zRevRangeBy(zcmd, key string, opt ZRangeByScore) *StringSl
12781277
return cmd
12791278
}
12801279

1281-
func (c *commandable) ZRevRangeByScore(key string, opt ZRangeByScore) *StringSliceCmd {
1280+
func (c *commandable) ZRevRangeByScore(key string, opt ZRangeBy) *StringSliceCmd {
12821281
return c.zRevRangeBy("ZREVRANGEBYSCORE", key, opt)
12831282
}
12841283

1285-
func (c *commandable) ZRevRangeByLex(key string, opt ZRangeByScore) *StringSliceCmd {
1284+
func (c *commandable) ZRevRangeByLex(key string, opt ZRangeBy) *StringSliceCmd {
12861285
return c.zRevRangeBy("ZREVRANGEBYLEX", key, opt)
12871286
}
12881287

1289-
func (c *commandable) ZRevRangeByScoreWithScores(key string, opt ZRangeByScore) *ZSliceCmd {
1288+
func (c *commandable) ZRevRangeByScoreWithScores(key string, opt ZRangeBy) *ZSliceCmd {
12901289
args := []interface{}{"ZREVRANGEBYSCORE", key, opt.Max, opt.Min, "WITHSCORES"}
12911290
if opt.Offset != 0 || opt.Count != 0 {
12921291
args = append(

commands_test.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2199,28 +2199,28 @@ var _ = Describe("Commands", func() {
21992199
zAdd = client.ZAdd("zset", redis.Z{3, "three"})
22002200
Expect(zAdd.Err()).NotTo(HaveOccurred())
22012201

2202-
zRangeByScore := client.ZRangeByScore("zset", redis.ZRangeByScore{
2202+
zRangeByScore := client.ZRangeByScore("zset", redis.ZRangeBy{
22032203
Min: "-inf",
22042204
Max: "+inf",
22052205
})
22062206
Expect(zRangeByScore.Err()).NotTo(HaveOccurred())
22072207
Expect(zRangeByScore.Val()).To(Equal([]string{"one", "two", "three"}))
22082208

2209-
zRangeByScore = client.ZRangeByScore("zset", redis.ZRangeByScore{
2209+
zRangeByScore = client.ZRangeByScore("zset", redis.ZRangeBy{
22102210
Min: "1",
22112211
Max: "2",
22122212
})
22132213
Expect(zRangeByScore.Err()).NotTo(HaveOccurred())
22142214
Expect(zRangeByScore.Val()).To(Equal([]string{"one", "two"}))
22152215

2216-
zRangeByScore = client.ZRangeByScore("zset", redis.ZRangeByScore{
2216+
zRangeByScore = client.ZRangeByScore("zset", redis.ZRangeBy{
22172217
Min: "(1",
22182218
Max: "2",
22192219
})
22202220
Expect(zRangeByScore.Err()).NotTo(HaveOccurred())
22212221
Expect(zRangeByScore.Val()).To(Equal([]string{"two"}))
22222222

2223-
zRangeByScore = client.ZRangeByScore("zset", redis.ZRangeByScore{
2223+
zRangeByScore = client.ZRangeByScore("zset", redis.ZRangeBy{
22242224
Min: "(1",
22252225
Max: "(2",
22262226
})
@@ -2235,28 +2235,28 @@ var _ = Describe("Commands", func() {
22352235
Expect(zAdd.Err()).NotTo(HaveOccurred())
22362236
zAdd = client.ZAdd("zset", redis.Z{0, "c"})
22372237

2238-
zRangeByLex := client.ZRangeByLex("zset", redis.ZRangeByScore{
2238+
zRangeByLex := client.ZRangeByLex("zset", redis.ZRangeBy{
22392239
Min: "-",
22402240
Max: "+",
22412241
})
22422242
Expect(zRangeByLex.Err()).NotTo(HaveOccurred())
22432243
Expect(zRangeByLex.Val()).To(Equal([]string{"a", "b", "c"}))
22442244

2245-
zRangeByLex = client.ZRangeByLex("zset", redis.ZRangeByScore{
2245+
zRangeByLex = client.ZRangeByLex("zset", redis.ZRangeBy{
22462246
Min: "[a",
22472247
Max: "[b",
22482248
})
22492249
Expect(zRangeByLex.Err()).NotTo(HaveOccurred())
22502250
Expect(zRangeByLex.Val()).To(Equal([]string{"a", "b"}))
22512251

2252-
zRangeByLex = client.ZRangeByLex("zset", redis.ZRangeByScore{
2252+
zRangeByLex = client.ZRangeByLex("zset", redis.ZRangeBy{
22532253
Min: "(a",
22542254
Max: "[b",
22552255
})
22562256
Expect(zRangeByLex.Err()).NotTo(HaveOccurred())
22572257
Expect(zRangeByLex.Val()).To(Equal([]string{"b"}))
22582258

2259-
zRangeByLex = client.ZRangeByLex("zset", redis.ZRangeByScore{
2259+
zRangeByLex = client.ZRangeByLex("zset", redis.ZRangeBy{
22602260
Min: "(a",
22612261
Max: "(b",
22622262
})
@@ -2272,28 +2272,28 @@ var _ = Describe("Commands", func() {
22722272
zAdd = client.ZAdd("zset", redis.Z{3, "three"})
22732273
Expect(zAdd.Err()).NotTo(HaveOccurred())
22742274

2275-
val, err := client.ZRangeByScoreWithScores("zset", redis.ZRangeByScore{
2275+
val, err := client.ZRangeByScoreWithScores("zset", redis.ZRangeBy{
22762276
Min: "-inf",
22772277
Max: "+inf",
22782278
}).Result()
22792279
Expect(err).NotTo(HaveOccurred())
22802280
Expect(val).To(Equal([]redis.Z{{1, "one"}, {2, "two"}, {3, "three"}}))
22812281

2282-
val, err = client.ZRangeByScoreWithScores("zset", redis.ZRangeByScore{
2282+
val, err = client.ZRangeByScoreWithScores("zset", redis.ZRangeBy{
22832283
Min: "1",
22842284
Max: "2",
22852285
}).Result()
22862286
Expect(err).NotTo(HaveOccurred())
22872287
Expect(val).To(Equal([]redis.Z{{1, "one"}, {2, "two"}}))
22882288

2289-
val, err = client.ZRangeByScoreWithScores("zset", redis.ZRangeByScore{
2289+
val, err = client.ZRangeByScoreWithScores("zset", redis.ZRangeBy{
22902290
Min: "(1",
22912291
Max: "2",
22922292
}).Result()
22932293
Expect(err).NotTo(HaveOccurred())
22942294
Expect(val).To(Equal([]redis.Z{{2, "two"}}))
22952295

2296-
val, err = client.ZRangeByScoreWithScores("zset", redis.ZRangeByScore{
2296+
val, err = client.ZRangeByScoreWithScores("zset", redis.ZRangeBy{
22972297
Min: "(1",
22982298
Max: "(2",
22992299
}).Result()
@@ -2420,17 +2420,17 @@ var _ = Describe("Commands", func() {
24202420
Expect(zadd.Err()).NotTo(HaveOccurred())
24212421

24222422
vals, err := client.ZRevRangeByScore(
2423-
"zset", redis.ZRangeByScore{Max: "+inf", Min: "-inf"}).Result()
2423+
"zset", redis.ZRangeBy{Max: "+inf", Min: "-inf"}).Result()
24242424
Expect(err).NotTo(HaveOccurred())
24252425
Expect(vals).To(Equal([]string{"three", "two", "one"}))
24262426

24272427
vals, err = client.ZRevRangeByScore(
2428-
"zset", redis.ZRangeByScore{Max: "2", Min: "(1"}).Result()
2428+
"zset", redis.ZRangeBy{Max: "2", Min: "(1"}).Result()
24292429
Expect(err).NotTo(HaveOccurred())
24302430
Expect(vals).To(Equal([]string{"two"}))
24312431

24322432
vals, err = client.ZRevRangeByScore(
2433-
"zset", redis.ZRangeByScore{Max: "(2", Min: "(1"}).Result()
2433+
"zset", redis.ZRangeBy{Max: "(2", Min: "(1"}).Result()
24342434
Expect(err).NotTo(HaveOccurred())
24352435
Expect(vals).To(Equal([]string{}))
24362436
})
@@ -2444,17 +2444,17 @@ var _ = Describe("Commands", func() {
24442444
Expect(zadd.Err()).NotTo(HaveOccurred())
24452445

24462446
vals, err := client.ZRevRangeByLex(
2447-
"zset", redis.ZRangeByScore{Max: "+", Min: "-"}).Result()
2447+
"zset", redis.ZRangeBy{Max: "+", Min: "-"}).Result()
24482448
Expect(err).NotTo(HaveOccurred())
24492449
Expect(vals).To(Equal([]string{"c", "b", "a"}))
24502450

24512451
vals, err = client.ZRevRangeByLex(
2452-
"zset", redis.ZRangeByScore{Max: "[b", Min: "(a"}).Result()
2452+
"zset", redis.ZRangeBy{Max: "[b", Min: "(a"}).Result()
24532453
Expect(err).NotTo(HaveOccurred())
24542454
Expect(vals).To(Equal([]string{"b"}))
24552455

24562456
vals, err = client.ZRevRangeByLex(
2457-
"zset", redis.ZRangeByScore{Max: "(b", Min: "(a"}).Result()
2457+
"zset", redis.ZRangeBy{Max: "(b", Min: "(a"}).Result()
24582458
Expect(err).NotTo(HaveOccurred())
24592459
Expect(vals).To(Equal([]string{}))
24602460
})
@@ -2468,7 +2468,7 @@ var _ = Describe("Commands", func() {
24682468
Expect(zadd.Err()).NotTo(HaveOccurred())
24692469

24702470
vals, err := client.ZRevRangeByScoreWithScores(
2471-
"zset", redis.ZRangeByScore{Max: "+inf", Min: "-inf"}).Result()
2471+
"zset", redis.ZRangeBy{Max: "+inf", Min: "-inf"}).Result()
24722472
Expect(err).NotTo(HaveOccurred())
24732473
Expect(vals).To(Equal([]redis.Z{{3, "three"}, {2, "two"}, {1, "one"}}))
24742474
})
@@ -2482,17 +2482,17 @@ var _ = Describe("Commands", func() {
24822482
Expect(zAdd.Err()).NotTo(HaveOccurred())
24832483

24842484
val, err := client.ZRevRangeByScoreWithScores(
2485-
"zset", redis.ZRangeByScore{Max: "+inf", Min: "-inf"}).Result()
2485+
"zset", redis.ZRangeBy{Max: "+inf", Min: "-inf"}).Result()
24862486
Expect(err).NotTo(HaveOccurred())
24872487
Expect(val).To(Equal([]redis.Z{{3, "three"}, {2, "two"}, {1, "one"}}))
24882488

24892489
val, err = client.ZRevRangeByScoreWithScores(
2490-
"zset", redis.ZRangeByScore{Max: "2", Min: "(1"}).Result()
2490+
"zset", redis.ZRangeBy{Max: "2", Min: "(1"}).Result()
24912491
Expect(err).NotTo(HaveOccurred())
24922492
Expect(val).To(Equal([]redis.Z{{2, "two"}}))
24932493

24942494
val, err = client.ZRevRangeByScoreWithScores(
2495-
"zset", redis.ZRangeByScore{Max: "(2", Min: "(1"}).Result()
2495+
"zset", redis.ZRangeBy{Max: "(2", Min: "(1"}).Result()
24962496
Expect(err).NotTo(HaveOccurred())
24972497
Expect(val).To(Equal([]redis.Z{}))
24982498
})

0 commit comments

Comments
 (0)