diff --git a/redis.go b/redis.go index 92e8d5b..fefac20 100644 --- a/redis.go +++ b/redis.go @@ -913,6 +913,10 @@ func valueToString(v reflect.Value) (string, os.Error) { } switch v := v.(type) { + case *reflect.PtrValue: + return valueToString(reflect.Indirect(v)) + case *reflect.InterfaceValue: + return valueToString(v.Elem()) case *reflect.BoolValue: x := v.Get() if x { @@ -1073,6 +1077,10 @@ func (client *Client) Hvals(key string) ([][]byte, os.Error) { func writeTo(data []byte, val reflect.Value) os.Error { s := string(data) switch v := val.(type) { + // if we're writing to an interace value, just set the byte data + // TODO: should we support writing to a pointer? + case *reflect.InterfaceValue: + v.Set(reflect.NewValue(data)) case *reflect.BoolValue: b, err := strconv.Atob(s) if err != nil { diff --git a/redis_test.go b/redis_test.go index 4dc6d21..2250572 100644 --- a/redis_test.go +++ b/redis_test.go @@ -324,12 +324,28 @@ func TestHash(t *testing.T) { err = client.Hgetall("hdne", &test5) if err == nil { t.Fatal("should be an error") + } + test6 := make(map[string]interface{}) + for _, v := range keys { + test6[v] = []byte(strings.Repeat(v, 5)) + } + client.Hmset("h4", test6) + + //test Hgetall + test7 := make(map[string]interface{}) + err = client.Hgetall("h4", &test7) + if err != nil { + t.Fatal("verifyHash Hgetall failed", err.String()) + } + if !reflect.DeepEqual(test6, test7) { + t.Fatal("verifyHash Hgetall failed") } client.Del("h") client.Del("h2") client.Del("h3") + client.Del("h4") } func BenchmarkMultipleGet(b *testing.B) {