Skip to content

Commit

Permalink
refactor: 整理代码
Browse files Browse the repository at this point in the history
  • Loading branch information
huangqing.zhu committed Jul 25, 2024
1 parent f474eab commit 23d6609
Show file tree
Hide file tree
Showing 5 changed files with 192 additions and 190 deletions.
44 changes: 31 additions & 13 deletions cmd_args.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,25 @@ import (
"time"
)

const KeepTTL = rueidiscompat.KeepTTL
const (
OK = "OK"
EMPTY = ""
BYTE = "BYTE"
BIT = "BIT"
M = "M"
KM = "KM"
FT = "FT"
MI = "MI"
XX = "XX"
NX = "NX"
BEFORE = "BEFORE"
AFTER = "AFTER"
RIGHT = "RIGHT"
LEFT = "LEFT"
LADDR = "LADDR"
TYPE = "TYPE"
KeepTTL = rueidiscompat.KeepTTL
)

type (
KeyValue = rueidiscompat.KeyValue
Expand Down Expand Up @@ -772,26 +790,26 @@ func geoRadiusQueryArgs(q GeoRadiusQuery) []string {
args = append(args, KM)
}
if q.WithCoord {
args = append(args, WITHCOORD)
args = append(args, XXX_WITHCOORD)
}
if q.WithDist {
args = append(args, WITHDIST)
args = append(args, XXX_WITHDIST)
}
if q.WithGeoHash {
args = append(args, WITHHASH)
args = append(args, XXX_WITHHASH)
}
if q.Count > 0 {
args = append(args, COUNT, strconv.FormatInt(q.Count, 10))
args = append(args, XXX_COUNT, strconv.FormatInt(q.Count, 10))
}
if q.Sort != "" {
args = append(args, q.Sort)
}
if q.Store != "" {
args = append(args, STORE)
args = append(args, XXX_STORE)
args = append(args, q.Store)
}
if q.StoreDist != "" {
args = append(args, STOREDIST)
args = append(args, XXX_STOREDIST)
args = append(args, q.StoreDist)
}
return args
Expand All @@ -800,28 +818,28 @@ func geoRadiusQueryArgs(q GeoRadiusQuery) []string {
func geoSearchQueryArgs(q GeoSearchQuery) []string {
args := make([]string, 0, 2)
if q.Member != "" {
args = append(args, FROMMEMBER, q.Member)
args = append(args, XXX_FROMMEMBER, q.Member)
} else {
args = append(args, FROMLONLAT, strconv.FormatFloat(q.Longitude, 'f', -1, 64), strconv.FormatFloat(q.Latitude, 'f', -1, 64))
args = append(args, XXX_FROMLONLAT, strconv.FormatFloat(q.Longitude, 'f', -1, 64), strconv.FormatFloat(q.Latitude, 'f', -1, 64))
}
if q.Radius > 0 {
if q.RadiusUnit == "" {
q.RadiusUnit = KM
}
args = append(args, BYRADIUS, strconv.FormatFloat(q.Radius, 'f', -1, 64), q.RadiusUnit)
args = append(args, XXX_BYRADIUS, strconv.FormatFloat(q.Radius, 'f', -1, 64), q.RadiusUnit)
} else {
if q.BoxUnit == "" {
q.BoxUnit = KM
}
args = append(args, BYBOX, strconv.FormatFloat(q.BoxWidth, 'f', -1, 64), strconv.FormatFloat(q.BoxHeight, 'f', -1, 64), q.BoxUnit)
args = append(args, XXX_BYBOX, strconv.FormatFloat(q.BoxWidth, 'f', -1, 64), strconv.FormatFloat(q.BoxHeight, 'f', -1, 64), q.BoxUnit)
}
if q.Sort != "" {
args = append(args, q.Sort)
}
if q.Count > 0 {
args = append(args, COUNT, strconv.FormatInt(q.Count, 10))
args = append(args, XXX_COUNT, strconv.FormatInt(q.Count, 10))
if q.CountAny {
args = append(args, ANY)
args = append(args, XXX_ANY)
}
}
return args
Expand Down
4 changes: 2 additions & 2 deletions cmd_bitmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ func (c *client) BitCount(ctx context.Context, key string, bc *BitCount) IntCmd
ctx = c.handler.before(ctx, CommandBitCount)
} else {
switch strings.ToUpper(bc.Unit) {
case BitCountIndexByte:
case BYTE:
ctx = c.handler.before(ctx, CommandBitCountByte)
case BitCountIndexBit:
case BIT:
ctx = c.handler.before(ctx, CommandBitCountBit)
default:
ctx = c.handler.before(ctx, CommandBitCount)
Expand Down
6 changes: 3 additions & 3 deletions connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var (

func (c *client) reviseCluster(ctx context.Context, info string) (err error) {
if len(info) == 0 {
info, err = c.Info(ctx, CLUSTER).Result()
info, err = c.Info(ctx, XXX_CLUSTER).Result()
if err != nil {
return
}
Expand All @@ -35,7 +35,7 @@ func (c *client) reviseCluster(ctx context.Context, info string) (err error) {

func (c *client) reviseVersion(ctx context.Context, info string) (err error) {
if len(info) == 0 {
info, err = c.Info(ctx, SERVER).Result()
info, err = c.Info(ctx, XXX_SERVER).Result()
if err != nil {
return err
}
Expand All @@ -54,7 +54,7 @@ func (c *client) reviseVersion(ctx context.Context, info string) (err error) {
}

func (c *client) revise(ctx context.Context) error {
info, err := c.Info(ctx, CLUSTER, SERVER).Result()
info, err := c.Info(ctx, XXX_CLUSTER, XXX_SERVER).Result()
if err != nil {
info = ""
}
Expand Down
Loading

0 comments on commit 23d6609

Please sign in to comment.