添加redis scan方法

This commit is contained in:
lifeiyi
2020-04-21 18:25:59 +08:00
parent fb44986a31
commit eb92470865
2 changed files with 25 additions and 6 deletions

View File

@@ -73,8 +73,9 @@ func (slf *GateService) Test(){
} }
func (slf *GateService) TestRedis() { func (slf *GateService) TestRedis() {
slf.redisModule.GetHashValueByHashKeyList("BITGET_2160_LastSetLevelInfo", "SBTC_USD_1", "BTC_SUSDT_1", "SBTC_USD_3") //slf.redisModule.GetHashValueByHashKeyList("BITGET_2160_LastSetLevelInfo", "SBTC_USD_1", "BTC_SUSDT_1", "SBTC_USD_3")
//slf.redisModule.GetHashValueByKey("BITGET_2160_LastSetLevelInfo", "SBTC_USD_1") //slf.redisModule.GetHashValueByKey("BITGET_2160_LastSetLevelInfo", "SBTC_USD_1")
slf.redisModule.ScanMatchKeys(192, "ZC*", 100)
} }
func (slf *GateService) HttpTest(session *sysservice.HttpSession) { func (slf *GateService) HttpTest(session *sysservice.HttpSession) {

View File

@@ -6,6 +6,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"github.com/duanhf2012/origin/log" "github.com/duanhf2012/origin/log"
"strconv"
"time" "time"
"github.com/duanhf2012/origin/service" "github.com/duanhf2012/origin/service"
@@ -760,21 +761,38 @@ func (slf *RedisModule) GetHashValueByHashKeyList(fieldKey ...interface{}) ([]st
return retList, nil return retList, nil
} }
/*func (slf *RedisModule) ScanMatchKeys(cursorValue int, redisKey string, count int) ([]string, error) { func (slf *RedisModule) ScanMatchKeys(cursorValue int, redisKey string, count int) (int, []string, error) {
retKeys := []string{} retKeys := []string{}
nextCursorValue := 0
if redisKey == "" { if redisKey == "" {
log.Error("ScanMatchKeys key is empty!") log.Error("ScanMatchKeys key is empty!")
return nil, errors.New("Key Is Empty") return nextCursorValue, nil, errors.New("Key Is Empty")
} }
conn, err := slf.getConn() conn, err := slf.getConn()
if err != nil { if err != nil {
return nil, err return nextCursorValue, nil, err
} }
defer conn.Close() defer conn.Close()
return retKeys, nil value, err := conn.Do("SCAN", cursorValue, "match", redisKey, "count", count)
}*/ if err != nil {
log.Error("GetHashValueByKey fail,reason:%v", err)
return nextCursorValue, nil, err
}
if value == nil {
return nextCursorValue, nil, errors.New("Reids Get Hash nil")
}
valueList := value.([]interface{})
nextCursorValue, _ = strconv.Atoi(string(valueList[0].([]byte)))
keysList := valueList[1].([]interface{})
for _, keysItem := range keysList {
retKeys = append(retKeys, string(keysItem.([]byte)))
}
return nextCursorValue, retKeys, nil
}
//SetRedisHashJSON ... //SetRedisHashJSON ...
func (slf *RedisModule) SetHashJSON(redisKey, hsahKey string, value interface{}) error { func (slf *RedisModule) SetHashJSON(redisKey, hsahKey string, value interface{}) error {