mirror of https://github.com/go-redis/redis.git
RediSearch Support (#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 <chayim@users.noreply.github.com>
This commit is contained in:
parent
2d7382e8cc
commit
244a3e22da
|
@ -58,3 +58,4 @@ variadic
|
||||||
RedisStack
|
RedisStack
|
||||||
RedisGears
|
RedisGears
|
||||||
RedisTimeseries
|
RedisTimeseries
|
||||||
|
RediSearch
|
||||||
|
|
59
command.go
59
command.go
|
@ -3787,6 +3787,65 @@ func (cmd *MapStringStringSliceCmd) readReply(rd *proto.Reader) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------
|
||||||
|
// MapStringInterfaceCmd represents a command that returns a map of strings to interface{}.
|
||||||
|
type MapMapStringInterfaceCmd struct {
|
||||||
|
baseCmd
|
||||||
|
val map[string]interface{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewMapMapStringInterfaceCmd(ctx context.Context, args ...interface{}) *MapMapStringInterfaceCmd {
|
||||||
|
return &MapMapStringInterfaceCmd{
|
||||||
|
baseCmd: baseCmd{
|
||||||
|
ctx: ctx,
|
||||||
|
args: args,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cmd *MapMapStringInterfaceCmd) String() string {
|
||||||
|
return cmdString(cmd, cmd.val)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cmd *MapMapStringInterfaceCmd) SetVal(val map[string]interface{}) {
|
||||||
|
cmd.val = val
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cmd *MapMapStringInterfaceCmd) Result() (map[string]interface{}, error) {
|
||||||
|
return cmd.val, cmd.err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cmd *MapMapStringInterfaceCmd) Val() map[string]interface{} {
|
||||||
|
return cmd.val
|
||||||
|
}
|
||||||
|
|
||||||
|
func (cmd *MapMapStringInterfaceCmd) readReply(rd *proto.Reader) (err error) {
|
||||||
|
n, err := rd.ReadArrayLen()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
data := make(map[string]interface{}, n/2)
|
||||||
|
for i := 0; i < n; i += 2 {
|
||||||
|
_, err := rd.ReadArrayLen()
|
||||||
|
if err != nil {
|
||||||
|
cmd.err = err
|
||||||
|
}
|
||||||
|
key, err := rd.ReadString()
|
||||||
|
if err != nil {
|
||||||
|
cmd.err = err
|
||||||
|
}
|
||||||
|
value, err := rd.ReadString()
|
||||||
|
if err != nil {
|
||||||
|
cmd.err = err
|
||||||
|
}
|
||||||
|
data[key] = value
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.val = data
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
|
|
||||||
type MapStringInterfaceSliceCmd struct {
|
type MapStringInterfaceSliceCmd struct {
|
||||||
|
|
|
@ -220,6 +220,7 @@ type Cmdable interface {
|
||||||
ProbabilisticCmdable
|
ProbabilisticCmdable
|
||||||
PubSubCmdable
|
PubSubCmdable
|
||||||
ScriptingFunctionsCmdable
|
ScriptingFunctionsCmdable
|
||||||
|
SearchCmdable
|
||||||
SetCmdable
|
SetCmdable
|
||||||
SortedSetCmdable
|
SortedSetCmdable
|
||||||
StringCmdable
|
StringCmdable
|
||||||
|
|
|
@ -3,6 +3,7 @@ package internal
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"net"
|
"net"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -81,3 +82,47 @@ func GetAddr(addr string) string {
|
||||||
}
|
}
|
||||||
return net.JoinHostPort(addr[:ind], addr[ind+1:])
|
return net.JoinHostPort(addr[:ind], addr[ind+1:])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ToInteger(val interface{}) int {
|
||||||
|
switch v := val.(type) {
|
||||||
|
case int:
|
||||||
|
return v
|
||||||
|
case int64:
|
||||||
|
return int(v)
|
||||||
|
case string:
|
||||||
|
i, _ := strconv.Atoi(v)
|
||||||
|
return i
|
||||||
|
default:
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func ToFloat(val interface{}) float64 {
|
||||||
|
switch v := val.(type) {
|
||||||
|
case float64:
|
||||||
|
return v
|
||||||
|
case string:
|
||||||
|
f, _ := strconv.ParseFloat(v, 64)
|
||||||
|
return f
|
||||||
|
default:
|
||||||
|
return 0.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func ToString(val interface{}) string {
|
||||||
|
if str, ok := val.(string); ok {
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func ToStringSlice(val interface{}) []string {
|
||||||
|
if arr, ok := val.([]interface{}); ok {
|
||||||
|
result := make([]string, len(arr))
|
||||||
|
for i, v := range arr {
|
||||||
|
result[i] = ToString(v)
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue