fzzbt/radix — pull request #13 by littlewhitetwo (2012-09-08 07:24:21+00:00)
Title: Choose the proper default value for ReplyNil response

hi, fzzbt

I made a patch to choose the default value of ReplyNil response for a Reply to transform to different type.

Why?
It is more practical.

It is useless to give a error message("XX is not available for this reply type") for ReplyNil . In this situation, the user should set his own value.
so, why do the library itself choose its default value (suits the need of common users) for different type and document it .
Doing so will simplify the usage of the redis Reply Api.
If the user has its own value for ReplyNil, then he can set his own base on Reply.Type

key Existence Problem
use Reply.Type == RelyNil to decide whether the key exist or not.

Now , the problem is that what is the proper default value ?

How?
I got two solution.
Here is my first solution. the patch is based on this default value.

Reply.Str() => ""
Reply.Bytes() => []byte{}/nil
Reply.Int64() => 0
Reply.Int() =>0
Reply.Bool() => false
Reply.List() = []string{}/nil
Reply.Hash() => map[string]string{}/ nil

Another alternative solution

change the prototype for functions of Reply type , so that the domain of return value can hold a nil value

Reply.Str() (string, error) => Reply.Str() (*string, error)
Reply.Int64() (int64, error) => Reply.Int64() (*int64, error)
Reply.Bool() (bool, error) => Reply.Bool() (*bool, error)

Reply.List() ([]string, error) no need to change
Reply.Bytes() ([]byte, error) no need to change
Reply.Hash() (map[string]string, error) no need to change

if the reply type is ReplyNil, return nil for the first result