gosexy / redis

Redis client for Go that maps the full redis command list into equivalent Go functions.
MIT License
167 stars 44 forks source link

Unexpected behaviour for HMGet #12

Closed rif closed 11 years ago

rif commented 11 years ago

package main

When using HMGet I was expecting a to receive some values in the return array even if not all fields are valid hash keys (like here: http://redis.io/commands/hmget)

redis> HMGET myhash field1 field2 nofield

1) "Hello" 2) "World" 3) (nil)

In the example below I expect something like this: ["", "*"]. Why do I get an error?

package main import ( "log" "menteslibres.net/gosexy/redis" )

var host = "127.0.0.1" var port = uint(6379)

var client *redis.Client

func main() { client = redis.New() client.Connect(host, port)

client.HMSet("test", "123", "*", "456", "*", "789", "*")

if values, err := client.HMGet("test", "1232", "456"); err == nil {
    log.Print("Values: ", values)
} else {
    log.Fatal("Error: ", err)
}

client.Quit()

}

xiam commented 11 years ago

Not quite sure yet, but thanks for your snippet example. Is this the same error you're receiving?

2013/09/09 18:16:44 Error: ERR Operation against a key holding the wrong kind of value
xiam commented 11 years ago

Sorry, rushed to run the code without checking, that was actually unrelated. This was the error, right?

2013/09/09 18:26:10 Error: Received a nil response.

Let me see...

xiam commented 11 years ago

Yep, gosexy/redis was (incorrectly) considering nil an invalid response and that raised an error, it turns out nil is a valid response by itself. Now fixed, can you confirm?

rif commented 11 years ago

Yes I can confirm the HMGet error is gone. Thanks for the quick reply. (I was expecting github to send me an email on your response, but it didn't. Good that a friend pointed me to your answer.)

Redis should put a star next to your lib in their client list ;)

xiam commented 11 years ago

Thank you rif! nice to know you like gosexy/redis :-).