Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support FT.CONFIG command #50

Merged
merged 1 commit into from
Apr 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 34 additions & 3 deletions redisearch/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ func (i *Client) Aggregate(q *AggregateQuery) (aggregateReply [][]string, total
}
// has no cursor
if !hasCursor {
total, aggregateReply,err = processAggReply(res)
// has cursor
total, aggregateReply, err = processAggReply(res)
// has cursor
} else {
var partialResults, err = redis.Values(res[0], nil)
if err != nil {
Expand All @@ -239,7 +239,7 @@ func (i *Client) Aggregate(q *AggregateQuery) (aggregateReply [][]string, total
if err != nil {
return aggregateReply, total, err
}
total, aggregateReply,err = processAggReply(partialResults)
total, aggregateReply, err = processAggReply(partialResults)
}

return
Expand Down Expand Up @@ -490,3 +490,34 @@ func (i *Client) Info() (*IndexInfo, error) {

return &ret, nil
}

// Set runtime configuration option
func (i *Client) SetConfig(option string, value string) (string, error) {
conn := i.pool.Get()
defer conn.Close()

args := redis.Args{"SET", option, value}
return redis.String(conn.Do("FT.CONFIG", args...))
}

// Get runtime configuration option value
func (i *Client) GetConfig(option string) (map[string]string, error) {
conn := i.pool.Get()
defer conn.Close()

args := redis.Args{"GET", option}
values, err := redis.Values(conn.Do("FT.CONFIG", args...))
if err != nil {
return nil, err
}

m := make(map[string]string)
valLen := len(values)
for i := 0; i < valLen; i++ {
kvs, _ := redis.Strings(values[i], nil)
if kvs != nil && len(kvs) == 2 {
m[kvs[0]] = kvs[1]
}
}
return m, nil
}
29 changes: 22 additions & 7 deletions redisearch/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,10 @@ func TestClient_DictAdd(t *testing.T) {
wantNewTerms int
wantErr bool
}{
{"empty-error", fields{pool: c.pool, name: c.name}, args{"dict1", []string{},}, 0, true},
{"1-term", fields{pool: c.pool, name: c.name}, args{"dict1", []string{"term1"},}, 1, false},
{"2nd-time-term", fields{pool: c.pool, name: c.name}, args{"dict1", []string{"term1"},}, 0, false},
{"multi-term", fields{pool: c.pool, name: c.name}, args{"dict1", []string{"t1", "t2", "t3", "t4", "t5"},}, 5, false},
{"empty-error", fields{pool: c.pool, name: c.name}, args{"dict1", []string{}}, 0, true},
{"1-term", fields{pool: c.pool, name: c.name}, args{"dict1", []string{"term1"}}, 1, false},
{"2nd-time-term", fields{pool: c.pool, name: c.name}, args{"dict1", []string{"term1"}}, 0, false},
{"multi-term", fields{pool: c.pool, name: c.name}, args{"dict1", []string{"t1", "t2", "t3", "t4", "t5"}}, 5, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -265,9 +265,9 @@ func TestClient_DictDel(t *testing.T) {
wantDeletedTerms int
wantErr bool
}{
{"empty-error", fields{pool: c.pool, name: c.name}, args{"dict1", []string{},}, 0, true},
{"1-term", fields{pool: c.pool, name: c.name}, args{"dict1", []string{"term1"},}, 1, false},
{"2nd-time-term", fields{pool: c.pool, name: c.name}, args{"dict1", []string{"term1"},}, 0, false},
{"empty-error", fields{pool: c.pool, name: c.name}, args{"dict1", []string{}}, 0, true},
{"1-term", fields{pool: c.pool, name: c.name}, args{"dict1", []string{"term1"}}, 1, false},
{"2nd-time-term", fields{pool: c.pool, name: c.name}, args{"dict1", []string{"term1"}}, 0, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -476,3 +476,18 @@ func TestClient_AliasUpdate(t *testing.T) {
})
}
}

func TestClient_Config(t *testing.T) {
c := createClient("testconfigindex")

ret, err := c.SetConfig("TIMEOUT", "100")
assert.Nil(t, err)
assert.Equal(t, "OK", ret)

var kvs map[string]string
kvs, _ = c.GetConfig("TIMEOUT")
assert.Equal(t, "100", kvs["TIMEOUT"])

kvs, _ = c.GetConfig("*")
assert.Equal(t, "100", kvs["TIMEOUT"])
}