Repository navigation
Replies: 1 comment
|
The typed API can't return these, because type Entry struct {
ID string
Fields [][2]string
}
func parseEntries(raw []interface{}) []Entry {
var out []Entry
for _, e := range raw {
pair := e.([]interface{})
kv := pair[1].([]interface{})
entry := Entry{ID: pair[0].(string)}
for i := 0; i+1 < len(kv); i += 2 {
entry.Fields = append(entry.Fields, [2]string{kv[i].(string), kv[i+1].(string)})
}
out = append(out, entry)
}
return out
}
rdb := redis.NewClient(&redis.Options{Addr: addr, Protocol: 2})
res, err := rdb.Do(ctx, "XREADGROUP", "GROUP", "mygroup", "myconsumer",
"COUNT", "10", "STREAMS", "mystream", ">").Result()
if err != nil {
return err // redis.Nil means no new messages when you use BLOCK
}
for _, stream := range res.([]interface{}) {
entries := parseEntries(stream.([]interface{})[1].([]interface{}))
// entries[0].Fields: [[message a] [message b] [message c]]
}I ran this on v9.23.0 against miniredis, and all three I set |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I have a redis stream which I dont control but I have to write a listener for that.
The message that comes has multiple field value pairs, but they will be duplicated
e.g.
This is a valid way to add multiple fields all with the same field name and different values.
Now I can XAdd this using
however when consuming this using
XReadGroupit is consumed as amapand I don't get all the duplicate fields and values.Is there a way I can consume this?
Here is how it works in redis-cli I can xadd multiple messages in a single XAdd and receive them also with the order being preseved
How do I achieve this using go-redis ?
Kind of related - #1388
All reactions