From 41ca21e2ca8eb63b09f9f0adcdd9bbcd0c2c59ff Mon Sep 17 00:00:00 2001 From: zhl Date: Thu, 28 Jan 2021 22:30:38 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E4=BF=A1=E6=81=AF=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E8=BF=94=E5=9B=9Erank?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/AccountController.ts | 13 ++++++++++++- src/redis/RedisClient.ts | 9 +++++++++ src/service/rank.ts | 6 ++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/controllers/AccountController.ts b/src/controllers/AccountController.ts index 4276d59..fd33d68 100644 --- a/src/controllers/AccountController.ts +++ b/src/controllers/AccountController.ts @@ -4,7 +4,12 @@ import { Card } from '../models/subdoc/Card' import { BaseConst } from '../constants/BaseConst' import { BagItem, ItemType } from '../models/BagItem' import { RedisClient } from '../redis/RedisClient' -import { checkGameing, setGameing, usersByScore } from '../service/rank' +import { + checkGameing, + getRankScore, + setGameing, + usersByScore +} from '../service/rank' import { fetchAccount } from '../dao/AccountDao' import { generateId } from '../utils/security.util' import { getRandom } from '../utils/number.util' @@ -32,6 +37,12 @@ export default class AccountController extends BaseController { result.season_score = account.season_score result.season_data = account.season_data result.match_score = account.getMatchScore() + let rank = await getRankScore(accountid) + if (typeof rank === 'string') { + result.rank = parseInt(rank) + } else { + result.rank = rank + } return result } @router('get /svr/:accountid/uinfo') diff --git a/src/redis/RedisClient.ts b/src/redis/RedisClient.ts index 891db0b..ab0d6d4 100644 --- a/src/redis/RedisClient.ts +++ b/src/redis/RedisClient.ts @@ -170,6 +170,15 @@ export class RedisClient { }); } + public async zrevrank(key: string, member: string) { + return new Promise((resolve, reject) => { + this.pub.zrevrank(key, member, (err, data) => { + if (err) { return reject(err); } + resolve(data); + }); + }); + } + public async hset(key: string, field: string, value: string) { return new Promise((resolve) => { this.pub.hset(key, field, value, resolve); diff --git a/src/service/rank.ts b/src/service/rank.ts index dea3ca4..d090fa5 100644 --- a/src/service/rank.ts +++ b/src/service/rank.ts @@ -20,3 +20,9 @@ export async function checkGameing(accountid: string) { return await new RedisClient().get('gameing_' + accountid) } +export async function getRankScore(accountid: string) { + return await new RedisClient().zrevrank(BaseConst.RANK_SCORE, accountid) +} + + +