Skip to content

Commit 244a3e2

Browse files
ofekshenawachayim
andauthored
RediSearch Support (redis#2801)
* Add RediSearch Support * searach * Add RediSearch commands and tests * Adding more tests and fixing commands * Remove unnecessary additions * fixing tests * fixing tests * fixing tests * fixing FTConfig dialect test * fix commects * make enum for field types * Support resp 2 * fix golang ci * fix ftinfo --------- Co-authored-by: Chayim <[email protected]>
1 parent 2d7382e commit 244a3e2

File tree

6 files changed

+3435
-1
lines changed

6 files changed

+3435
-1
lines changed

.github/wordlist.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,5 @@ url
5757
variadic
5858
RedisStack
5959
RedisGears
60-
RedisTimeseries
60+
RedisTimeseries
61+
RediSearch

command.go

+59
Original file line numberDiff line numberDiff line change
@@ -3787,6 +3787,65 @@ func (cmd *MapStringStringSliceCmd) readReply(rd *proto.Reader) error {
37873787
return nil
37883788
}
37893789

3790+
// -----------------------------------------------------------------------
3791+
// MapStringInterfaceCmd represents a command that returns a map of strings to interface{}.
3792+
type MapMapStringInterfaceCmd struct {
3793+
baseCmd
3794+
val map[string]interface{}
3795+
}
3796+
3797+
func NewMapMapStringInterfaceCmd(ctx context.Context, args ...interface{}) *MapMapStringInterfaceCmd {
3798+
return &MapMapStringInterfaceCmd{
3799+
baseCmd: baseCmd{
3800+
ctx: ctx,
3801+
args: args,
3802+
},
3803+
}
3804+
}
3805+
3806+
func (cmd *MapMapStringInterfaceCmd) String() string {
3807+
return cmdString(cmd, cmd.val)
3808+
}
3809+
3810+
func (cmd *MapMapStringInterfaceCmd) SetVal(val map[string]interface{}) {
3811+
cmd.val = val
3812+
}
3813+
3814+
func (cmd *MapMapStringInterfaceCmd) Result() (map[string]interface{}, error) {
3815+
return cmd.val, cmd.err
3816+
}
3817+
3818+
func (cmd *MapMapStringInterfaceCmd) Val() map[string]interface{} {
3819+
return cmd.val
3820+
}
3821+
3822+
func (cmd *MapMapStringInterfaceCmd) readReply(rd *proto.Reader) (err error) {
3823+
n, err := rd.ReadArrayLen()
3824+
if err != nil {
3825+
return err
3826+
}
3827+
3828+
data := make(map[string]interface{}, n/2)
3829+
for i := 0; i < n; i += 2 {
3830+
_, err := rd.ReadArrayLen()
3831+
if err != nil {
3832+
cmd.err = err
3833+
}
3834+
key, err := rd.ReadString()
3835+
if err != nil {
3836+
cmd.err = err
3837+
}
3838+
value, err := rd.ReadString()
3839+
if err != nil {
3840+
cmd.err = err
3841+
}
3842+
data[key] = value
3843+
}
3844+
3845+
cmd.val = data
3846+
return nil
3847+
}
3848+
37903849
//-----------------------------------------------------------------------
37913850

37923851
type MapStringInterfaceSliceCmd struct {

commands.go

+1
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ type Cmdable interface {
220220
ProbabilisticCmdable
221221
PubSubCmdable
222222
ScriptingFunctionsCmdable
223+
SearchCmdable
223224
SetCmdable
224225
SortedSetCmdable
225226
StringCmdable

internal/util.go

+45
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package internal
33
import (
44
"context"
55
"net"
6+
"strconv"
67
"strings"
78
"time"
89

@@ -81,3 +82,47 @@ func GetAddr(addr string) string {
8182
}
8283
return net.JoinHostPort(addr[:ind], addr[ind+1:])
8384
}
85+
86+
func ToInteger(val interface{}) int {
87+
switch v := val.(type) {
88+
case int:
89+
return v
90+
case int64:
91+
return int(v)
92+
case string:
93+
i, _ := strconv.Atoi(v)
94+
return i
95+
default:
96+
return 0
97+
}
98+
}
99+
100+
func ToFloat(val interface{}) float64 {
101+
switch v := val.(type) {
102+
case float64:
103+
return v
104+
case string:
105+
f, _ := strconv.ParseFloat(v, 64)
106+
return f
107+
default:
108+
return 0.0
109+
}
110+
}
111+
112+
func ToString(val interface{}) string {
113+
if str, ok := val.(string); ok {
114+
return str
115+
}
116+
return ""
117+
}
118+
119+
func ToStringSlice(val interface{}) []string {
120+
if arr, ok := val.([]interface{}); ok {
121+
result := make([]string, len(arr))
122+
for i, v := range arr {
123+
result[i] = ToString(v)
124+
}
125+
return result
126+
}
127+
return nil
128+
}

0 commit comments

Comments
 (0)