Reputation: 2141
I need to read a redis hash from redigo. This hash has variable keys. This causes a problem because ScanStruct requires me to know those keys beforehand, so I can put it in a struct and unpack the HGETALL result into that struct.
Is there a way to parse a redigo HGETALL result that has unknown keys? It does not have to be with ScanStruct (or even with redigo), as long as I can access the result from within go.
Upvotes: 1
Views: 3605
Reputation: 109331
ScanStruct
is just a convenience for when you're mapping a known struct to a redis hash.
Use the redis.StringMap
helper function to get a map[string]string
.
Everything is redis is a string, and the redigo library converts the values for you. You can easily convert the values as needed from their string representations. If you want the raw bytes without the first string conversion, you can use redis.Values
, which will return alternating keys and values in a []interface{}
.
Upvotes: 6