Redigo: Redis streams

Created on 20 Nov 2018  路  3Comments  路  Source: gomodule/redigo

I am using Redigo in a project that relies on reading messages from streams. I know this is a newer feature of Redis, but is this something that Redigo plans to support natively in the future? I have cobbled together a stream reader by traversing through the nested interfaces returned from the Do() call and using type assertion (based on trial and improvement and knowledge of whats being sent) to pull useful results out. However this is extremely brittle and only works because I can guarantee whats being appended to the streams. If a code update is not required it would be great to see some documentation showing an idiomatic way of reading streams.

Enhancement Help wanted

Most helpful comment

r, err := redis.Values(conn.Do("XREAD", "STREAMS", "stream1", "stream2", "0-0", "0-0"))

for kIndex :=0; kIndex < len(r); kIndex++ {
    var keyInfo = r[kIndex].([]interface{})

    var key = string(keyInfo[0].([]byte))
    var idList = keyInfo[1].([]interface{})

    for idIndex :=0; idIndex <len(idList); idIndex++ {
        var idInfo = idList[idIndex].([]interface{})

        var id = string(idInfo[0].([]byte))

        var fieldList = idInfo[1].([]interface{})
        var field = string(fieldList[0].([]byte))
        var value = string(fieldList[1].([]byte))

        fmt.Println(key, id, field, value)
    }
}

All 3 comments

r, err := redis.Values(conn.Do("XREAD", "STREAMS", "stream1", "stream2", "0-0", "0-0"))

for kIndex :=0; kIndex < len(r); kIndex++ {
    var keyInfo = r[kIndex].([]interface{})

    var key = string(keyInfo[0].([]byte))
    var idList = keyInfo[1].([]interface{})

    for idIndex :=0; idIndex <len(idList); idIndex++ {
        var idInfo = idList[idIndex].([]interface{})

        var id = string(idInfo[0].([]byte))

        var fieldList = idInfo[1].([]interface{})
        var field = string(fieldList[0].([]byte))
        var value = string(fieldList[1].([]byte))

        fmt.Println(key, id, field, value)
    }
}

apologies for the radio silence, life got busy! I'm happy to tackle this feature if the main man wants it implemented as part of the API - @garyburd, otherwise I'll close this and carry on using the wrapper I mentioned.

I should have an ability to deserialize XREAD response to a struct{}
Currently I don't know how I can do it

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Serhioromano picture Serhioromano  路  7Comments

jney picture jney  路  17Comments

elimisteve picture elimisteve  路  7Comments

lovegnep picture lovegnep  路  18Comments

V2Vz picture V2Vz  路  4Comments