Commit a457569b by xuzhenhao

增加了redis工具库中的方法

1 parent ee03c575
...@@ -463,7 +463,7 @@ func IceGameTopRedisGetSingleUserRangeRankInfo(uid string, gtid string, gid stri ...@@ -463,7 +463,7 @@ func IceGameTopRedisGetSingleUserRangeRankInfo(uid string, gtid string, gid stri
} else if sorceorder == "0" { } else if sorceorder == "0" {
if nextrankIndex != 0 { if nextrankIndex != 0 {
strList1, err = RedisZRangeByScore(redisConn, "sortset:gtid:"+gtid+":gid:"+gid+":toptype:"+toptype, score, "+inf", "true", 0, prerankIndex) strList1, err = RedisZRangeByScore(redisConn, "sortset:gtid:"+gtid+":gid:"+gid+":toptype:"+toptype, scoreString, "+inf", "true", 0, prerankIndex)
//将结果倒序 //将结果倒序
var tempList []string var tempList []string
for i := len(strList1); i < 0; i -= 2 { for i := len(strList1); i < 0; i -= 2 {
...@@ -473,7 +473,7 @@ func IceGameTopRedisGetSingleUserRangeRankInfo(uid string, gtid string, gid stri ...@@ -473,7 +473,7 @@ func IceGameTopRedisGetSingleUserRangeRankInfo(uid string, gtid string, gid stri
strList1 = tempList strList1 = tempList
} }
if prerankIndex != 0 { if prerankIndex != 0 {
strList2, err = RedisZRevRangeByScore(redisConn, "sortset:gtid:"+gtid+":gid:"+gid+":toptype:"+toptype, score, "-inf", "true", 0, nextrankIndex) strList2, err = RedisZRevRangeByScore(redisConn, "sortset:gtid:"+gtid+":gid:"+gid+":toptype:"+toptype, scoreString, "-inf", "true", 0, nextrankIndex)
} }
if len(strList1) == 0 { if len(strList1) == 0 {
...@@ -603,8 +603,7 @@ func GetSingleUserRank(key string, member string) (rankIndex interface{}, err er ...@@ -603,8 +603,7 @@ func GetSingleUserRank(key string, member string) (rankIndex interface{}, err er
defer RedisClose(redisConn) defer RedisClose(redisConn)
rank, err := RedisZRank(redisConn, key, member) rank, err := RedisZRank(redisConn, key, member)
if err != nil { if err != nil {
resIndex = "105202" return "105202", err
return resIndex, err
} }
if rank == nil { if rank == nil {
err = errors.New("用户未提交分数") err = errors.New("用户未提交分数")
...@@ -613,4 +612,5 @@ func GetSingleUserRank(key string, member string) (rankIndex interface{}, err er ...@@ -613,4 +612,5 @@ func GetSingleUserRank(key string, member string) (rankIndex interface{}, err er
log.Println("key:", key) log.Println("key:", key)
log.Println("rank:", rank) log.Println("rank:", rank)
rankIndex = int(rank.(int64)) rankIndex = int(rank.(int64))
return rankIndex, nil
} }
...@@ -227,7 +227,7 @@ func RedisZRank(conn redis.Conn, key string, member string) (reply interface{}, ...@@ -227,7 +227,7 @@ func RedisZRank(conn redis.Conn, key string, member string) (reply interface{},
/* /*
* zrangebyscore * zrangebyscore
*/ */
func RedisZRangeByScore(conn redis.Conn, key string, startScore string, endScore string, limit string, limitStart int, limitEnd int) (reply interface{}, err error) { func RedisZRangeByScore(conn redis.Conn, key string, startScore string, endScore string, limit string, limitStart int, limitEnd int) (reply []string, err error) {
if limit == "true" { if limit == "true" {
return RedisCommand(conn, "zrangebyscore", key, startScore, endScore, "withscore", "limit", limitStart, limitEnd) return RedisCommand(conn, "zrangebyscore", key, startScore, endScore, "withscore", "limit", limitStart, limitEnd)
} }
...@@ -237,7 +237,7 @@ func RedisZRangeByScore(conn redis.Conn, key string, startScore string, endScore ...@@ -237,7 +237,7 @@ func RedisZRangeByScore(conn redis.Conn, key string, startScore string, endScore
/* /*
* zrevrangebyscore * zrevrangebyscore
*/ */
func RedisZRevRangeByScore(conn redis.Conn, key string, startScore string, endScore string, limit string, limitStart int, limitEnd int) (reply interface{}, err error) { func RedisZRevRangeByScore(conn redis.Conn, key string, startScore string, endScore string, limit string, limitStart int, limitEnd int) (reply []string, err error) {
if limit == "true" { if limit == "true" {
return RedisCommand(conn, "zrevrangebyscore", key, startScore, endScore, "withscore", "limit", limitStart, limitEnd) return RedisCommand(conn, "zrevrangebyscore", key, startScore, endScore, "withscore", "limit", limitStart, limitEnd)
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!