From 6baaeefcc83645f5d695fe1c629b06eb03599b3e Mon Sep 17 00:00:00 2001 From: Michael Hoisie Date: Sat, 20 Apr 2013 20:50:36 -1000 Subject: [PATCH] Update for Go 1.0 --- .gitignore | 14 ++ Makefile | 23 +-- redis.go | 289 ++++++++++++++------------- redis_test.go | 87 ++++---- redis-dump.go => tools/redis-dump.go | 0 redis-load.go => tools/redis-load.go | 0 6 files changed, 206 insertions(+), 207 deletions(-) create mode 100644 .gitignore rename redis-dump.go => tools/redis-dump.go (100%) rename redis-load.go => tools/redis-load.go (100%) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..add3041 --- /dev/null +++ b/.gitignore @@ -0,0 +1,14 @@ +*.6 +*.8 +*.o +*.so +*.out +*.go~ +*.cgo?.* +_cgo_* +_obj +_test +_testmain.go +*.swp +_site +.DS_Store diff --git a/Makefile b/Makefile index eb1a627..0f1c86e 100644 --- a/Makefile +++ b/Makefile @@ -1,23 +1,10 @@ - -include $(GOROOT)/src/Make.inc - -TARG=redis +GOFMT=gofmt -s -tabs=false -tabwidth=4 GOFILES=\ redis.go\ -include $(GOROOT)/src/Make.pkg - -tools: - ${GC} -o redis-dump.${O} redis-dump.go - ${LD} -o redis-dump redis-dump.${O} - install -m 0755 redis-dump $(GOBIN) - ${GC} -o redis-load.${O} redis-load.go - ${LD} -o redis-load redis-load.${O} - install -m 0755 redis-load $(GOBIN) - format: - gofmt -spaces=true -tabindent=false -tabwidth=4 -w redis.go - gofmt -spaces=true -tabindent=false -tabwidth=4 -w redis_test.go - gofmt -spaces=true -tabindent=false -tabwidth=4 -w redis-load.go - gofmt -spaces=true -tabindent=false -tabwidth=4 -w redis-dump.go + ${GOFMT} -w ${GOFILES} + ${GOFMT} -w redis_test.go + ${GOFMT} -w tools/redis-load.go + ${GOFMT} -w tools/redis-dump.go diff --git a/redis.go b/redis.go index e6d46b2..68c1a57 100644 --- a/redis.go +++ b/redis.go @@ -3,12 +3,11 @@ package redis import ( "bufio" "bytes" - "container/vector" + "errors" "fmt" "io" "io/ioutil" "net" - "os" "reflect" "strconv" "strings" @@ -18,7 +17,7 @@ const ( MaxPoolSize = 5 ) -var defaultAddr = "127.0.0.1:7379" +var defaultAddr = "127.0.0.1:6379" type Client struct { Addr string @@ -30,13 +29,13 @@ type Client struct { type RedisError string -func (err RedisError) String() string { return "Redis Error: " + string(err) } +func (err RedisError) Error() string { return "Redis Error: " + string(err) } var doesNotExist = RedisError("Key does not exist ") // reads a bulk reply (i.e $5\r\nhello) -func readBulk(reader *bufio.Reader, head string) ([]byte, os.Error) { - var err os.Error +func readBulk(reader *bufio.Reader, head string) ([]byte, error) { + var err error var data []byte if head == "" { @@ -70,7 +69,7 @@ func readBulk(reader *bufio.Reader, head string) ([]byte, os.Error) { return data, err } -func writeRequest(writer io.Writer, cmd string, args ...string) os.Error { +func writeRequest(writer io.Writer, cmd string, args ...string) error { b := commandBytes(cmd, args...) _, err := writer.Write(b) return err @@ -84,10 +83,10 @@ func commandBytes(cmd string, args ...string) []byte { return cmdbuf.Bytes() } -func readResponse(reader *bufio.Reader) (interface{}, os.Error) { +func readResponse(reader *bufio.Reader) (interface{}, error) { var line string - var err os.Error + var err error //read until the first non-whitespace line for { @@ -111,7 +110,7 @@ func readResponse(reader *bufio.Reader) (interface{}, os.Error) { } if line[0] == ':' { - n, err := strconv.Atoi64(strings.TrimSpace(line[1:])) + n, err := strconv.ParseInt(strings.TrimSpace(line[1:]), 10, 64) if err != nil { return nil, RedisError("Int reply is not a number") } @@ -142,7 +141,7 @@ func readResponse(reader *bufio.Reader) (interface{}, os.Error) { return readBulk(reader, line) } -func (client *Client) rawSend(c net.Conn, cmd []byte) (interface{}, os.Error) { +func (client *Client) rawSend(c net.Conn, cmd []byte) (interface{}, error) { _, err := c.Write(cmd) if err != nil { return nil, err @@ -158,7 +157,7 @@ func (client *Client) rawSend(c net.Conn, cmd []byte) (interface{}, os.Error) { return data, nil } -func (client *Client) openConnection() (c net.Conn, err os.Error) { +func (client *Client) openConnection() (c net.Conn, err error) { var addr = defaultAddr @@ -182,20 +181,21 @@ func (client *Client) openConnection() (c net.Conn, err os.Error) { return } - -func (client *Client) sendCommand(cmd string, args ...string) (data interface{}, err os.Error) { +func (client *Client) sendCommand(cmd string, args ...string) (data interface{}, err error) { // grab a connection from the pool + var b []byte c, err := client.popCon() - if err != nil { + println(err.Error()) goto End } - b := commandBytes(cmd, args...) + b = commandBytes(cmd, args...) data, err = client.rawSend(c, b) - if err == os.EOF || err == os.EPIPE { + if err == io.EOF { c, err = client.openConnection() if err != nil { + println(err.Error()) goto End } @@ -210,21 +210,24 @@ End: return data, err } -func (client *Client) sendCommands(cmdArgs <-chan []string, data chan<- interface{}) (err os.Error) { +func (client *Client) sendCommands(cmdArgs <-chan []string, data chan<- interface{}) (err error) { // grab a connection from the pool c, err := client.popCon() + var reader *bufio.Reader + var pong interface{} + var errs chan error if err != nil { goto End } - reader := bufio.NewReader(c) + reader = bufio.NewReader(c) // Ping first to verify connection is open err = writeRequest(c, "PING") // On first attempt permit a reconnection attempt - if err == os.EOF { + if err == io.EOF { // Looks like we have to open a new connection c, err = client.openConnection() if err != nil { @@ -233,7 +236,7 @@ func (client *Client) sendCommands(cmdArgs <-chan []string, data chan<- interfac reader = bufio.NewReader(c) } else { // Read Ping response - pong, err := readResponse(reader) + pong, err = readResponse(reader) if pong != "PONG" { return RedisError("Unexpected response to PING.") } @@ -242,7 +245,7 @@ func (client *Client) sendCommands(cmdArgs <-chan []string, data chan<- interfac } } - errs := make(chan os.Error) + errs = make(chan error) go func() { for cmdArg := range cmdArgs { @@ -283,7 +286,7 @@ End: return err } -func (client *Client) popCon() (net.Conn, os.Error) { +func (client *Client) popCon() (net.Conn, error) { if client.pool == nil { client.pool = make(chan net.Conn, MaxPoolSize) for i := 0; i < MaxPoolSize; i++ { @@ -306,7 +309,7 @@ func (client *Client) pushCon(c net.Conn) { // General Commands -func (client *Client) Auth(password string) os.Error { +func (client *Client) Auth(password string) error { _, err := client.sendCommand("AUTH", password) if err != nil { return err @@ -315,7 +318,7 @@ func (client *Client) Auth(password string) os.Error { return nil } -func (client *Client) Exists(key string) (bool, os.Error) { +func (client *Client) Exists(key string) (bool, error) { res, err := client.sendCommand("EXISTS", key) if err != nil { return false, err @@ -323,7 +326,7 @@ func (client *Client) Exists(key string) (bool, os.Error) { return res.(int64) == 1, nil } -func (client *Client) Del(key string) (bool, os.Error) { +func (client *Client) Del(key string) (bool, error) { res, err := client.sendCommand("DEL", key) if err != nil { @@ -333,7 +336,7 @@ func (client *Client) Del(key string) (bool, os.Error) { return res.(int64) == 1, nil } -func (client *Client) Type(key string) (string, os.Error) { +func (client *Client) Type(key string) (string, error) { res, err := client.sendCommand("TYPE", key) if err != nil { @@ -343,7 +346,7 @@ func (client *Client) Type(key string) (string, os.Error) { return res.(string), nil } -func (client *Client) Keys(pattern string) ([]string, os.Error) { +func (client *Client) Keys(pattern string) ([]string, error) { res, err := client.sendCommand("KEYS", pattern) if err != nil { @@ -365,7 +368,7 @@ func (client *Client) Keys(pattern string) ([]string, os.Error) { return ret, nil } -func (client *Client) Randomkey() (string, os.Error) { +func (client *Client) Randomkey() (string, error) { res, err := client.sendCommand("RANDOMKEY") if err != nil { return "", err @@ -373,8 +376,7 @@ func (client *Client) Randomkey() (string, os.Error) { return res.(string), nil } - -func (client *Client) Rename(src string, dst string) os.Error { +func (client *Client) Rename(src string, dst string) error { _, err := client.sendCommand("RENAME", src, dst) if err != nil { return err @@ -382,7 +384,7 @@ func (client *Client) Rename(src string, dst string) os.Error { return nil } -func (client *Client) Renamenx(src string, dst string) (bool, os.Error) { +func (client *Client) Renamenx(src string, dst string) (bool, error) { res, err := client.sendCommand("RENAMENX", src, dst) if err != nil { return false, err @@ -390,7 +392,7 @@ func (client *Client) Renamenx(src string, dst string) (bool, os.Error) { return res.(int64) == 1, nil } -func (client *Client) Dbsize() (int, os.Error) { +func (client *Client) Dbsize() (int, error) { res, err := client.sendCommand("DBSIZE") if err != nil { return -1, err @@ -399,8 +401,8 @@ func (client *Client) Dbsize() (int, os.Error) { return int(res.(int64)), nil } -func (client *Client) Expire(key string, time int64) (bool, os.Error) { - res, err := client.sendCommand("EXPIRE", key, strconv.Itoa64(time)) +func (client *Client) Expire(key string, time int64) (bool, error) { + res, err := client.sendCommand("EXPIRE", key, strconv.FormatInt(time, 10)) if err != nil { return false, err @@ -409,7 +411,7 @@ func (client *Client) Expire(key string, time int64) (bool, os.Error) { return res.(int64) == 1, nil } -func (client *Client) Ttl(key string) (int64, os.Error) { +func (client *Client) Ttl(key string) (int64, error) { res, err := client.sendCommand("TTL", key) if err != nil { return -1, err @@ -418,7 +420,7 @@ func (client *Client) Ttl(key string) (int64, os.Error) { return res.(int64), nil } -func (client *Client) Move(key string, dbnum int) (bool, os.Error) { +func (client *Client) Move(key string, dbnum int) (bool, error) { res, err := client.sendCommand("MOVE", key, strconv.Itoa(dbnum)) if err != nil { @@ -428,7 +430,7 @@ func (client *Client) Move(key string, dbnum int) (bool, os.Error) { return res.(int64) == 1, nil } -func (client *Client) Flush(all bool) os.Error { +func (client *Client) Flush(all bool) error { var cmd string if all { cmd = "FLUSHALL" @@ -444,7 +446,7 @@ func (client *Client) Flush(all bool) os.Error { // String-related commands -func (client *Client) Set(key string, val []byte) os.Error { +func (client *Client) Set(key string, val []byte) error { _, err := client.sendCommand("SET", key, string(val)) if err != nil { @@ -454,7 +456,7 @@ func (client *Client) Set(key string, val []byte) os.Error { return nil } -func (client *Client) Get(key string) ([]byte, os.Error) { +func (client *Client) Get(key string) ([]byte, error) { res, _ := client.sendCommand("GET", key) if res == nil { return nil, RedisError("Key `" + key + "` does not exist") @@ -464,7 +466,7 @@ func (client *Client) Get(key string) ([]byte, os.Error) { return data, nil } -func (client *Client) Getset(key string, val []byte) ([]byte, os.Error) { +func (client *Client) Getset(key string, val []byte) ([]byte, error) { res, err := client.sendCommand("GETSET", key, string(val)) if err != nil { @@ -475,7 +477,7 @@ func (client *Client) Getset(key string, val []byte) ([]byte, os.Error) { return data, nil } -func (client *Client) Mget(keys ...string) ([][]byte, os.Error) { +func (client *Client) Mget(keys ...string) ([][]byte, error) { res, err := client.sendCommand("MGET", keys...) if err != nil { return nil, err @@ -485,7 +487,7 @@ func (client *Client) Mget(keys ...string) ([][]byte, os.Error) { return data, nil } -func (client *Client) Setnx(key string, val []byte) (bool, os.Error) { +func (client *Client) Setnx(key string, val []byte) (bool, error) { res, err := client.sendCommand("SETNX", key, string(val)) if err != nil { @@ -497,8 +499,8 @@ func (client *Client) Setnx(key string, val []byte) (bool, os.Error) { return false, RedisError("Unexpected reply to SETNX") } -func (client *Client) Setex(key string, time int64, val []byte) os.Error { - _, err := client.sendCommand("SETEX", key, strconv.Itoa64(time), string(val)) +func (client *Client) Setex(key string, time int64, val []byte) error { + _, err := client.sendCommand("SETEX", key, strconv.FormatInt(time, 10), string(val)) if err != nil { return err @@ -507,7 +509,7 @@ func (client *Client) Setex(key string, time int64, val []byte) os.Error { return nil } -func (client *Client) Mset(mapping map[string][]byte) os.Error { +func (client *Client) Mset(mapping map[string][]byte) error { args := make([]string, len(mapping)*2) i := 0 for k, v := range mapping { @@ -522,7 +524,7 @@ func (client *Client) Mset(mapping map[string][]byte) os.Error { return nil } -func (client *Client) Msetnx(mapping map[string][]byte) (bool, os.Error) { +func (client *Client) Msetnx(mapping map[string][]byte) (bool, error) { args := make([]string, len(mapping)*2) i := 0 for k, v := range mapping { @@ -540,7 +542,7 @@ func (client *Client) Msetnx(mapping map[string][]byte) (bool, os.Error) { return false, RedisError("Unexpected reply to MSETNX") } -func (client *Client) Incr(key string) (int64, os.Error) { +func (client *Client) Incr(key string) (int64, error) { res, err := client.sendCommand("INCR", key) if err != nil { return -1, err @@ -549,8 +551,8 @@ func (client *Client) Incr(key string) (int64, os.Error) { return res.(int64), nil } -func (client *Client) Incrby(key string, val int64) (int64, os.Error) { - res, err := client.sendCommand("INCRBY", key, strconv.Itoa64(val)) +func (client *Client) Incrby(key string, val int64) (int64, error) { + res, err := client.sendCommand("INCRBY", key, strconv.FormatInt(val, 10)) if err != nil { return -1, err } @@ -558,7 +560,7 @@ func (client *Client) Incrby(key string, val int64) (int64, os.Error) { return res.(int64), nil } -func (client *Client) Decr(key string) (int64, os.Error) { +func (client *Client) Decr(key string) (int64, error) { res, err := client.sendCommand("DECR", key) if err != nil { return -1, err @@ -567,8 +569,8 @@ func (client *Client) Decr(key string) (int64, os.Error) { return res.(int64), nil } -func (client *Client) Decrby(key string, val int64) (int64, os.Error) { - res, err := client.sendCommand("DECRBY", key, strconv.Itoa64(val)) +func (client *Client) Decrby(key string, val int64) (int64, error) { + res, err := client.sendCommand("DECRBY", key, strconv.FormatInt(val, 10)) if err != nil { return -1, err } @@ -576,7 +578,7 @@ func (client *Client) Decrby(key string, val int64) (int64, os.Error) { return res.(int64), nil } -func (client *Client) Append(key string, val []byte) os.Error { +func (client *Client) Append(key string, val []byte) error { _, err := client.sendCommand("APPEND", key, string(val)) if err != nil { @@ -586,7 +588,7 @@ func (client *Client) Append(key string, val []byte) os.Error { return nil } -func (client *Client) Substr(key string, start int, end int) ([]byte, os.Error) { +func (client *Client) Substr(key string, start int, end int) ([]byte, error) { res, _ := client.sendCommand("SUBSTR", key, strconv.Itoa(start), strconv.Itoa(end)) if res == nil { @@ -599,7 +601,7 @@ func (client *Client) Substr(key string, start int, end int) ([]byte, os.Error) // List commands -func (client *Client) Rpush(key string, val []byte) os.Error { +func (client *Client) Rpush(key string, val []byte) error { _, err := client.sendCommand("RPUSH", key, string(val)) if err != nil { @@ -609,7 +611,7 @@ func (client *Client) Rpush(key string, val []byte) os.Error { return nil } -func (client *Client) Lpush(key string, val []byte) os.Error { +func (client *Client) Lpush(key string, val []byte) error { _, err := client.sendCommand("LPUSH", key, string(val)) if err != nil { @@ -619,7 +621,7 @@ func (client *Client) Lpush(key string, val []byte) os.Error { return nil } -func (client *Client) Llen(key string) (int, os.Error) { +func (client *Client) Llen(key string) (int, error) { res, err := client.sendCommand("LLEN", key) if err != nil { return -1, err @@ -628,7 +630,7 @@ func (client *Client) Llen(key string) (int, os.Error) { return int(res.(int64)), nil } -func (client *Client) Lrange(key string, start int, end int) ([][]byte, os.Error) { +func (client *Client) Lrange(key string, start int, end int) ([][]byte, error) { res, err := client.sendCommand("LRANGE", key, strconv.Itoa(start), strconv.Itoa(end)) if err != nil { return nil, err @@ -637,7 +639,7 @@ func (client *Client) Lrange(key string, start int, end int) ([][]byte, os.Error return res.([][]byte), nil } -func (client *Client) Ltrim(key string, start int, end int) os.Error { +func (client *Client) Ltrim(key string, start int, end int) error { _, err := client.sendCommand("LTRIM", key, strconv.Itoa(start), strconv.Itoa(end)) if err != nil { return err @@ -646,7 +648,7 @@ func (client *Client) Ltrim(key string, start int, end int) os.Error { return nil } -func (client *Client) Lindex(key string, index int) ([]byte, os.Error) { +func (client *Client) Lindex(key string, index int) ([]byte, error) { res, err := client.sendCommand("LINDEX", key, strconv.Itoa(index)) if err != nil { return nil, err @@ -655,7 +657,7 @@ func (client *Client) Lindex(key string, index int) ([]byte, os.Error) { return res.([]byte), nil } -func (client *Client) Lset(key string, index int, value []byte) os.Error { +func (client *Client) Lset(key string, index int, value []byte) error { _, err := client.sendCommand("LSET", key, strconv.Itoa(index), string(value)) if err != nil { return err @@ -664,7 +666,7 @@ func (client *Client) Lset(key string, index int, value []byte) os.Error { return nil } -func (client *Client) Lrem(key string, index int) (int, os.Error) { +func (client *Client) Lrem(key string, index int) (int, error) { res, err := client.sendCommand("LREM", key, strconv.Itoa(index)) if err != nil { return -1, err @@ -673,7 +675,7 @@ func (client *Client) Lrem(key string, index int) (int, os.Error) { return int(res.(int64)), nil } -func (client *Client) Lpop(key string) ([]byte, os.Error) { +func (client *Client) Lpop(key string) ([]byte, error) { res, err := client.sendCommand("LPOP", key) if err != nil { return nil, err @@ -682,7 +684,7 @@ func (client *Client) Lpop(key string) ([]byte, os.Error) { return res.([]byte), nil } -func (client *Client) Rpop(key string) ([]byte, os.Error) { +func (client *Client) Rpop(key string) ([]byte, error) { res, err := client.sendCommand("RPOP", key) if err != nil { return nil, err @@ -691,15 +693,15 @@ func (client *Client) Rpop(key string) ([]byte, os.Error) { return res.([]byte), nil } -func (client *Client) Blpop(keys []string, timeoutSecs uint) (*string, []byte, os.Error) { +func (client *Client) Blpop(keys []string, timeoutSecs uint) (*string, []byte, error) { return client.bpop("BLPOP", keys, timeoutSecs) } -func (client *Client) Brpop(keys []string, timeoutSecs uint) (*string, []byte, os.Error) { +func (client *Client) Brpop(keys []string, timeoutSecs uint) (*string, []byte, error) { return client.bpop("BRPOP", keys, timeoutSecs) } -func (client *Client) bpop(cmd string, keys []string, timeoutSecs uint) (*string, []byte, os.Error) { - args := append(keys, strconv.Uitoa(timeoutSecs)) +func (client *Client) bpop(cmd string, keys []string, timeoutSecs uint) (*string, []byte, error) { + args := append(keys, strconv.FormatUint(uint64(timeoutSecs), 10)) res, err := client.sendCommand(cmd, args...) if err != nil { return nil, nil, err @@ -714,7 +716,7 @@ func (client *Client) bpop(cmd string, keys []string, timeoutSecs uint) (*string return &k, v, nil } -func (client *Client) Rpoplpush(src string, dst string) ([]byte, os.Error) { +func (client *Client) Rpoplpush(src string, dst string) ([]byte, error) { res, err := client.sendCommand("RPOPLPUSH", src, dst) if err != nil { return nil, err @@ -725,7 +727,7 @@ func (client *Client) Rpoplpush(src string, dst string) ([]byte, os.Error) { // Set commands -func (client *Client) Sadd(key string, value []byte) (bool, os.Error) { +func (client *Client) Sadd(key string, value []byte) (bool, error) { res, err := client.sendCommand("SADD", key, string(value)) if err != nil { @@ -735,7 +737,7 @@ func (client *Client) Sadd(key string, value []byte) (bool, os.Error) { return res.(int64) == 1, nil } -func (client *Client) Srem(key string, value []byte) (bool, os.Error) { +func (client *Client) Srem(key string, value []byte) (bool, error) { res, err := client.sendCommand("SREM", key, string(value)) if err != nil { @@ -745,7 +747,7 @@ func (client *Client) Srem(key string, value []byte) (bool, os.Error) { return res.(int64) == 1, nil } -func (client *Client) Spop(key string) ([]byte, os.Error) { +func (client *Client) Spop(key string) ([]byte, error) { res, err := client.sendCommand("SPOP", key) if err != nil { return nil, err @@ -759,7 +761,7 @@ func (client *Client) Spop(key string) ([]byte, os.Error) { return data, nil } -func (client *Client) Smove(src string, dst string, val []byte) (bool, os.Error) { +func (client *Client) Smove(src string, dst string, val []byte) (bool, error) { res, err := client.sendCommand("SMOVE", src, dst, string(val)) if err != nil { return false, err @@ -768,7 +770,7 @@ func (client *Client) Smove(src string, dst string, val []byte) (bool, os.Error) return res.(int64) == 1, nil } -func (client *Client) Scard(key string) (int, os.Error) { +func (client *Client) Scard(key string) (int, error) { res, err := client.sendCommand("SCARD", key) if err != nil { return -1, err @@ -777,7 +779,7 @@ func (client *Client) Scard(key string) (int, os.Error) { return int(res.(int64)), nil } -func (client *Client) Sismember(key string, value []byte) (bool, os.Error) { +func (client *Client) Sismember(key string, value []byte) (bool, error) { res, err := client.sendCommand("SISMEMBER", key, string(value)) if err != nil { @@ -787,7 +789,7 @@ func (client *Client) Sismember(key string, value []byte) (bool, os.Error) { return res.(int64) == 1, nil } -func (client *Client) Sinter(keys ...string) ([][]byte, os.Error) { +func (client *Client) Sinter(keys ...string) ([][]byte, error) { res, err := client.sendCommand("SINTER", keys...) if err != nil { return nil, err @@ -796,7 +798,7 @@ func (client *Client) Sinter(keys ...string) ([][]byte, os.Error) { return res.([][]byte), nil } -func (client *Client) Sinterstore(dst string, keys ...string) (int, os.Error) { +func (client *Client) Sinterstore(dst string, keys ...string) (int, error) { args := make([]string, len(keys)+1) args[0] = dst copy(args[1:], keys) @@ -808,7 +810,7 @@ func (client *Client) Sinterstore(dst string, keys ...string) (int, os.Error) { return int(res.(int64)), nil } -func (client *Client) Sunion(keys ...string) ([][]byte, os.Error) { +func (client *Client) Sunion(keys ...string) ([][]byte, error) { res, err := client.sendCommand("SUNION", keys...) if err != nil { return nil, err @@ -817,7 +819,7 @@ func (client *Client) Sunion(keys ...string) ([][]byte, os.Error) { return res.([][]byte), nil } -func (client *Client) Sunionstore(dst string, keys ...string) (int, os.Error) { +func (client *Client) Sunionstore(dst string, keys ...string) (int, error) { args := make([]string, len(keys)+1) args[0] = dst copy(args[1:], keys) @@ -829,7 +831,7 @@ func (client *Client) Sunionstore(dst string, keys ...string) (int, os.Error) { return int(res.(int64)), nil } -func (client *Client) Sdiff(key1 string, keys []string) ([][]byte, os.Error) { +func (client *Client) Sdiff(key1 string, keys []string) ([][]byte, error) { args := make([]string, len(keys)+1) args[0] = key1 copy(args[1:], keys) @@ -841,7 +843,7 @@ func (client *Client) Sdiff(key1 string, keys []string) ([][]byte, os.Error) { return res.([][]byte), nil } -func (client *Client) Sdiffstore(dst string, key1 string, keys []string) (int, os.Error) { +func (client *Client) Sdiffstore(dst string, key1 string, keys []string) (int, error) { args := make([]string, len(keys)+2) args[0] = dst args[1] = key1 @@ -854,7 +856,7 @@ func (client *Client) Sdiffstore(dst string, key1 string, keys []string) (int, o return int(res.(int64)), nil } -func (client *Client) Smembers(key string) ([][]byte, os.Error) { +func (client *Client) Smembers(key string) ([][]byte, error) { res, err := client.sendCommand("SMEMBERS", key) if err != nil { @@ -864,7 +866,7 @@ func (client *Client) Smembers(key string) ([][]byte, os.Error) { return res.([][]byte), nil } -func (client *Client) Srandmember(key string) ([]byte, os.Error) { +func (client *Client) Srandmember(key string) ([]byte, error) { res, err := client.sendCommand("SRANDMEMBER", key) if err != nil { return nil, err @@ -875,8 +877,8 @@ func (client *Client) Srandmember(key string) ([]byte, os.Error) { // sorted set commands -func (client *Client) Zadd(key string, value []byte, score float64) (bool, os.Error) { - res, err := client.sendCommand("ZADD", key, strconv.Ftoa64(score, 'f', -1), string(value)) +func (client *Client) Zadd(key string, value []byte, score float64) (bool, error) { + res, err := client.sendCommand("ZADD", key, strconv.FormatFloat(score, 'f', -1, 64), string(value)) if err != nil { return false, err } @@ -884,7 +886,7 @@ func (client *Client) Zadd(key string, value []byte, score float64) (bool, os.Er return res.(int64) == 1, nil } -func (client *Client) Zrem(key string, value []byte) (bool, os.Error) { +func (client *Client) Zrem(key string, value []byte) (bool, error) { res, err := client.sendCommand("ZREM", key, string(value)) if err != nil { return false, err @@ -893,18 +895,18 @@ func (client *Client) Zrem(key string, value []byte) (bool, os.Error) { return res.(int64) == 1, nil } -func (client *Client) Zincrby(key string, value []byte, score float64) (float64, os.Error) { - res, err := client.sendCommand("ZINCRBY", key, strconv.Ftoa64(score, 'f', -1), string(value)) +func (client *Client) Zincrby(key string, value []byte, score float64) (float64, error) { + res, err := client.sendCommand("ZINCRBY", key, strconv.FormatFloat(score, 'f', -1, 64), string(value)) if err != nil { return 0, err } data := string(res.([]byte)) - f, _ := strconv.Atof64(data) + f, _ := strconv.ParseFloat(data, 64) return f, nil } -func (client *Client) Zrank(key string, value []byte) (int, os.Error) { +func (client *Client) Zrank(key string, value []byte) (int, error) { res, err := client.sendCommand("ZRANK", key, string(value)) if err != nil { return 0, err @@ -913,7 +915,7 @@ func (client *Client) Zrank(key string, value []byte) (int, os.Error) { return int(res.(int64)), nil } -func (client *Client) Zrevrank(key string, value []byte) (int, os.Error) { +func (client *Client) Zrevrank(key string, value []byte) (int, error) { res, err := client.sendCommand("ZREVRANK", key, string(value)) if err != nil { return 0, err @@ -922,7 +924,7 @@ func (client *Client) Zrevrank(key string, value []byte) (int, os.Error) { return int(res.(int64)), nil } -func (client *Client) Zrange(key string, start int, end int) ([][]byte, os.Error) { +func (client *Client) Zrange(key string, start int, end int) ([][]byte, error) { res, err := client.sendCommand("ZRANGE", key, strconv.Itoa(start), strconv.Itoa(end)) if err != nil { return nil, err @@ -931,7 +933,7 @@ func (client *Client) Zrange(key string, start int, end int) ([][]byte, os.Error return res.([][]byte), nil } -func (client *Client) Zrevrange(key string, start int, end int) ([][]byte, os.Error) { +func (client *Client) Zrevrange(key string, start int, end int) ([][]byte, error) { res, err := client.sendCommand("ZREVRANGE", key, strconv.Itoa(start), strconv.Itoa(end)) if err != nil { return nil, err @@ -940,8 +942,8 @@ func (client *Client) Zrevrange(key string, start int, end int) ([][]byte, os.Er return res.([][]byte), nil } -func (client *Client) Zrangebyscore(key string, start float64, end float64) ([][]byte, os.Error) { - res, err := client.sendCommand("ZRANGEBYSCORE", key, strconv.Ftoa64(start, 'f', -1), strconv.Ftoa64(end, 'f', -1)) +func (client *Client) Zrangebyscore(key string, start float64, end float64) ([][]byte, error) { + res, err := client.sendCommand("ZRANGEBYSCORE", key, strconv.FormatFloat(start, 'f', -1, 64), strconv.FormatFloat(end, 'f', -1, 64)) if err != nil { return nil, err } @@ -949,7 +951,7 @@ func (client *Client) Zrangebyscore(key string, start float64, end float64) ([][ return res.([][]byte), nil } -func (client *Client) Zcard(key string) (int, os.Error) { +func (client *Client) Zcard(key string) (int, error) { res, err := client.sendCommand("ZCARD", key) if err != nil { return -1, err @@ -958,18 +960,18 @@ func (client *Client) Zcard(key string) (int, os.Error) { return int(res.(int64)), nil } -func (client *Client) Zscore(key string, member []byte) (float64, os.Error) { +func (client *Client) Zscore(key string, member []byte) (float64, error) { res, err := client.sendCommand("ZSCORE", key, string(member)) if err != nil { return 0, err } data := string(res.([]byte)) - f, _ := strconv.Atof64(data) + f, _ := strconv.ParseFloat(data, 64) return f, nil } -func (client *Client) Zremrangebyrank(key string, start int, end int) (int, os.Error) { +func (client *Client) Zremrangebyrank(key string, start int, end int) (int, error) { res, err := client.sendCommand("ZREMRANGEBYRANK", key, strconv.Itoa(start), strconv.Itoa(end)) if err != nil { return -1, err @@ -978,8 +980,8 @@ func (client *Client) Zremrangebyrank(key string, start int, end int) (int, os.E return int(res.(int64)), nil } -func (client *Client) Zremrangebyscore(key string, start float64, end float64) (int, os.Error) { - res, err := client.sendCommand("ZREMRANGEBYSCORE", key, strconv.Ftoa64(start, 'f', -1), strconv.Ftoa64(end, 'f', -1)) +func (client *Client) Zremrangebyscore(key string, start float64, end float64) (int, error) { + res, err := client.sendCommand("ZREMRANGEBYSCORE", key, strconv.FormatFloat(start, 'f', -1, 64), strconv.FormatFloat(end, 'f', -1, 64)) if err != nil { return -1, err } @@ -989,7 +991,7 @@ func (client *Client) Zremrangebyscore(key string, start float64, end float64) ( // hash commands -func (client *Client) Hset(key string, field string, val []byte) (bool, os.Error) { +func (client *Client) Hset(key string, field string, val []byte) (bool, error) { res, err := client.sendCommand("HSET", key, field, string(val)) if err != nil { return false, err @@ -998,7 +1000,7 @@ func (client *Client) Hset(key string, field string, val []byte) (bool, os.Error return res.(int64) == 1, nil } -func (client *Client) Hget(key string, field string) ([]byte, os.Error) { +func (client *Client) Hget(key string, field string) ([]byte, error) { res, _ := client.sendCommand("HGET", key, field) if res == nil { @@ -1011,7 +1013,7 @@ func (client *Client) Hget(key string, field string) ([]byte, os.Error) { //pretty much copy the json code from here. -func valueToString(v reflect.Value) (string, os.Error) { +func valueToString(v reflect.Value) (string, error) { if !v.IsValid() { return "null", nil } @@ -1030,14 +1032,14 @@ func valueToString(v reflect.Value) (string, os.Error) { } case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - return strconv.Itoa64(v.Int()), nil + return strconv.FormatInt(v.Int(), 10), nil case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: - return strconv.Uitoa64(v.Uint()), nil + return strconv.FormatUint(v.Uint(), 10), nil case reflect.UnsafePointer: - return strconv.Uitoa64(uint64(v.Pointer())), nil + return strconv.FormatUint(uint64(v.Pointer()), 10), nil case reflect.Float32, reflect.Float64: - return strconv.Ftoa64(v.Float(), 'g', -1), nil + return strconv.FormatFloat(v.Float(), 'g', -1, 64), nil case reflect.String: return v.String(), nil @@ -1055,10 +1057,10 @@ func valueToString(v reflect.Value) (string, os.Error) { } } } - return "", os.NewError("Unsupported type") + return "", errors.New("Unsupported type") } -func containerToString(val reflect.Value, args *vector.StringVector) os.Error { +func containerToString(val reflect.Value, args *[]string) error { switch v := val; v.Kind() { case reflect.Ptr: return containerToString(reflect.Indirect(v), args) @@ -1066,47 +1068,47 @@ func containerToString(val reflect.Value, args *vector.StringVector) os.Error { return containerToString(v.Elem(), args) case reflect.Map: if v.Type().Key().Kind() != reflect.String { - return os.NewError("Unsupported type - map key must be a string") + return errors.New("Unsupported type - map key must be a string") } for _, k := range v.MapKeys() { - args.Push(k.String()) + *args = append(*args, k.String()) s, err := valueToString(v.MapIndex(k)) if err != nil { return err } - args.Push(s) + *args = append(*args, s) } case reflect.Struct: st := v.Type() for i := 0; i < st.NumField(); i++ { ft := st.FieldByIndex([]int{i}) - args.Push(ft.Name) + *args = append(*args, ft.Name) s, err := valueToString(v.FieldByIndex([]int{i})) if err != nil { return err } - args.Push(s) + *args = append(*args, s) } } return nil } -func (client *Client) Hmset(key string, mapping interface{}) os.Error { - args := new(vector.StringVector) - args.Push(key) - err := containerToString(reflect.ValueOf(mapping), args) +func (client *Client) Hmset(key string, mapping interface{}) error { + var args []string + args = append(args, key) + err := containerToString(reflect.ValueOf(mapping), &args) if err != nil { return err } - _, err = client.sendCommand("HMSET", *args...) + _, err = client.sendCommand("HMSET", args...) if err != nil { return err } return nil } -func (client *Client) Hincrby(key string, field string, val int64) (int64, os.Error) { - res, err := client.sendCommand("HINCRBY", key, field, strconv.Itoa64(val)) +func (client *Client) Hincrby(key string, field string, val int64) (int64, error) { + res, err := client.sendCommand("HINCRBY", key, field, strconv.FormatInt(val, 10)) if err != nil { return -1, err } @@ -1114,7 +1116,7 @@ func (client *Client) Hincrby(key string, field string, val int64) (int64, os.Er return res.(int64), nil } -func (client *Client) Hexists(key string, field string) (bool, os.Error) { +func (client *Client) Hexists(key string, field string) (bool, error) { res, err := client.sendCommand("HEXISTS", key, field) if err != nil { return false, err @@ -1122,7 +1124,7 @@ func (client *Client) Hexists(key string, field string) (bool, os.Error) { return res.(int64) == 1, nil } -func (client *Client) Hdel(key string, field string) (bool, os.Error) { +func (client *Client) Hdel(key string, field string) (bool, error) { res, err := client.sendCommand("HDEL", key, field) if err != nil { @@ -1132,7 +1134,7 @@ func (client *Client) Hdel(key string, field string) (bool, os.Error) { return res.(int64) == 1, nil } -func (client *Client) Hlen(key string) (int, os.Error) { +func (client *Client) Hlen(key string) (int, error) { res, err := client.sendCommand("HLEN", key) if err != nil { return -1, err @@ -1141,7 +1143,7 @@ func (client *Client) Hlen(key string) (int, os.Error) { return int(res.(int64)), nil } -func (client *Client) Hkeys(key string) ([]string, os.Error) { +func (client *Client) Hkeys(key string) ([]string, error) { res, err := client.sendCommand("HKEYS", key) if err != nil { @@ -1156,7 +1158,7 @@ func (client *Client) Hkeys(key string) ([]string, os.Error) { return ret, nil } -func (client *Client) Hvals(key string) ([][]byte, os.Error) { +func (client *Client) Hvals(key string) ([][]byte, error) { res, err := client.sendCommand("HVALS", key) if err != nil { @@ -1165,7 +1167,7 @@ func (client *Client) Hvals(key string) ([][]byte, os.Error) { return res.([][]byte), nil } -func writeTo(data []byte, val reflect.Value) os.Error { +func writeTo(data []byte, val reflect.Value) error { s := string(data) switch v := val; v.Kind() { // if we're writing to an interace value, just set the byte data @@ -1173,25 +1175,25 @@ func writeTo(data []byte, val reflect.Value) os.Error { case reflect.Interface: v.Set(reflect.ValueOf(data)) case reflect.Bool: - b, err := strconv.Atob(s) + b, err := strconv.ParseBool(s) if err != nil { return err } v.SetBool(b) case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: - i, err := strconv.Atoi64(s) + i, err := strconv.ParseInt(s, 10, 64) if err != nil { return err } v.SetInt(i) case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: - ui, err := strconv.Atoui64(s) + ui, err := strconv.ParseUint(s, 10, 64) if err != nil { return err } v.SetUint(ui) case reflect.Float32, reflect.Float64: - f, err := strconv.Atof64(s) + f, err := strconv.ParseFloat(s, 64) if err != nil { return err } @@ -1208,7 +1210,7 @@ func writeTo(data []byte, val reflect.Value) os.Error { return nil } -func writeToContainer(data [][]byte, val reflect.Value) os.Error { +func writeToContainer(data [][]byte, val reflect.Value) error { switch v := val; v.Kind() { case reflect.Ptr: return writeToContainer(data, reflect.Indirect(v)) @@ -1216,7 +1218,7 @@ func writeToContainer(data [][]byte, val reflect.Value) os.Error { return writeToContainer(data, v.Elem()) case reflect.Map: if v.Type().Key().Kind() != reflect.String { - return os.NewError("Invalid map type") + return errors.New("Invalid map type") } elemtype := v.Type().Elem() for i := 0; i < len(data)/2; i++ { @@ -1235,13 +1237,12 @@ func writeToContainer(data [][]byte, val reflect.Value) os.Error { writeTo(data[i*2+1], field) } default: - return os.NewError("Invalid container type") + return errors.New("Invalid container type") } return nil } - -func (client *Client) Hgetall(key string, val interface{}) os.Error { +func (client *Client) Hgetall(key string, val interface{}) error { res, err := client.sendCommand("HGETALL", key) if err != nil { return err @@ -1273,7 +1274,7 @@ type Message struct { // The former does an exact match on the channel, the later uses glob patterns on the redis channels. // Closing either of these channels will unblock this method call. // Messages that are received are sent down the messages channel. -func (client *Client) Subscribe(subscribe <-chan string, unsubscribe <-chan string, psubscribe <-chan string, punsubscribe <-chan string, messages chan<- Message) os.Error { +func (client *Client) Subscribe(subscribe <-chan string, unsubscribe <-chan string, psubscribe <-chan string, punsubscribe <-chan string, messages chan<- Message) error { cmds := make(chan []string, 0) data := make(chan interface{}, 0) @@ -1335,7 +1336,7 @@ func (client *Client) Subscribe(subscribe <-chan string, unsubscribe <-chan stri } // Publish a message to a redis server. -func (client *Client) Publish(channel string, val []byte) os.Error { +func (client *Client) Publish(channel string, val []byte) error { _, err := client.sendCommand("PUBLISH", channel, string(val)) if err != nil { return err @@ -1345,7 +1346,7 @@ func (client *Client) Publish(channel string, val []byte) os.Error { //Server commands -func (client *Client) Save() os.Error { +func (client *Client) Save() error { _, err := client.sendCommand("SAVE") if err != nil { return err @@ -1353,7 +1354,7 @@ func (client *Client) Save() os.Error { return nil } -func (client *Client) Bgsave() os.Error { +func (client *Client) Bgsave() error { _, err := client.sendCommand("BGSAVE") if err != nil { return err @@ -1361,7 +1362,7 @@ func (client *Client) Bgsave() os.Error { return nil } -func (client *Client) Lastsave() (int64, os.Error) { +func (client *Client) Lastsave() (int64, error) { res, err := client.sendCommand("LASTSAVE") if err != nil { return 0, err @@ -1370,7 +1371,7 @@ func (client *Client) Lastsave() (int64, os.Error) { return res.(int64), nil } -func (client *Client) Bgrewriteaof() os.Error { +func (client *Client) Bgrewriteaof() error { _, err := client.sendCommand("BGREWRITEAOF") if err != nil { return err diff --git a/redis_test.go b/redis_test.go index 9576a00..d31832f 100644 --- a/redis_test.go +++ b/redis_test.go @@ -1,16 +1,14 @@ package redis import ( - "container/vector" + "encoding/json" "fmt" - "json" - "os" "reflect" "runtime" "strconv" "strings" - "time" "testing" + "time" ) const ( @@ -23,19 +21,19 @@ var client Client func init() { runtime.GOMAXPROCS(2) - client.Addr = "127.0.0.1:7379" + client.Addr = "127.0.0.1:6379" client.Db = 13 } func TestBasic(t *testing.T) { var val []byte - var err os.Error + var err error err = client.Set("a", []byte("hello")) if err != nil { - t.Fatal("set failed", err.String()) + t.Fatal("set failed", err.Error()) } if val, err = client.Get("a"); err != nil || string(val) != "hello" { @@ -62,13 +60,13 @@ func setget(t *testing.T, i int) { s := strconv.Itoa(i) err := client.Set(s, []byte(s)) if err != nil { - t.Fatal("Concurrent set", err.String()) + t.Fatal("Concurrent set", err.Error()) } s2, err := client.Get(s) if err != nil { - t.Fatal("Concurrent get", err.String()) + t.Fatal("Concurrent get", err.Error()) } if s != string(s2) { @@ -89,7 +87,7 @@ func TestEmptyGet(t *testing.T) { vals, err := client.Mget("a", "b") if err != nil { - t.Fatal(err.String()) + t.Fatal(err.Error()) } if vals[0] == nil || vals[1] != nil { t.Fatal("TestEmptyGet failed") @@ -102,9 +100,8 @@ func TestConcurrent(t *testing.T) { } } - func TestSet(t *testing.T) { - var err os.Error + var err error vals := []string{"a", "b", "c", "d", "e"} @@ -116,7 +113,7 @@ func TestSet(t *testing.T) { if members, err = client.Smembers("s"); err != nil || len(members) != 5 { if err != nil { - t.Fatal("Set setup failed", err.String()) + t.Fatal("Set setup failed", err.Error()) } else { t.Fatalf("Expected %d members but got %d", 5, len(members)) } @@ -136,7 +133,7 @@ func TestSet(t *testing.T) { if members, err = client.Smembers("s"); err != nil || len(members) != 0 { if err != nil { - t.Fatal("Set setup failed", err.String()) + t.Fatal("Set setup failed", err.Error()) } else { t.Fatalf("Expected %d members but got %d", 0, len(members)) } @@ -146,7 +143,6 @@ func TestSet(t *testing.T) { } - func TestList(t *testing.T) { //var err os.Error @@ -158,7 +154,7 @@ func TestList(t *testing.T) { if l, err := client.Llen("l"); err != nil || l != 5 { if err != nil { - t.Fatal("Llen failed", err.String()) + t.Fatal("Llen failed", err.Error()) } else { t.Fatal("Llen failed, list wrong length", l) } @@ -167,7 +163,7 @@ func TestList(t *testing.T) { for i := 0; i < len(vals); i++ { if val, err := client.Lindex("l", i); err != nil || string(val) != vals[i] { if err != nil { - t.Fatal("Lindex failed", err.String()) + t.Fatal("Lindex failed", err.Error()) } else { t.Fatalf("Expected %s but got %s", vals[i], string(val)) } @@ -176,14 +172,14 @@ func TestList(t *testing.T) { for i := 0; i < len(vals); i++ { if err := client.Lset("l", i, []byte("a")); err != nil { - t.Fatal("Lset failed", err.String()) + t.Fatal("Lset failed", err.Error()) } } for i := 0; i < len(vals); i++ { if val, err := client.Lindex("l", i); err != nil || string(val) != "a" { if err != nil { - t.Fatal("Lindex failed", err.String()) + t.Fatal("Lindex failed", err.Error()) } else { t.Fatalf("Expected %s but got %s", "a", string(val)) } @@ -198,12 +194,12 @@ func TestBrpop(t *testing.T) { go func() { time.Sleep(100 * 1000) if err := client.Lpush("l", []byte("a")); err != nil { - t.Fatal("Lpush failed", err.String()) + t.Fatal("Lpush failed", err.Error()) } }() key, value, err := client.Brpop([]string{"l"}, 1) if err != nil { - t.Fatal("Brpop failed", err.String()) + t.Fatal("Brpop failed", err.Error()) } if *key != "l" { t.Fatalf("Expected %s but got %s", "l", *key) @@ -217,12 +213,12 @@ func TestBlpop(t *testing.T) { go func() { time.Sleep(100 * 1000) if err := client.Lpush("l", []byte("a")); err != nil { - t.Fatal("Lpush failed", err.String()) + t.Fatal("Lpush failed", err.Error()) } }() key, value, err := client.Blpop([]string{"l"}, 1) if err != nil { - t.Fatal("Blpop failed", err.String()) + t.Fatal("Blpop failed", err.Error()) } if *key != "l" { t.Fatalf("Expected %s but got %s", "l", *key) @@ -235,7 +231,7 @@ func TestBlpop(t *testing.T) { func TestBrpopTimeout(t *testing.T) { key, value, err := client.Brpop([]string{"l"}, 1) if err != nil { - t.Fatal("BrpopTimeout failed", err.String()) + t.Fatal("BrpopTimeout failed", err.Error()) } if key != nil { t.Fatalf("Expected nil but got '%s'", *key) @@ -248,7 +244,7 @@ func TestBrpopTimeout(t *testing.T) { func TestBlpopTimeout(t *testing.T) { key, value, err := client.Blpop([]string{"l"}, 1) if err != nil { - t.Fatal("BlpopTimeout failed", err.String()) + t.Fatal("BlpopTimeout failed", err.Error()) } if key != nil { t.Fatalf("Expected nil but got '%s'", *key) @@ -257,6 +253,7 @@ func TestBlpopTimeout(t *testing.T) { t.Fatalf("Expected nil but got '%s'", value) } } + /* func TestSubscribe(t *testing.T) { @@ -450,10 +447,10 @@ func TestPSubscribe(t *testing.T) { func verifyHash(t *testing.T, key string, expected map[string][]byte) { //test Hget m1 := make(map[string][]byte) - for k, _ := range expected { + for k := range expected { actual, err := client.Hget(key, k) if err != nil { - t.Fatal("verifyHash Hget failed", err.String()) + t.Fatal("verifyHash Hget failed", err.Error()) } m1[k] = actual } @@ -464,7 +461,7 @@ func verifyHash(t *testing.T, key string, expected map[string][]byte) { //test Hkeys keys, err := client.Hkeys(key) if err != nil { - t.Fatal("verifyHash Hkeys failed", err.String()) + t.Fatal("verifyHash Hkeys failed", err.Error()) } if len(keys) != len(expected) { fmt.Printf("%v\n", keys) @@ -479,7 +476,7 @@ func verifyHash(t *testing.T, key string, expected map[string][]byte) { //test Hvals vals, err := client.Hvals(key) if err != nil { - t.Fatal("verifyHash Hvals failed", err.String()) + t.Fatal("verifyHash Hvals failed", err.Error()) } if len(vals) != len(expected) { t.Fatal("verifyHash Hvals failed") @@ -489,7 +486,7 @@ func verifyHash(t *testing.T, key string, expected map[string][]byte) { //test Hgetall err = client.Hgetall(key, m2) if err != nil { - t.Fatal("verifyHash Hgetall failed", err.String()) + t.Fatal("verifyHash Hgetall failed", err.Error()) } if !reflect.DeepEqual(m2, expected) { t.Fatal("verifyHash Hgetall failed") @@ -504,11 +501,11 @@ func TestSortedSet(t *testing.T) { vals[i] = []byte(svals[i]) _, err := client.Zadd("zs", vals[i], ranks[i]) if err != nil { - t.Fatal("zdd failed" + err.String()) + t.Fatal("zdd failed" + err.Error()) } score, err := client.Zscore("zs", vals[i]) if err != nil { - t.Fatal("zscore failed" + err.String()) + t.Fatal("zscore failed" + err.Error()) } if score != ranks[i] { t.Fatal("zscore failed") @@ -517,7 +514,7 @@ func TestSortedSet(t *testing.T) { card, err := client.Zcard("zs") if err != nil { - t.Fatal("zcard failed" + err.String()) + t.Fatal("zcard failed" + err.Error()) } if card != 5 { t.Fatal("zcard failed", card) @@ -540,7 +537,7 @@ func TestSortedSet(t *testing.T) { score, err := client.Zscore("zs", vals[i]) if err != nil { - t.Fatal("zscore failed" + err.String()) + t.Fatal("zscore failed" + err.Error()) } if score != ranks[i]+1 { t.Fatal("zscore failed") @@ -554,22 +551,22 @@ func TestSortedSet(t *testing.T) { //clean up _, err = client.Zrem("zs", []byte("a")) if err != nil { - t.Fatal("zrem failed" + err.String()) + t.Fatal("zrem failed" + err.Error()) } _, err = client.Zremrangebyrank("zs", 0, 1) if err != nil { - t.Fatal("zremrangebynrank failed" + err.String()) + t.Fatal("zremrangebynrank failed" + err.Error()) } _, err = client.Zremrangebyscore("zs", 3, 4) if err != nil { - t.Fatal("zremrangebyscore failed" + err.String()) + t.Fatal("zremrangebyscore failed" + err.Error()) } card, err = client.Zcard("zs") if err != nil { - t.Fatal("zcard failed" + err.String()) + t.Fatal("zcard failed" + err.Error()) } if card != 0 { t.Fatal("zcard failed", card) @@ -611,7 +608,7 @@ func TestHash(t *testing.T) { //test Hgetall err := client.Hgetall("h3", &test4) if err != nil { - t.Fatal("verifyHash Hgetall failed", err.String()) + t.Fatal("verifyHash Hgetall failed", err.Error()) } if !reflect.DeepEqual(test4, test3) { t.Fatal("verifyHash Hgetall failed") @@ -622,7 +619,7 @@ func TestHash(t *testing.T) { var test5 tt err = client.Hgetall("h3", &test5) if err != nil { - t.Fatal("verifyHash Hgetall failed", err.String()) + t.Fatal("verifyHash Hgetall failed", err.Error()) } if !reflect.DeepEqual(test5, test3) { t.Fatal("verifyHash Hgetall failed") @@ -643,7 +640,7 @@ func TestHash(t *testing.T) { test7 := make(map[string]interface{}) err = client.Hgetall("h4", &test7) if err != nil { - t.Fatal("verifyHash Hgetall failed", err.String()) + t.Fatal("verifyHash Hgetall failed", err.Error()) } if !reflect.DeepEqual(test6, test7) { t.Fatal("verifyHash Hgetall failed") @@ -665,9 +662,9 @@ func BenchmarkMultipleGet(b *testing.B) { func BenchmarkMGet(b *testing.B) { client.Set("bmg", []byte("hi")) - var vals vector.StringVector + var vals []string for i := 0; i < b.N; i++ { - vals.Push("bmg") + vals = append(vals, "bmg") } client.Mget(vals...) client.Del("bmg") @@ -720,9 +717,9 @@ func BenchmarkJsonMget(b *testing.B) { od, _ := json.Marshal(testObj) client.Set("tjs", od) - var vals vector.StringVector + var vals []string for i := 0; i < b.N; i++ { - vals.Push("tjs") + vals = append(vals, "tjs") } data, _ := client.Mget(vals...) diff --git a/redis-dump.go b/tools/redis-dump.go similarity index 100% rename from redis-dump.go rename to tools/redis-dump.go diff --git a/redis-load.go b/tools/redis-load.go similarity index 100% rename from redis-load.go rename to tools/redis-load.go