Skip to content

Commit 96fe058

Browse files
authored
Merge branch 'master' into dependabot/github_actions/rojopolis/spellcheck-github-actions-0.45.0
2 parents e8ede3c + 930d904 commit 96fe058

File tree

6 files changed

+2068
-1802
lines changed

6 files changed

+2068
-1802
lines changed

.github/wordlist.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ stunnel
5454
SynDump
5555
TCP
5656
TLS
57+
UnstableResp
5758
uri
5859
URI
5960
url
@@ -62,3 +63,5 @@ RedisStack
6263
RedisGears
6364
RedisTimeseries
6465
RediSearch
66+
RawResult
67+
RawVal

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,21 @@ rdb := redis.NewClient(&redis.Options{
186186
#### Unstable RESP3 Structures for RediSearch Commands
187187
When integrating Redis with application functionalities using RESP3, it's important to note that some response structures aren't final yet. This is especially true for more complex structures like search and query results. We recommend using RESP2 when using the search and query capabilities, but we plan to stabilize the RESP3-based API-s in the coming versions. You can find more guidance in the upcoming release notes.
188188

189+
To enable unstable RESP3, set the option in your client configuration:
190+
191+
```go
192+
redis.NewClient(&redis.Options{
193+
UnstableResp3: true,
194+
})
195+
```
196+
**Note:** When UnstableResp3 mode is enabled, it's necessary to use RawResult() and RawVal() to retrieve a raw data.
197+
Since, raw response is the only option for unstable search commands Val() and Result() calls wouldn't have any affect on them:
198+
199+
```go
200+
res1, err := client.FTSearchWithArgs(ctx, "txt", "foo bar", &redis.FTSearchOptions{}).RawResult()
201+
val1 := client.FTSearchWithArgs(ctx, "txt", "foo bar", &redis.FTSearchOptions{}).RawVal()
202+
```
203+
189204
## Contributing
190205

191206
Please see [out contributing guidelines](CONTRIBUTING.md) to help us improve this library!

command.go

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,27 +1403,63 @@ func (cmd *MapStringSliceInterfaceCmd) Val() map[string][]interface{} {
14031403
}
14041404

14051405
func (cmd *MapStringSliceInterfaceCmd) readReply(rd *proto.Reader) (err error) {
1406-
n, err := rd.ReadMapLen()
1406+
readType, err := rd.PeekReplyType()
14071407
if err != nil {
14081408
return err
14091409
}
1410-
cmd.val = make(map[string][]interface{}, n)
1411-
for i := 0; i < n; i++ {
1412-
k, err := rd.ReadString()
1410+
1411+
cmd.val = make(map[string][]interface{})
1412+
1413+
if readType == proto.RespMap {
1414+
n, err := rd.ReadMapLen()
14131415
if err != nil {
14141416
return err
14151417
}
1416-
nn, err := rd.ReadArrayLen()
1418+
for i := 0; i < n; i++ {
1419+
k, err := rd.ReadString()
1420+
if err != nil {
1421+
return err
1422+
}
1423+
nn, err := rd.ReadArrayLen()
1424+
if err != nil {
1425+
return err
1426+
}
1427+
cmd.val[k] = make([]interface{}, nn)
1428+
for j := 0; j < nn; j++ {
1429+
value, err := rd.ReadReply()
1430+
if err != nil {
1431+
return err
1432+
}
1433+
cmd.val[k][j] = value
1434+
}
1435+
}
1436+
} else if readType == proto.RespArray {
1437+
// RESP2 response
1438+
n, err := rd.ReadArrayLen()
14171439
if err != nil {
14181440
return err
14191441
}
1420-
cmd.val[k] = make([]interface{}, nn)
1421-
for j := 0; j < nn; j++ {
1422-
value, err := rd.ReadReply()
1442+
1443+
for i := 0; i < n; i++ {
1444+
// Each entry in this array is itself an array with key details
1445+
itemLen, err := rd.ReadArrayLen()
14231446
if err != nil {
14241447
return err
14251448
}
1426-
cmd.val[k][j] = value
1449+
1450+
key, err := rd.ReadString()
1451+
if err != nil {
1452+
return err
1453+
}
1454+
cmd.val[key] = make([]interface{}, 0, itemLen-1)
1455+
for j := 1; j < itemLen; j++ {
1456+
// Read the inner array for timestamp-value pairs
1457+
data, err := rd.ReadReply()
1458+
if err != nil {
1459+
return err
1460+
}
1461+
cmd.val[key] = append(cmd.val[key], data)
1462+
}
14271463
}
14281464
}
14291465

probabilistic.go

Lines changed: 52 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -319,37 +319,69 @@ func (cmd *BFInfoCmd) Result() (BFInfo, error) {
319319
}
320320

321321
func (cmd *BFInfoCmd) readReply(rd *proto.Reader) (err error) {
322-
n, err := rd.ReadMapLen()
322+
result := BFInfo{}
323+
324+
// Create a mapping from key names to pointers of struct fields
325+
respMapping := map[string]*int64{
326+
"Capacity": &result.Capacity,
327+
"CAPACITY": &result.Capacity,
328+
"Size": &result.Size,
329+
"SIZE": &result.Size,
330+
"Number of filters": &result.Filters,
331+
"FILTERS": &result.Filters,
332+
"Number of items inserted": &result.ItemsInserted,
333+
"ITEMS": &result.ItemsInserted,
334+
"Expansion rate": &result.ExpansionRate,
335+
"EXPANSION": &result.ExpansionRate,
336+
}
337+
338+
// Helper function to read and assign a value based on the key
339+
readAndAssignValue := func(key string) error {
340+
fieldPtr, exists := respMapping[key]
341+
if !exists {
342+
return fmt.Errorf("redis: BLOOM.INFO unexpected key %s", key)
343+
}
344+
345+
// Read the integer and assign to the field via pointer dereferencing
346+
val, err := rd.ReadInt()
347+
if err != nil {
348+
return err
349+
}
350+
*fieldPtr = val
351+
return nil
352+
}
353+
354+
readType, err := rd.PeekReplyType()
323355
if err != nil {
324356
return err
325357
}
326358

327-
var key string
328-
var result BFInfo
329-
for f := 0; f < n; f++ {
330-
key, err = rd.ReadString()
359+
if len(cmd.args) > 2 && readType == proto.RespArray {
360+
n, err := rd.ReadArrayLen()
331361
if err != nil {
332362
return err
333363
}
334-
335-
switch key {
336-
case "Capacity":
337-
result.Capacity, err = rd.ReadInt()
338-
case "Size":
339-
result.Size, err = rd.ReadInt()
340-
case "Number of filters":
341-
result.Filters, err = rd.ReadInt()
342-
case "Number of items inserted":
343-
result.ItemsInserted, err = rd.ReadInt()
344-
case "Expansion rate":
345-
result.ExpansionRate, err = rd.ReadInt()
346-
default:
347-
return fmt.Errorf("redis: BLOOM.INFO unexpected key %s", key)
364+
if key, ok := cmd.args[2].(string); ok && n == 1 {
365+
if err := readAndAssignValue(key); err != nil {
366+
return err
367+
}
368+
} else {
369+
return fmt.Errorf("redis: BLOOM.INFO invalid argument key type")
348370
}
349-
371+
} else {
372+
n, err := rd.ReadMapLen()
350373
if err != nil {
351374
return err
352375
}
376+
for i := 0; i < n; i++ {
377+
key, err := rd.ReadString()
378+
if err != nil {
379+
return err
380+
}
381+
if err := readAndAssignValue(key); err != nil {
382+
return err
383+
}
384+
}
353385
}
354386

355387
cmd.val = result

0 commit comments

Comments
 (0)