feat(路由): 部分路由不缓存redis

This commit is contained in:
luying
2023-05-06 16:23:23 +08:00
parent 96407c470e
commit 3b351e03b7
3 changed files with 39 additions and 3 deletions

View File

@@ -17,7 +17,7 @@ interface ServerInfo {
export async function dispatch(redis: any, uid: string, connectors: ServerInfo[], serverType: string = '') {
connectors.sort((a, b) => a.id > b.id? 1: -1);
if (serverType) {
if (serverType && needRoleRoute(serverType)) {
let appid: string = await redis.hgetAsync('roleRoute', `${uid}_${serverType}`);
if(!appid) {
let index = Math.abs(crc.crc32(uid)) % connectors.length;
@@ -30,4 +30,30 @@ export async function dispatch(redis: any, uid: string, connectors: ServerInfo[]
}
let index = Math.abs(crc.crc32(uid)) % connectors.length;
return connectors[index];
}
function needRoleRoute(serverType: string) {
switch (serverType) {
case 'connector':
case 'role':
case 'battle':
case 'activity':
case 'order':
case 'gm':
case 'chat':
return false;
case 'comBattle':
case 'guild':
return true;
default:
return true;
}
}
export async function clearComBattleRoute(redis: any, teamCode: string) {
try {
await redis.hdelAsync('roleRoute', `${teamCode}_comBattle`);
} catch(e) {
console.log(e)
}
}