Skip to content

Sorted Set Functionality #14

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: go1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ temp
*_obj
*.iml
*.goide
*.sw[po]
42 changes: 42 additions & 0 deletions asynchclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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{})
Expand Down
20 changes: 19 additions & 1 deletion redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)

Expand All @@ -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

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -537,7 +556,6 @@ type AsyncClient interface {
//
func init() {
runtime.GOMAXPROCS(2);
flag.Parse();
}

// redis:d
Expand Down
2 changes: 2 additions & 0 deletions specification.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
41 changes: 41 additions & 0 deletions synchclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down