🎈 perf(dispatch): 路由使用redis
This commit is contained in:
@@ -1,20 +1,21 @@
|
||||
|
||||
import { dispatch } from './dispatcher';
|
||||
import { dispatch } from '../pubUtils/dispatcher';
|
||||
import { Session, Application } from 'pinus';
|
||||
import { redisClient } from '../services/redisService';
|
||||
|
||||
export function chat(session: Session, msg: any, app: Application, cb: (err: Error, serverId?: string) => void) {
|
||||
export async function chat(session: Session, msg: any, app: Application, cb: (err: Error, serverId?: string) => void) {
|
||||
let chatServers = app.getServersByType('chat');
|
||||
|
||||
if (!chatServers || chatServers.length === 0) {
|
||||
cb(new Error('can not find chat servers.'));
|
||||
return;
|
||||
}
|
||||
let id = session.get('chatServer')||dispatch(session.get('roleId'), chatServers, 'chat').id;
|
||||
let id = session.get('chatServer')||(await dispatch(redisClient(), session.get('roleId'), chatServers, 'chat')).id;
|
||||
|
||||
cb(null, id);
|
||||
}
|
||||
|
||||
export function battle(session: Session, msg: any, app: Application, cb: (err: Error, serverId?: string) => void) {
|
||||
export async function battle(session: Session, msg: any, app: Application, cb: (err: Error, serverId?: string) => void) {
|
||||
let battleServers = app.getServersByType('battle');
|
||||
|
||||
if (!battleServers || battleServers.length === 0) {
|
||||
@@ -42,16 +43,16 @@ export function battle(session: Session, msg: any, app: Application, cb: (err: E
|
||||
}
|
||||
|
||||
if(needDispatch) {
|
||||
let id = dispatch(rid, battleServers, 'battle').id;
|
||||
let id = (await dispatch(redisClient(), rid, battleServers, 'battle')).id;
|
||||
cb(null, id);
|
||||
} else {
|
||||
let id = session.get('battleServer')||dispatch(rid, battleServers, 'battle').id;
|
||||
let id = session.get('battleServer')||(await dispatch(redisClient(), rid, battleServers, 'battle')).id;
|
||||
cb(null, id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export function guild(session: Session, msg: any, app: Application, cb: (err: Error, serverId?: string) => void) {
|
||||
export async function guild(session: Session, msg: any, app: Application, cb: (err: Error, serverId?: string) => void) {
|
||||
let guildServers = app.getServersByType('guild');
|
||||
|
||||
if (!guildServers || guildServers.length === 0) {
|
||||
@@ -126,25 +127,25 @@ export function guild(session: Session, msg: any, app: Application, cb: (err: Er
|
||||
}
|
||||
|
||||
if(needDispatch) {
|
||||
let id = dispatch(rid, guildServers, 'guild').id;
|
||||
let id = (await dispatch(redisClient(), rid, guildServers, 'guild')).id;
|
||||
cb(null, id);
|
||||
} else {
|
||||
let id = session.get('guildServer')||dispatch(rid, guildServers, 'guild').id;
|
||||
let id = session.get('guildServer')||(await dispatch(redisClient(), rid, guildServers, 'guild')).id;
|
||||
cb(null, id);
|
||||
}
|
||||
}
|
||||
|
||||
export function activity(session: Session, msg: any, app: Application, cb: (err: Error, serverId?: string) => void) {
|
||||
export async function activity(session: Session, msg: any, app: Application, cb: (err: Error, serverId?: string) => void) {
|
||||
let activityServers = app.getServersByType('activity');
|
||||
if (!activityServers || activityServers.length === 0) {
|
||||
cb(new Error('can not find activity servers.'));
|
||||
return;
|
||||
}
|
||||
let id = session.get('activityServer')||dispatch(session.get('roleId'), activityServers, 'activity');
|
||||
let id = session.get('activityServer')||(await dispatch(redisClient(), session.get('roleId'), activityServers, 'activity'));
|
||||
cb(null, id);
|
||||
}
|
||||
|
||||
export function gm(session: Session, msg: any, app: Application, cb: (err: Error, serverId?: string) => void) {
|
||||
export async function gm(session: Session, msg: any, app: Application, cb: (err: Error, serverId?: string) => void) {
|
||||
let gmServers = app.getServersByType('gm');
|
||||
|
||||
if (!gmServers || gmServers.length === 0) {
|
||||
@@ -152,11 +153,11 @@ export function gm(session: Session, msg: any, app: Application, cb: (err: Error
|
||||
return;
|
||||
}
|
||||
|
||||
let res = dispatch(session.get('roleId'), gmServers, 'gm');
|
||||
let res = await dispatch(redisClient(), session.get('roleId'), gmServers, 'gm');
|
||||
cb(null, res.id);
|
||||
}
|
||||
|
||||
export function role(session: Session, msg: any, app: Application, cb: (err: Error, serverId?: string) => void) {
|
||||
export async function role(session: Session, msg: any, app: Application, cb: (err: Error, serverId?: string) => void) {
|
||||
let roleServers = app.getServersByType('role');
|
||||
|
||||
if (!roleServers || roleServers.length === 0) {
|
||||
@@ -164,11 +165,11 @@ export function role(session: Session, msg: any, app: Application, cb: (err: Err
|
||||
return;
|
||||
}
|
||||
|
||||
let id = session.get('roleServer')||dispatch(session.get('roleId'), roleServers).id;
|
||||
let id = session.get('roleServer')||(await dispatch(redisClient(), session.get('roleId'), roleServers)).id;
|
||||
cb(null, id);
|
||||
}
|
||||
|
||||
export function order(session: Session, msg: any, app: Application, cb: (err: Error, serverId?: string) => void) {
|
||||
export async function order(session: Session, msg: any, app: Application, cb: (err: Error, serverId?: string) => void) {
|
||||
let orderServers = app.getServersByType('order');
|
||||
|
||||
if (!orderServers || orderServers.length === 0) {
|
||||
@@ -176,6 +177,6 @@ export function order(session: Session, msg: any, app: Application, cb: (err: Er
|
||||
return;
|
||||
}
|
||||
|
||||
let id = session.get('orderServer')||dispatch(session.get('roleId'), orderServers, 'order').id;
|
||||
let id = session.get('orderServer')||(await dispatch(redisClient(), session.get('roleId'), orderServers, 'order')).id;
|
||||
cb(null, id);
|
||||
}
|
||||
Reference in New Issue
Block a user