From bfd8631de8505fd964213fcf84d6c0755dbbd303 Mon Sep 17 00:00:00 2001 From: Micha Gorelick Date: Tue, 19 Jun 2012 13:31:53 -0400 Subject: [PATCH 1/5] Added ZRevrangeWithScores This was out of necessity, but thought should be given for allowing optional arguments to be sent to redis. --- asynchclient.go | 14 ++++++++++++++ redis.go | 3 +++ synchclient.go | 14 ++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/asynchclient.go b/asynchclient.go index 074336e..d504611 100644 --- a/asynchclient.go +++ b/asynchclient.go @@ -833,6 +833,20 @@ func (c *asyncClient) Zrevrange(arg0 string, arg1 int64, arg2 int64) (result Fut } +func (c *asyncClient) ZrevrangeWithScores(arg0 string, arg1 int64, arg2 int64) (result FutureBytesArray, err Error) { + arg0bytes := []byte(arg0) + arg1bytes := []byte(fmt.Sprintf("%d", arg1)) + arg2bytes := []byte(fmt.Sprintf("%d", arg2)) + + var resp *PendingResponse + resp, err = c.conn.QueueRequest(&ZREVRANGE, [][]byte{arg0bytes, arg1bytes, arg2bytes, []byte("WITHSCORES")}) + if err == nil { + result = resp.future.(FutureBytesArray) + } + return result, err + +} + // Redis ZRANGEBYSCORE command. func (c *asyncClient) Zrangebyscore(arg0 string, arg1 float64, arg2 float64) (result FutureBytesArray, err Error) { arg0bytes := []byte(arg0) diff --git a/redis.go b/redis.go index 3562e2a..f915496 100644 --- a/redis.go +++ b/redis.go @@ -297,6 +297,9 @@ type Client interface { // Redis ZREVRANGE command. Zrevrange(key string, arg1 int64, arg2 int64) (result [][]byte, err Error) + // Redis ZREVRANGE command. + ZrevrangeWithScores(key string, arg1 int64, arg2 int64) (result [][]byte, err Error) + // Redis ZRANGEBYSCORE command. Zrangebyscore(key string, arg1 float64, arg2 float64) (result [][]byte, err Error) diff --git a/synchclient.go b/synchclient.go index 12f66e7..38f58c7 100644 --- a/synchclient.go +++ b/synchclient.go @@ -854,6 +854,20 @@ func (c *syncClient) Zrevrange(arg0 string, arg1 int64, arg2 int64) (result [][] } +func (c *syncClient) ZrevrangeWithScores(arg0 string, arg1 int64, arg2 int64) (result [][]byte, err Error) { + arg0bytes := []byte(arg0) + arg1bytes := []byte(fmt.Sprintf("%d", arg1)) + arg2bytes := []byte(fmt.Sprintf("%d", arg2)) + + var resp Response + resp, err = c.conn.ServiceRequest(&ZREVRANGE, [][]byte{arg0bytes, arg1bytes, arg2bytes, []byte("WITHSCORES")}) + if err == nil { + result = resp.GetMultiBulkData() + } + return result, err + +} + // Redis ZRANGEBYSCORE command. func (c *syncClient) Zrangebyscore(arg0 string, arg1 float64, arg2 float64) (result [][]byte, err Error) { arg0bytes := []byte(arg0) From a766bc7d0fa8efbf46a4f95089917ddb11d330ea Mon Sep 17 00:00:00 2001 From: Micha Gorelick Date: Tue, 19 Jun 2012 15:30:34 -0400 Subject: [PATCH 2/5] Added Zincrby in synch and asynch clients --- asynchclient.go | 14 ++++++++++++++ redis.go | 6 ++++++ specification.go | 1 + synchclient.go | 14 ++++++++++++++ 4 files changed, 35 insertions(+) diff --git a/asynchclient.go b/asynchclient.go index d504611..6b067bf 100644 --- a/asynchclient.go +++ b/asynchclient.go @@ -803,6 +803,20 @@ func (c *asyncClient) Zscore(arg0 string, arg1 []byte) (result FutureFloat64, er } +// Redis ZINCRBY command. +func (c *asyncClient) Zincrby(arg0 string, arg1 float64, arg2 []byte) (result FutureFloat64, err Error) { + arg0bytes := []byte(arg0) + arg1bytes := []byte(fmt.Sprintf("%e", arg1)) + + var resp *PendingResponse + resp, err = c.conn.QueueRequest(&ZINCRBY, [][]byte{arg0bytes, arg1bytes, arg2}) + if err == nil { + result = newFutureFloat64(resp.future.(FutureBytes)) + } + return result, err + +} + // Redis ZRANGE command. func (c *asyncClient) Zrange(arg0 string, arg1 int64, arg2 int64) (result FutureBytesArray, err Error) { arg0bytes := []byte(arg0) diff --git a/redis.go b/redis.go index f915496..3b79963 100644 --- a/redis.go +++ b/redis.go @@ -291,6 +291,9 @@ type Client interface { // Redis ZSCORE command. Zscore(key string, arg1 []byte) (result float64, err Error) + // Redis ZINCRBY command. + Zincrby(key string, arg1 float64, arg2 []byte) (result int64, err Error) + // Redis ZRANGE command. Zrange(key string, arg1 int64, arg2 int64) (result [][]byte, err Error) @@ -503,6 +506,9 @@ type AsyncClient interface { // Redis ZSCORE command. Zscore(key string, arg1 []byte) (result FutureFloat64, err Error) + // Redis ZINCRBY command. + Zincrby(key string, arg1 float64, arg2 []byte) (result FutureFloat64, err Error) + // Redis ZRANGE command. Zrange(key string, arg1 int64, arg2 int64) (result FutureBytesArray, err Error) diff --git a/specification.go b/specification.go index 250878f..9ae77be 100644 --- a/specification.go +++ b/specification.go @@ -170,6 +170,7 @@ var ( ZREM Command = Command{"ZREM", KEY_VALUE, BOOLEAN} ZCARD Command = Command{"ZCARD", KEY, NUMBER} ZSCORE Command = Command{"ZSCORE", KEY_VALUE, BULK} + ZINCRBY Command = Command{"ZINCRBY", KEY_IDX_VALUE, BULK} ZRANGE Command = Command{"ZRANGE", KEY_NUM_NUM, MULTI_BULK} ZREVRANGE Command = Command{"ZREVRANGE", KEY_NUM_NUM, MULTI_BULK} ZRANGEBYSCORE Command = Command{"ZRANGEBYSCORE", KEY_NUM_NUM, MULTI_BULK} diff --git a/synchclient.go b/synchclient.go index 38f58c7..3d52c37 100644 --- a/synchclient.go +++ b/synchclient.go @@ -824,6 +824,20 @@ func Btof64(buff []byte) (num float64, e Error) { return } +// Redis ZINCRBY command. +func (c *syncClient) Zincrby(arg0 string, arg1 float64, arg2 []byte) (result int64, err Error) { + arg0bytes := []byte(arg0) + arg1bytes := []byte(fmt.Sprintf("%e", arg1)) + + var resp Response + resp, err = c.conn.ServiceRequest(&ZINCRBY, [][]byte{arg0bytes, arg1bytes, arg2}) + if err == nil { + result = resp.GetNumberValue() + } + return result, err + +} + // Redis ZRANGE command. func (c *syncClient) Zrange(arg0 string, arg1 int64, arg2 int64) (result [][]byte, err Error) { arg0bytes := []byte(arg0) From 8d4e243cd66c0843e4d13ad9199fc02b6c20e58f Mon Sep 17 00:00:00 2001 From: Micha Gorelick Date: Wed, 20 Jun 2012 12:18:51 -0400 Subject: [PATCH 3/5] Fixed flag clobbering Took out the flag parsing so that redis doesn't clobber user defined flags. This is under the philosophy that the redis debug flag will only exist if the user calls flag.Parse(), otherwise the user won't expect their program to accept flags. --- redis.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/redis.go b/redis.go index 3b79963..ec519e4 100644 --- a/redis.go +++ b/redis.go @@ -515,6 +515,9 @@ type AsyncClient interface { // Redis ZREVRANGE command. Zrevrange(key string, arg1 int64, arg2 int64) (result FutureBytesArray, err Error) + // Redis ZREVRANGE command. + ZrevrangeWithScores(key string, arg1 int64, arg2 int64) (result FutureBytesArray, err Error) + // Redis ZRANGEBYSCORE command. Zrangebyscore(key string, arg1 float64, arg2 float64) (result FutureBytesArray, err Error) @@ -546,7 +549,6 @@ type AsyncClient interface { // func init() { runtime.GOMAXPROCS(2); - flag.Parse(); } // redis:d From 064e8e72d0b20051410ede0efdd841e08126881a Mon Sep 17 00:00:00 2001 From: Micha Gorelick Date: Wed, 20 Jun 2012 13:15:00 -0400 Subject: [PATCH 4/5] Added Version() for version control --- redis.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/redis.go b/redis.go index ec519e4..246836d 100644 --- a/redis.go +++ b/redis.go @@ -97,6 +97,10 @@ import ( "runtime"; ) +func Version() string { + return "0.2" +} + // Common interface supported by all clients // to consolidate common ops type RedisClient interface { From 4605185a279673c0877c778d23ba85babf7afd3d Mon Sep 17 00:00:00 2001 From: Micha Gorelick Date: Tue, 24 Jul 2012 11:07:46 -0400 Subject: [PATCH 5/5] Added Hincrby command --- .gitignore | 1 + asynchclient.go | 14 ++++++++++++++ redis.go | 5 ++++- specification.go | 1 + synchclient.go | 13 +++++++++++++ 5 files changed, 33 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index bffb011..acfb0e3 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ temp *_obj *.iml *.goide +*.sw[po] diff --git a/asynchclient.go b/asynchclient.go index 6b067bf..fcd857d 100644 --- a/asynchclient.go +++ b/asynchclient.go @@ -917,6 +917,20 @@ func (c *asyncClient) Hgetall(arg0 string) (result FutureBytes, err Error) { } +// Redis HINCRBY command. +func (c *asyncClient) Hincrby(arg0 string, arg1 string, arg2 int64) (result FutureInt64, err Error) { + arg0bytes := []byte(arg0) + arg1bytes := []byte(arg1) + arg2bytes := []byte(fmt.Sprintf("%d", arg2)) + + var resp *PendingResponse + resp, err = c.conn.QueueRequest(&HINCRBY, [][]byte{arg0bytes, arg1bytes, arg2bytes}) + if err == nil { + result = resp.future.(FutureInt64) + } + return result, err +} + // Redis FLUSHDB command. func (c *asyncClient) Flushdb() (stat FutureBool, err Error) { resp, err := c.conn.QueueRequest(&FLUSHDB, [][]byte{}) diff --git a/redis.go b/redis.go index 246836d..425bd36 100644 --- a/redis.go +++ b/redis.go @@ -98,7 +98,7 @@ import ( ) func Version() string { - return "0.2" + return "0.3" } // Common interface supported by all clients @@ -319,6 +319,9 @@ type Client interface { // Redis HGETALL command. Hgetall(key string) (result [][]byte, err Error) + // Redis HINCRBY command. + Hincrby(key string, hashkey string, arg1 int64) (result int64, err Error) + // Redis FLUSHDB command. Flushdb() Error diff --git a/specification.go b/specification.go index 9ae77be..b17848f 100644 --- a/specification.go +++ b/specification.go @@ -166,6 +166,7 @@ var ( HGET Command = Command{"HGET", KEY_KEY, BULK} HSET Command = Command{"HSET", KEY_KEY_VALUE, STATUS} HGETALL Command = Command{"HGETALL", KEY, MULTI_BULK} + HINCRBY Command = Command{"HINCRBY", KEY_KEY_VALUE, NUMBER} ZADD Command = Command{"ZADD", KEY_IDX_VALUE, BOOLEAN} ZREM Command = Command{"ZREM", KEY_VALUE, BOOLEAN} ZCARD Command = Command{"ZCARD", KEY, NUMBER} diff --git a/synchclient.go b/synchclient.go index 3d52c37..5ba47cd 100644 --- a/synchclient.go +++ b/synchclient.go @@ -931,7 +931,20 @@ func (c *syncClient) Hgetall(arg0 string) (result [][]byte, err Error) { result = resp.GetMultiBulkData() } return result, err +} +// Redis HINCRBY command. +func (c *syncClient) Hincrby(arg0 string, arg1 string, arg2 int64) (result int64, err Error) { + arg0bytes := []byte(arg0) + arg1bytes := []byte(arg1) + arg2bytes := []byte(fmt.Sprintf("%d", arg2)) + + var resp Response + resp, err = c.conn.ServiceRequest(&HINCRBY, [][]byte{arg0bytes, arg1bytes, arg2bytes}) + if err == nil { + result = resp.GetNumberValue() + } + return result, err } // Redis FLUSHDB command.