Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
xuzhenhao
/
rlw-dev
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit a068eb5a
authored
Dec 09, 2017
by
xuzhenhao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加了返回个人排行信息的时候可以看到前后玩家信息的功能
1 parent
6e3f6187
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
73 additions
and
33 deletions
ranklist/ranklist.go
sdkredis/ice_gametopREDIS.go
sdkredis/redisCommon.go
ranklist/ranklist.go
View file @
a068eb5
...
...
@@ -137,10 +137,11 @@ func SingleRank(c *gin.Context) {
gtid
:=
c
.
Query
(
"gtid"
)
gid
:=
c
.
Query
(
"gid"
)
toptype
:=
c
.
Query
(
"toptype"
)
prerank
:=
c
.
Query
(
"prerank"
)
nextrank
:=
c
.
Query
(
"nextrank"
)
log
.
Printf
(
"SingleRank uid[%s] gtid[%s] gid[%s] toptype[%s] prerank[%s] nextrank[%s]
\n
"
,
uid
,
gtid
,
gid
,
toptype
,
prerank
,
nextrank
)
log
.
Printf
(
"SingleRank uid[%s] gtid[%s] gid[%s] toptype[%s]
\n
"
,
uid
,
gtid
,
gid
,
toptype
)
igt
:=
sdkredis
.
IceGameTopRedisGetSingleUserRankInfo
(
uid
,
gtid
,
gid
,
toptype
)
igt
:=
sdkredis
.
IceGameTopRedisGetSingleUserRankInfo
(
uid
,
gtid
,
gid
,
toptype
,
prerank
,
nextrank
)
fmt
.
Println
(
igt
)
msg
:=
new
(
Msg
)
if
igt
==
nil
{
...
...
sdkredis/ice_gametopREDIS.go
View file @
a068eb5
...
...
@@ -269,7 +269,7 @@ func IceGametopRedisSubmitScore(uid string, gtid string, gid string, score strin
/**
* 获取单个用户的排名信息
*/
func
IceGameTopRedisGetSingleUserRankInfo
(
uid
string
,
gtid
string
,
gid
string
,
toptype
string
)
(
igt
*
IGT
)
{
func
IceGameTopRedisGetSingleUserRankInfo
(
uid
string
,
gtid
string
,
gid
string
,
toptype
string
,
prerank
string
,
nextrank
string
)
(
igt
*
IGT
)
{
// 连接redis
redisConn
:=
RedisClient
.
GetConn
()
defer
RedisClose
(
redisConn
)
...
...
@@ -289,15 +289,49 @@ func IceGameTopRedisGetSingleUserRankInfo(uid string, gtid string, gid string, t
}
else
{
return
}
// 获取当前用户排名
rank
,
err
:=
RedisZRank
(
redisConn
,
"sortset:gtid:"
+
gtid
+
":gid:"
+
gid
+
":toptype:"
+
toptype
,
member
)
if
err
!=
nil
{
log
.
Println
(
"RedisZRANK err[%v]"
,
err
)
return
}
rankIndex
:=
rank
.
(
int
)
// 获取当前用户前x位和后x位的排名数据
var
prerankIndex
int
var
nextrankIndex
int
if
prerank
==
""
{
prerankIndex
=
1
}
else
{
prerankIndex
,
err
=
strconv
.
Atoi
(
prerank
)
if
err
!=
nil
{
log
.
Println
(
"String to Int err: "
,
err
)
return
}
}
if
nextrank
==
""
{
nextrankIndex
=
1
}
else
{
nextrankIndex
,
err
=
strconv
.
Atoi
(
nextrank
)
if
err
!=
nil
{
log
.
Println
(
"String to Int err: "
,
err
)
return
}
}
if
rankIndex
-
prerankIndex
<
0
{
prerankIndex
=
0
}
else
{
prerankIndex
=
rankIndex
-
prerankIndex
}
nextrankIndex
=
rankIndex
+
nextrankIndex
// 排序
var
strList
[]
string
var
sorterr
error
if
sorceorder
==
"0"
{
strList
,
sorterr
=
RedisSort
(
redisConn
,
"sortset:gtid:"
+
gtid
+
":gid:"
+
gid
+
":toptype:"
+
toptype
,
0
,
-
1
)
strList
,
sorterr
=
RedisSort
(
redisConn
,
"sortset:gtid:"
+
gtid
+
":gid:"
+
gid
+
":toptype:"
+
toptype
,
prerankIndex
,
nextrankIndex
)
}
else
if
sorceorder
==
"1"
{
strList
,
sorterr
=
RedisReverseSort
(
redisConn
,
"sortset:gtid:"
+
gtid
+
":gid:"
+
gid
+
":toptype:"
+
toptype
,
0
,
-
1
)
strList
,
sorterr
=
RedisReverseSort
(
redisConn
,
"sortset:gtid:"
+
gtid
+
":gid:"
+
gid
+
":toptype:"
+
toptype
,
prerankIndex
,
nextrankIndex
)
}
if
sorterr
!=
nil
{
log
.
Println
(
"RedisSort err[%v]"
,
sorterr
)
...
...
@@ -319,34 +353,32 @@ func IceGameTopRedisGetSingleUserRankInfo(uid string, gtid string, gid string, t
endIndex
:=
strings
.
Index
(
strList
[
i
],
":gtid"
)
currUID
:=
common
.
Substr2
(
strList
[
i
],
startIndex
,
endIndex
)
if
currUID
==
uid
{
igt
.
UID
=
uid
igt
.
RankIndex
=
index
igt
.
MyKey
=
strList
[
i
+
1
]
//查询储存昵称以及头像url的redis
var
err
error
resultstr
,
err
=
RedisGetKV
(
redisConn
,
"GUID:"
+
igt
.
UID
)
if
err
!=
nil
{
log
.
Println
(
"get redis err:"
,
err
)
}
r
,
err
:=
regexp
.
Compile
(
`\|([^\|])*\|`
)
if
err
!=
nil
{
log
.
Println
(
"err:"
,
err
)
}
// 使用正则匹配需要的值
result
:=
r
.
FindAllString
(
resultstr
,
valuecount
)
//去除用来匹配的特殊字符“|“
if
result
!=
nil
{
for
key
,
value
:=
range
result
{
value
=
value
[
1
:
len
(
value
)
-
1
]
log
.
Println
(
value
)
result
[
key
]
=
value
}
//result 为切片,储存了所有匹配到的特定值
igt
.
NickName
=
result
[
0
]
//第一个为昵称
igt
.
HeadPortraitURL
=
result
[
1
]
//第二个为头像url
igt
.
UID
=
uid
igt
.
RankIndex
=
index
igt
.
MyKey
=
strList
[
i
+
1
]
//查询储存昵称以及头像url的redis
var
err
error
resultstr
,
err
=
RedisGetKV
(
redisConn
,
"GUID:"
+
igt
.
UID
)
if
err
!=
nil
{
log
.
Println
(
"get redis err:"
,
err
)
}
r
,
err
:=
regexp
.
Compile
(
`\|([^\|])*\|`
)
if
err
!=
nil
{
log
.
Println
(
"err:"
,
err
)
}
// 使用正则匹配需要的值
result
:=
r
.
FindAllString
(
resultstr
,
valuecount
)
//去除用来匹配的特殊字符“|“
if
result
!=
nil
{
for
key
,
value
:=
range
result
{
value
=
value
[
1
:
len
(
value
)
-
1
]
log
.
Println
(
value
)
result
[
key
]
=
value
}
//result 为切片,储存了所有匹配到的特定值
igt
.
NickName
=
result
[
0
]
//第一个为昵称
igt
.
HeadPortraitURL
=
result
[
1
]
//第二个为头像url
}
index
++
...
...
sdkredis/redisCommon.go
View file @
a068eb5
...
...
@@ -216,3 +216,10 @@ func RedisIncrBy(conn redis.Conn, key string, num int64) (reply interface{}, err
return
}
/*
* zrank
*/
func
RedisZRank
(
conn
redis
.
Conn
,
key
string
,
member
string
)
(
reply
interface
{},
err
error
)
{
return
RedisCommand
(
conn
,
"zrank"
,
key
,
member
)
}
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment