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 e298655b
authored
Dec 12, 2017
by
xuzhenhao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加了相应的错误返回
1 parent
ac48ee16
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
24 deletions
ranklist/ranklist.go
sdkredis/ice_gametopREDIS.go
ranklist/ranklist.go
View file @
e298655
...
...
@@ -173,17 +173,17 @@ func SingleRangeRank(c *gin.Context) {
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
)
igt
,
resIndex
:=
sdkredis
.
IceGameTopRedisGetSingleUserRangeRankInfo
(
uid
,
gtid
,
gid
,
toptype
,
prerank
,
nextrank
)
igt
,
resIndex
,
err
:=
sdkredis
.
IceGameTopRedisGetSingleUserRangeRankInfo
(
uid
,
gtid
,
gid
,
toptype
,
prerank
,
nextrank
)
fmt
.
Println
(
igt
)
infoList
:=
make
(
map
[
string
]
interface
{},
0
)
infoList
[
"info_list"
]
=
igt
infoList
[
"user_index"
]
=
resIndex
msg
:=
new
(
Msg
)
if
igt
=
=
nil
{
err
:=
errors
.
New
(
"gametop name or game name not exist"
)
if
err
!
=
nil
{
log
.
Println
(
err
)
msg
.
ErrMsg
=
err
.
Error
()
msg
.
ErrCode
=
"105101"
msg
.
ErrCode
=
resIndex
.
(
string
)
}
else
{
infoList
[
"info_list"
]
=
igt
infoList
[
"user_index"
]
=
resIndex
.
(
int
)
msg
.
ErrCode
=
"0"
msg
.
ErrMsg
=
"success"
msg
.
Obj
=
infoList
...
...
sdkredis/ice_gametopREDIS.go
View file @
e298655
...
...
@@ -360,7 +360,7 @@ func IceGameTopRedisGetSingleUserRankInfo(uid string, gtid string, gid string, t
/**
* 获取单个用户以及前后用户的排名信息
*/
func
IceGameTopRedisGetSingleUserRangeRankInfo
(
uid
string
,
gtid
string
,
gid
string
,
toptype
string
,
prerank
string
,
nextrank
string
)
(
res
*
[]
IGT
,
resIndex
int
)
{
func
IceGameTopRedisGetSingleUserRangeRankInfo
(
uid
string
,
gtid
string
,
gid
string
,
toptype
string
,
prerank
string
,
nextrank
string
)
(
res
*
[]
IGT
,
resIndex
int
erface
{},
err
error
)
{
// 连接redis
redisConn
:=
RedisClient
.
GetConn
()
defer
RedisClose
(
redisConn
)
...
...
@@ -377,16 +377,18 @@ func IceGameTopRedisGetSingleUserRangeRankInfo(uid string, gtid string, gid stri
return
}
}
else
{
resIndex
=
"105207"
return
}
// 获取当前用户排名
rank
,
err
:=
RedisZRank
(
redisConn
,
"sortset:gtid:"
+
gtid
+
":gid:"
+
gid
+
":toptype:"
+
toptype
,
"ice_gametop:uid:"
+
uid
+
":gtid:"
+
gtid
+
":gid:"
+
gid
+
":toptype:"
+
toptype
+
":mykey"
)
if
err
!=
nil
{
log
.
Println
(
"RedisZRANK err[%v]"
,
err
)
resIndex
=
"105202"
return
}
if
rank
==
nil
{
return
nil
,
0
err
=
errors
.
New
(
"用户未提交分数"
)
return
nil
,
"105201"
,
err
}
rankIndex
:=
int
(
rank
.
(
int64
))
...
...
@@ -398,7 +400,7 @@ func IceGameTopRedisGetSingleUserRangeRankInfo(uid string, gtid string, gid stri
}
else
{
prerankIndex
,
err
=
strconv
.
Atoi
(
prerank
)
if
err
!=
nil
{
log
.
Println
(
"String to Int err: "
,
err
)
resIndex
=
"105200"
return
}
}
...
...
@@ -407,7 +409,7 @@ func IceGameTopRedisGetSingleUserRangeRankInfo(uid string, gtid string, gid stri
}
else
{
nextrankIndex
,
err
=
strconv
.
Atoi
(
nextrank
)
if
err
!=
nil
{
log
.
Println
(
"String to Int err: "
,
err
)
resIndex
=
"105200"
return
}
}
...
...
@@ -420,18 +422,18 @@ func IceGameTopRedisGetSingleUserRangeRankInfo(uid string, gtid string, gid stri
// 排序
var
strList
[]
string
var
sorterr
error
if
sorceorder
==
"0"
{
strList
,
sort
err
=
RedisSort
(
redisConn
,
"sortset:gtid:"
+
gtid
+
":gid:"
+
gid
+
":toptype:"
+
toptype
,
prerankIndex
,
nextrankIndex
)
strList
,
err
=
RedisSort
(
redisConn
,
"sortset:gtid:"
+
gtid
+
":gid:"
+
gid
+
":toptype:"
+
toptype
,
prerankIndex
,
nextrankIndex
)
}
else
if
sorceorder
==
"1"
{
strList
,
sort
err
=
RedisReverseSort
(
redisConn
,
"sortset:gtid:"
+
gtid
+
":gid:"
+
gid
+
":toptype:"
+
toptype
,
prerankIndex
,
nextrankIndex
)
strList
,
err
=
RedisReverseSort
(
redisConn
,
"sortset:gtid:"
+
gtid
+
":gid:"
+
gid
+
":toptype:"
+
toptype
,
prerankIndex
,
nextrankIndex
)
}
if
sorterr
!=
nil
{
log
.
Println
(
"RedisSort err[%v]"
,
sorterr
)
if
err
!=
nil
{
resIndex
=
"105203"
log
.
Println
(
"RedisSort err"
)
return
}
else
if
len
(
strList
)
==
0
{
log
.
Println
(
"rank has no data"
)
err
=
errors
.
New
(
"rank has no data"
)
resIndex
=
"105204"
}
igt
:=
make
([]
IGT
,
len
(
strList
)
/
2
)
...
...
@@ -442,7 +444,8 @@ func IceGameTopRedisGetSingleUserRangeRankInfo(uid string, gtid string, gid stri
var
valuecount
=
2
_
,
err
=
RedisDBSelect
(
redisConn
,
4
)
if
err
!=
nil
{
log
.
Printf
(
"select db err:"
,
err
)
resIndex
=
"105205"
log
.
Printf
(
"select db err"
)
}
for
i
:=
0
;
i
<
len
(
strList
);
i
+=
2
{
startIndex
:=
strings
.
Index
(
strList
[
i
],
"uid:"
)
+
4
...
...
@@ -454,7 +457,6 @@ func IceGameTopRedisGetSingleUserRangeRankInfo(uid string, gtid string, gid stri
}
else
{
s
=
i
/
2
}
log
.
Println
(
"s:"
,
s
,
"i:"
,
i
)
if
prerankIndex
+
index
-
1
==
rankIndex
{
resIndex
=
prerankIndex
+
index
}
...
...
@@ -462,14 +464,13 @@ func IceGameTopRedisGetSingleUserRangeRankInfo(uid string, gtid string, gid stri
igt
[
s
]
.
RankIndex
=
prerankIndex
+
index
igt
[
s
]
.
MyKey
=
strList
[
i
+
1
]
//查询储存昵称以及头像url的redis
var
err
error
resultstr
,
err
=
RedisGetKV
(
redisConn
,
"GUID:"
+
igt
[
s
]
.
UID
)
if
err
!=
nil
{
log
.
Println
(
"get redis err:"
,
err
)
resIndex
=
"105206"
}
r
,
err
:=
regexp
.
Compile
(
`\|([^\|])*\|`
)
if
err
!=
nil
{
log
.
Println
(
"err:"
,
err
)
resIndex
=
"105200"
}
// 使用正则匹配需要的值
result
:=
r
.
FindAllString
(
resultstr
,
valuecount
)
...
...
@@ -492,7 +493,7 @@ func IceGameTopRedisGetSingleUserRangeRankInfo(uid string, gtid string, gid stri
if
err
!=
nil
{
log
.
Printf
(
"select db err:"
,
err
)
}
return
&
igt
,
resIndex
return
&
igt
,
resIndex
,
nil
}
func
IceGameTopRedisCreateRank
(
gtid
string
,
gid
string
,
toptype
string
,
gtname
string
,
sorcetype
string
,
sorcesub
string
,
sorceorder
string
)
error
{
// 连接redis
...
...
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