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 074336e..fcd857d 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) @@ -833,6 +847,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) @@ -889,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 3562e2a..425bd36 100644 --- a/redis.go +++ b/redis.go @@ -97,6 +97,10 @@ import ( "runtime"; ) +func Version() string { + return "0.3" +} + // Common interface supported by all clients // to consolidate common ops type RedisClient interface { @@ -291,12 +295,18 @@ 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) // 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) @@ -309,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 @@ -500,12 +513,18 @@ 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) // 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) @@ -537,7 +556,6 @@ type AsyncClient interface { // func init() { runtime.GOMAXPROCS(2); - flag.Parse(); } // redis:d diff --git a/specification.go b/specification.go index 250878f..b17848f 100644 --- a/specification.go +++ b/specification.go @@ -166,10 +166,12 @@ 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} 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 12f66e7..5ba47cd 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) @@ -854,6 +868,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) @@ -903,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.