Skip to content

Commit 38d1749

Browse files
authored
adjust the code (#1842)
* Upgrade redis-server version (#1833) * Upgrade redis-server version Signed-off-by: monkey <golang@88.com> * XAutoClaim changed the return value Signed-off-by: monkey <golang@88.com> * add cmd: geosearch, geosearchstore (#1836) * add cmd: geosearch, geosearchstore Signed-off-by: monkey92t <golang@88.com> * GeoSearchQuery and GeoSearchLocationQuery changed to pointer passing Signed-off-by: monkey92t <golang@88.com> * adjust the code, and fix #1553, #1676 Signed-off-by: monkey92t <golang@88.com>
1 parent b8245b5 commit 38d1749

15 files changed

+439
-77
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ bench: testdeps
1414

1515
testdata/redis:
1616
mkdir -p $@
17-
wget -qO- https://download.redis.io/releases/redis-6.2.1.tar.gz | tar xvz --strip-components=1 -C $@
17+
wget -qO- https://download.redis.io/releases/redis-6.2.5.tar.gz | tar xvz --strip-components=1 -C $@
1818

1919
testdata/redis/src/redis-server: testdata/redis
2020
cd $< && make all

cluster.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,6 @@ func (c *ClusterClient) process(ctx context.Context, cmd Cmder) error {
795795
_ = pipe.Process(ctx, NewCmd(ctx, "asking"))
796796
_ = pipe.Process(ctx, cmd)
797797
_, lastErr = pipe.Exec(ctx)
798-
_ = pipe.Close()
799798
ask = false
800799
} else {
801800
lastErr = node.Client.Process(ctx, cmd)

cluster_test.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -515,9 +515,7 @@ var _ = Describe("ClusterClient", func() {
515515
pipe = client.Pipeline().(*redis.Pipeline)
516516
})
517517

518-
AfterEach(func() {
519-
Expect(pipe.Close()).NotTo(HaveOccurred())
520-
})
518+
AfterEach(func() {})
521519

522520
assertPipeline()
523521
})
@@ -527,9 +525,7 @@ var _ = Describe("ClusterClient", func() {
527525
pipe = client.TxPipeline().(*redis.Pipeline)
528526
})
529527

530-
AfterEach(func() {
531-
Expect(pipe.Close()).NotTo(HaveOccurred())
532-
})
528+
AfterEach(func() {})
533529

534530
assertPipeline()
535531
})

command.go

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2564,6 +2564,183 @@ func (cmd *GeoLocationCmd) readReply(rd *proto.Reader) error {
25642564

25652565
//------------------------------------------------------------------------------
25662566

2567+
// GeoSearchQuery is used for GEOSearch/GEOSearchStore command query.
2568+
type GeoSearchQuery struct {
2569+
Member string
2570+
2571+
// Latitude and Longitude when using FromLonLat option.
2572+
Longitude float64
2573+
Latitude float64
2574+
2575+
// Distance and unit when using ByRadius option.
2576+
// Can use m, km, ft, or mi. Default is km.
2577+
Radius float64
2578+
RadiusUnit string
2579+
2580+
// Height, width and unit when using ByBox option.
2581+
// Can be m, km, ft, or mi. Default is km.
2582+
BoxWidth float64
2583+
BoxHeight float64
2584+
BoxUnit string
2585+
2586+
// Can be ASC or DESC. Default is no sort order.
2587+
Sort string
2588+
Count int
2589+
CountAny bool
2590+
}
2591+
2592+
type GeoSearchLocationQuery struct {
2593+
GeoSearchQuery
2594+
2595+
WithCoord bool
2596+
WithDist bool
2597+
WithHash bool
2598+
}
2599+
2600+
type GeoSearchStoreQuery struct {
2601+
GeoSearchQuery
2602+
2603+
// When using the StoreDist option, the command stores the items in a
2604+
// sorted set populated with their distance from the center of the circle or box,
2605+
// as a floating-point number, in the same unit specified for that shape.
2606+
StoreDist bool
2607+
}
2608+
2609+
func geoSearchLocationArgs(q *GeoSearchLocationQuery, args []interface{}) []interface{} {
2610+
args = geoSearchArgs(&q.GeoSearchQuery, args)
2611+
2612+
if q.WithCoord {
2613+
args = append(args, "withcoord")
2614+
}
2615+
if q.WithDist {
2616+
args = append(args, "withdist")
2617+
}
2618+
if q.WithHash {
2619+
args = append(args, "withhash")
2620+
}
2621+
2622+
return args
2623+
}
2624+
2625+
func geoSearchArgs(q *GeoSearchQuery, args []interface{}) []interface{} {
2626+
if q.Member != "" {
2627+
args = append(args, "frommember", q.Member)
2628+
} else {
2629+
args = append(args, "fromlonlat", q.Longitude, q.Latitude)
2630+
}
2631+
2632+
if q.Radius > 0 {
2633+
if q.RadiusUnit == "" {
2634+
q.RadiusUnit = "km"
2635+
}
2636+
args = append(args, "byradius", q.Radius, q.RadiusUnit)
2637+
} else {
2638+
if q.BoxUnit == "" {
2639+
q.BoxUnit = "km"
2640+
}
2641+
args = append(args, "bybox", q.BoxWidth, q.BoxHeight, q.BoxUnit)
2642+
}
2643+
2644+
if q.Sort != "" {
2645+
args = append(args, q.Sort)
2646+
}
2647+
2648+
if q.Count > 0 {
2649+
args = append(args, "count", q.Count)
2650+
if q.CountAny {
2651+
args = append(args, "any")
2652+
}
2653+
}
2654+
2655+
return args
2656+
}
2657+
2658+
type GeoSearchLocationCmd struct {
2659+
baseCmd
2660+
2661+
opt *GeoSearchLocationQuery
2662+
val []GeoLocation
2663+
}
2664+
2665+
var _ Cmder = (*GeoSearchLocationCmd)(nil)
2666+
2667+
func NewGeoSearchLocationCmd(
2668+
ctx context.Context, opt *GeoSearchLocationQuery, args ...interface{},
2669+
) *GeoSearchLocationCmd {
2670+
return &GeoSearchLocationCmd{
2671+
baseCmd: baseCmd{
2672+
ctx: ctx,
2673+
args: args,
2674+
},
2675+
opt: opt,
2676+
}
2677+
}
2678+
2679+
func (cmd *GeoSearchLocationCmd) Val() []GeoLocation {
2680+
return cmd.val
2681+
}
2682+
2683+
func (cmd *GeoSearchLocationCmd) Result() ([]GeoLocation, error) {
2684+
return cmd.val, cmd.err
2685+
}
2686+
2687+
func (cmd *GeoSearchLocationCmd) String() string {
2688+
return cmdString(cmd, cmd.val)
2689+
}
2690+
2691+
func (cmd *GeoSearchLocationCmd) readReply(rd *proto.Reader) error {
2692+
n, err := rd.ReadArrayLen()
2693+
if err != nil {
2694+
return err
2695+
}
2696+
2697+
cmd.val = make([]GeoLocation, n)
2698+
for i := 0; i < n; i++ {
2699+
_, err = rd.ReadArrayLen()
2700+
if err != nil {
2701+
return err
2702+
}
2703+
2704+
var loc GeoLocation
2705+
2706+
loc.Name, err = rd.ReadString()
2707+
if err != nil {
2708+
return err
2709+
}
2710+
if cmd.opt.WithDist {
2711+
loc.Dist, err = rd.ReadFloat()
2712+
if err != nil {
2713+
return err
2714+
}
2715+
}
2716+
if cmd.opt.WithHash {
2717+
loc.GeoHash, err = rd.ReadInt()
2718+
if err != nil {
2719+
return err
2720+
}
2721+
}
2722+
if cmd.opt.WithCoord {
2723+
if err = rd.ReadFixedArrayLen(2); err != nil {
2724+
return err
2725+
}
2726+
loc.Longitude, err = rd.ReadFloat()
2727+
if err != nil {
2728+
return err
2729+
}
2730+
loc.Latitude, err = rd.ReadFloat()
2731+
if err != nil {
2732+
return err
2733+
}
2734+
}
2735+
2736+
cmd.val[i] = loc
2737+
}
2738+
2739+
return nil
2740+
}
2741+
2742+
//------------------------------------------------------------------------------
2743+
25672744
type GeoPos struct {
25682745
Longitude, Latitude float64
25692746
}

command_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"errors"
55
"time"
66

7-
redis "github.com/go-redis/redis/v8"
7+
"github.com/go-redis/redis/v8"
88

99
. "github.com/onsi/ginkgo"
1010
. "github.com/onsi/gomega"

commands.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ type Cmdable interface {
244244
XTrimMinIDApprox(ctx context.Context, key string, minID string, limit int64) *IntCmd
245245
XInfoGroups(ctx context.Context, key string) *XInfoGroupsCmd
246246
XInfoStream(ctx context.Context, key string) *XInfoStreamCmd
247+
XInfoStreamFull(ctx context.Context, key string, count int) *XInfoStreamFullCmd
247248
XInfoConsumers(ctx context.Context, key string, group string) *XInfoConsumersCmd
248249

249250
BZPopMax(ctx context.Context, timeout time.Duration, keys ...string) *ZWithKeyCmd
@@ -304,6 +305,8 @@ type Cmdable interface {
304305
ClientList(ctx context.Context) *StringCmd
305306
ClientPause(ctx context.Context, dur time.Duration) *BoolCmd
306307
ClientID(ctx context.Context) *IntCmd
308+
ClientUnblock(ctx context.Context, id int64) *IntCmd
309+
ClientUnblockWithError(ctx context.Context, id int64) *IntCmd
307310
ConfigGet(ctx context.Context, parameter string) *MapStringStringCmd
308311
ConfigResetStat(ctx context.Context) *StatusCmd
309312
ConfigSet(ctx context.Context, parameter, value string) *StatusCmd
@@ -320,6 +323,7 @@ type Cmdable interface {
320323
ShutdownSave(ctx context.Context) *StatusCmd
321324
ShutdownNoSave(ctx context.Context) *StatusCmd
322325
SlaveOf(ctx context.Context, host, port string) *StatusCmd
326+
SlowLogGet(ctx context.Context, num int64) *SlowLogCmd
323327
Time(ctx context.Context) *TimeCmd
324328
DebugObject(ctx context.Context, key string) *StringCmd
325329
ReadOnly(ctx context.Context) *StatusCmd
@@ -364,6 +368,9 @@ type Cmdable interface {
364368
GeoRadiusStore(ctx context.Context, key string, longitude, latitude float64, query *GeoRadiusQuery) *IntCmd
365369
GeoRadiusByMember(ctx context.Context, key, member string, query *GeoRadiusQuery) *GeoLocationCmd
366370
GeoRadiusByMemberStore(ctx context.Context, key, member string, query *GeoRadiusQuery) *IntCmd
371+
GeoSearch(ctx context.Context, key string, q *GeoSearchQuery) *StringSliceCmd
372+
GeoSearchLocation(ctx context.Context, key string, q *GeoSearchLocationQuery) *GeoSearchLocationCmd
373+
GeoSearchStore(ctx context.Context, key, store string, q *GeoSearchStoreQuery) *IntCmd
367374
GeoDist(ctx context.Context, key string, member1, member2, unit string) *FloatCmd
368375
GeoHash(ctx context.Context, key string, members ...string) *StringSliceCmd
369376
}
@@ -3240,6 +3247,38 @@ func (c cmdable) GeoRadiusByMemberStore(
32403247
return cmd
32413248
}
32423249

3250+
func (c cmdable) GeoSearch(ctx context.Context, key string, q *GeoSearchQuery) *StringSliceCmd {
3251+
args := make([]interface{}, 0, 13)
3252+
args = append(args, "geosearch", key)
3253+
args = geoSearchArgs(q, args)
3254+
cmd := NewStringSliceCmd(ctx, args...)
3255+
_ = c(ctx, cmd)
3256+
return cmd
3257+
}
3258+
3259+
func (c cmdable) GeoSearchLocation(
3260+
ctx context.Context, key string, q *GeoSearchLocationQuery,
3261+
) *GeoSearchLocationCmd {
3262+
args := make([]interface{}, 0, 16)
3263+
args = append(args, "geosearch", key)
3264+
args = geoSearchLocationArgs(q, args)
3265+
cmd := NewGeoSearchLocationCmd(ctx, q, args...)
3266+
_ = c(ctx, cmd)
3267+
return cmd
3268+
}
3269+
3270+
func (c cmdable) GeoSearchStore(ctx context.Context, key, store string, q *GeoSearchStoreQuery) *IntCmd {
3271+
args := make([]interface{}, 0, 15)
3272+
args = append(args, "geosearchstore", store, key)
3273+
args = geoSearchArgs(&q.GeoSearchQuery, args)
3274+
if q.StoreDist {
3275+
args = append(args, "storedist")
3276+
}
3277+
cmd := NewIntCmd(ctx, args...)
3278+
_ = c(ctx, cmd)
3279+
return cmd
3280+
}
3281+
32433282
func (c cmdable) GeoDist(
32443283
ctx context.Context, key string, member1, member2, unit string,
32453284
) *FloatCmd {

0 commit comments

Comments
 (0)