全面去掉hero的redis依赖

This commit is contained in:
ciniao 2023-12-18 14:43:13 +08:00
parent 2bbfb55704
commit 327f9c9b5a
9 changed files with 30 additions and 23 deletions

View File

@ -120,7 +120,13 @@ export default async function (call: ApiCall<ReqBingo, ResBingo>) {
} }
} else if (shell[0] == 'heroMaxLv') { } else if (shell[0] == 'heroMaxLv') {
let heros = await G.redis.get('hero', call.uid); //let heros = await G.redis.get('hero', call.uid);
let s = await G.mongodb.collection('hero').find({
uid: call.uid
}).toArray();
let heros = s.map(h => G.mongodb.conversionIdObj(h));
for (let [_id, hero] of Object.entries(heros)) { for (let [_id, hero] of Object.entries(heros)) {
await HeroFun.changeHeroAttr(call, hero, { await HeroFun.changeHeroAttr(call, hero, {
lv: Object.keys(G.gc.playerLv).length * 3, lv: Object.keys(G.gc.playerLv).length * 3,

View File

@ -39,7 +39,7 @@ export default async function (call: ApiCall<ReqChangePos, ResChangePos>) {
} }
} else if (call.req.state == 'change') { } else if (call.req.state == 'change') {
if (heroPos[call.req.pos]) { if (heroPos[call.req.pos]) {
let unLoadHero = await G.redis.get('hero', call.uid, heroPos[call.req.pos]); let unLoadHero = await HeroFun.getHero(call, heroPos[call.req.pos]);
unLoadHero && fightHeros.removeOne(id => id == unLoadHero.heroId); unLoadHero && fightHeros.removeOne(id => id == unLoadHero.heroId);
} }
if (fightHeros.includes(hero.heroId.toString())) return call.errorCode(-2); if (fightHeros.includes(hero.heroId.toString())) return call.errorCode(-2);

View File

@ -4,7 +4,7 @@ import { ReqGetList, ResGetList } from "../../shared/protocols/hero/PtlGetList";
export default async function (call: ApiCall<ReqGetList, ResGetList>) { export default async function (call: ApiCall<ReqGetList, ResGetList>) {
let list: ResGetList['list'] = {}; let list: ResGetList['list'] = {};
let kvList: k_v<RedisCollections2['hero']> = {}; //let kvList: k_v<RedisCollections2['hero']> = {};
let arrList = await G.mongodb.collection('hero').find({ uid: call.uid }).toArray(); let arrList = await G.mongodb.collection('hero').find({ uid: call.uid }).toArray();
let heroCon = G.gc.hero; let heroCon = G.gc.hero;
@ -12,7 +12,7 @@ export default async function (call: ApiCall<ReqGetList, ResGetList>) {
let maxherolv = 0; let maxherolv = 0;
arrList.forEach(v => { arrList.forEach(v => {
let d = G.mongodb.conversionIdObj(v); let d = G.mongodb.conversionIdObj(v);
kvList[G.formatRedisKey(d._id)] = d; //kvList[G.formatRedisKey(d._id)] = d;
list[d._id] = d; list[d._id] = d;
if (v.lv > maxherolv) maxherolv = v.lv; if (v.lv > maxherolv) maxherolv = v.lv;
@ -23,7 +23,7 @@ export default async function (call: ApiCall<ReqGetList, ResGetList>) {
await G.mongodb.collection('playerInfo', 'usertasklog').updateOne({ uid: call.conn.uid, type: 'usertasklog' }, await G.mongodb.collection('playerInfo', 'usertasklog').updateOne({ uid: call.conn.uid, type: 'usertasklog' },
{ $set: { maxherolv: maxherolv, herocolor: color } }, { upsert: true }); { $set: { maxherolv: maxherolv, herocolor: color } }, { upsert: true });
G.redis.set('hero', call.uid, kvList); //G.redis.set('hero', call.uid, kvList);
let recLshd = await G.mongodb.collection('playerInfo', 'lshd_hero').findOne({ uid: call.conn.uid, type: 'lshd_hero' }); let recLshd = await G.mongodb.collection('playerInfo', 'lshd_hero').findOne({ uid: call.conn.uid, type: 'lshd_hero' });
let { uid, _id, type, ...heros } = (recLshd || {}); let { uid, _id, type, ...heros } = (recLshd || {});

View File

@ -39,7 +39,7 @@ export default async function (call: ApiCall<ReqJinJie, ResJinJie, ServiceType>)
let selectHeros: ResGetList['list'][''][] = []; let selectHeros: ResGetList['list'][''][] = [];
for (let _id of call.req.idArr) { for (let _id of call.req.idArr) {
let _hero = await G.redis.get('hero', call.uid, _id); let _hero = await HeroFun.getHero(call, _id);
if (!_hero) return call.error(globalThis.lng.hero_1); if (!_hero) return call.error(globalThis.lng.hero_1);
selectHeros.push(_hero); selectHeros.push(_hero);
} }

View File

@ -17,7 +17,7 @@ export class EquipFun {
//穿戴装备时该装备穿戴在另一个英雄身上 //穿戴装备时该装备穿戴在另一个英雄身上
if (change.wearaId != undefined && equip.wearaId && equip.wearaId != change.wearaId && changeHero) { if (change.wearaId != undefined && equip.wearaId && equip.wearaId != change.wearaId && changeHero) {
let takeHero = await G.redis.get('hero', call.uid, equip.wearaId); let takeHero = await HeroFun.getHero(call, equip.wearaId);
if (takeHero) { if (takeHero) {
let _equip = Object.assign({}, takeHero.equip); let _equip = Object.assign({}, takeHero.equip);
_equip[G.gc.equip[equip.equipId].type] = ''; _equip[G.gc.equip[equip.equipId].type] = '';

View File

@ -24,9 +24,9 @@ export class HeroFun {
hero.zhanli = HeroShared.getHeroZhanLi(hero, call.otherBuff, Object.values(call.conn.gud.heroPos).indexOf(hero._id)); hero.zhanli = HeroShared.getHeroZhanLi(hero, call.otherBuff, Object.values(call.conn.gud.heroPos).indexOf(hero._id));
change.zhanli = hero.zhanli; change.zhanli = hero.zhanli;
for (let k in change) { // for (let k in change) {
await G.redis.set('hero', call.uid, hero._id, k as any, change[k]); // await G.redis.set('hero', call.uid, hero._id, k as any, change[k]);
} // }
await G.mongodb.collection('hero').updateOne({uid: call.uid, _id: new ObjectId(hero._id)}, { await G.mongodb.collection('hero').updateOne({uid: call.uid, _id: new ObjectId(hero._id)}, {
$set: { $set: {
@ -41,13 +41,13 @@ export class HeroFun {
/**获取英雄 */ /**获取英雄 */
static async getHero(call: call, oid: string) { static async getHero(call: call, oid: string) {
let data = await G.redis.get('hero', call.uid, oid); //let data = await G.redis.get('hero', call.uid, oid);
if (!data) { // 如果redis中的hero数据被清理掉 直接查询数据库 //if (!data) { // 如果redis中的hero数据被清理掉 直接查询数据库
let {_id, ...info} = await G.mongodb.collection("hero").findOne({ let {_id, ...info} = await G.mongodb.collection("hero").findOne({
_id: G.mongodb.conversionId(oid) _id: G.mongodb.conversionId(oid)
}) })
data = Object.assign({_id: _id.toHexString()}, info) let data = Object.assign({_id: _id.toHexString()}, info)
} //}
return data return data
} }

View File

@ -432,12 +432,12 @@ export class PlayerFun {
//hero/apiGetList里会G.redis.set('hero', call.uid, kvList); //hero/apiGetList里会G.redis.set('hero', call.uid, kvList);
//在这之后再执行下面的代码则不会报错 //在这之后再执行下面的代码则不会报错
if (await G.redis.type('hero', call.uid) != null) { // if (await G.redis.type('hero', call.uid) != null) {
G.redis.set('hero', call.uid, id, { // G.redis.set('hero', call.uid, id, {
_id: id, // _id: id,
...ops // ...ops
}); // });
} // }
call.addEventMsg('msg_s2c/HeroChange', id, { call.addEventMsg('msg_s2c/HeroChange', id, {

View File

@ -38,7 +38,7 @@ export class ShiwuFun {
//穿戴饰物时该装备穿戴在另一个英雄身上 //穿戴饰物时该装备穿戴在另一个英雄身上
if (change.wearId != undefined && shiwu.wearId && shiwu.wearId != change.wearId && changeHero) { if (change.wearId != undefined && shiwu.wearId && shiwu.wearId != change.wearId && changeHero) {
let takeHero = await G.redis.get('hero', call.uid, shiwu.wearId); let takeHero = await HeroFun.getHero(call, shiwu.wearId);
if (takeHero) { if (takeHero) {
let _shiwu = Object.assign({}, takeHero.shiwu); let _shiwu = Object.assign({}, takeHero.shiwu);
let _pos = Object.keys(_shiwu).filter(pos => _shiwu[pos]._id == shiwu._id)[0]; let _pos = Object.keys(_shiwu).filter(pos => _shiwu[pos]._id == shiwu._id)[0];
@ -55,7 +55,7 @@ export class ShiwuFun {
//属性发生变化并且穿戴在英雄身上时 //属性发生变化并且穿戴在英雄身上时
if (change.wearId == undefined && shiwu.wearId) { if (change.wearId == undefined && shiwu.wearId) {
let takeHero = await G.redis.get('hero', call.uid, shiwu.wearId); let takeHero = await HeroFun.getHero(call, shiwu.wearId);
if (takeHero) { if (takeHero) {
let _shiwu = Object.assign({}, takeHero.shiwu); let _shiwu = Object.assign({}, takeHero.shiwu);
let _pos = Object.keys(_shiwu).filter(pos => _shiwu[pos]._id == shiwu._id)[0]; let _pos = Object.keys(_shiwu).filter(pos => _shiwu[pos]._id == shiwu._id)[0];

View File

@ -75,8 +75,9 @@ async function clearRedis() {
G.redis.fromatKey('jjc'), G.redis.fromatKey('jjc'),
G.redis.fromatKey('user'), G.redis.fromatKey('user'),
G.redis.fromatKey('item'), G.redis.fromatKey('item'),
G.redis.fromatKey('hero'),
//G.redis.fromatKey('equip'), //G.redis.fromatKey('equip'),
//G.redis.fromatKey('hero'),
//G.redis.fromatKey('shiwu'), //G.redis.fromatKey('shiwu'),
//G.redis.fromatKey('gbtx'), //G.redis.fromatKey('gbtx'),
//G.redis.fromatKey('dxlt'), //G.redis.fromatKey('dxlt'),