Redigo type of value returned from GET

408 views Asked by At

I'd like to be able to GET a value of a key and immediately know what type it is. I'm using

res, err := conn.Do("GET", key)

This returns an interface{} in res. Depending on the type, I'd like to call one of the helper functions like redigo.String(res) or redigo.Bool(res). I know I can do conn.Do("TYPE", key) to get the type separately, but how can I get the type just from the result of one GET request?

1

There are 1 answers

0
sonus21 On

Wait, REDIS TYPE command does not provide you the details of value type it just tells you whether the key's value is a string, list, set, zset, hash, or stream.

So your application code or client code must identify what's it's equivalent for your programming language.

You can try to decode your data using the known key value types.