mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-19 02:44:42 +08:00
Merge pull request #9 from vipally/master
fix list reply unmarshal error
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package sysmodule
|
package sysmodule
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -1128,6 +1129,7 @@ func (slf *RedisModule) ZRangeJSON(key string, start, stop int, ascend bool, dat
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = json.Unmarshal(b, data)
|
err = json.Unmarshal(b, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -1150,7 +1152,21 @@ func (slf *RedisModule) ZRange(key string, start, stop int, ascend bool) ([]byte
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return redis.Bytes(reply, err)
|
return makeListJson(reply.([]interface{})), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
//["123","234"]
|
||||||
|
func makeListJson(redisReply []interface{}) []byte {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
buf.WriteString("[")
|
||||||
|
for i, v := range redisReply {
|
||||||
|
if i > 0 {
|
||||||
|
buf.WriteString(",")
|
||||||
|
}
|
||||||
|
buf.WriteString(fmt.Sprintf("%s", v))
|
||||||
|
}
|
||||||
|
buf.WriteString("]")
|
||||||
|
return buf.Bytes()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (slf *RedisModule) ZRangeByScoreJSON(key string, start, stop int, ascend bool, data interface{}) error {
|
func (slf *RedisModule) ZRangeByScoreJSON(key string, start, stop int, ascend bool, data interface{}) error {
|
||||||
@@ -1179,7 +1195,7 @@ func (slf *RedisModule) ZRangeByScore(key string, start, stop int, ascend bool)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return redis.Bytes(reply, err)
|
return makeListJson(reply.([]interface{})), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (slf *RedisModule) ZREMRANGEBYSCORE(key string, start, stop interface{}) error {
|
func (slf *RedisModule) ZREMRANGEBYSCORE(key string, start, stop interface{}) error {
|
||||||
@@ -1219,5 +1235,5 @@ func (slf *RedisModule) LRange(key string, start, stop int) ([]byte, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return redis.Bytes(reply, err)
|
return makeListJson(reply.([]interface{})), nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user