Commit 785d6efc by 宋毅

tj

parent c7c4ff1a
...@@ -8,13 +8,13 @@ class APIBase { ...@@ -8,13 +8,13 @@ class APIBase {
this.redisClient = system.getObject("util.redisClient"); this.redisClient = system.getObject("util.redisClient");
this.execClient = system.getObject("util.execClient"); this.execClient = system.getObject("util.execClient");
this.esUtils = system.getObject("util.esUtils"); this.esUtils = system.getObject("util.esUtils");
this.exTime = 6 * 3600;//缓存过期时间,6小时
} }
//-----------------------新的模式------------------开始 //-----------------------新的模式------------------开始
async doexecMethod(gname, methodname, pobj, query, req) { async doexecMethod(gname, methodname, pobj, query, req) {
try { try {
var result = await this[methodname](pobj, query, req); var result = await this[methodname](pobj, query, req);
result.requestId = await this.getBusUid("scz");
if ("LOGS-SYTXPUBLIC-MSGQ" != settings.queuedName) { if ("LOGS-SYTXPUBLIC-MSGQ" != settings.queuedName) {
pobj.actionBody.resultInfo = result; pobj.actionBody.resultInfo = result;
pobj.actionBody.requestId = result.requestId; pobj.actionBody.requestId = result.requestId;
...@@ -25,8 +25,7 @@ class APIBase { ...@@ -25,8 +25,7 @@ class APIBase {
} catch (e) { } catch (e) {
console.log(e.stack, "api.base调用出现异常,请联系管理员.........."); console.log(e.stack, "api.base调用出现异常,请联系管理员..........");
var rtnerror = system.getResultFail(-200, "出现异常,error:" + e.stack); var rtnerror = system.getResultFail(-200, "出现异常,error:" + e.stack);
rtnerror.requestId = await this.getBusUid("err"); pobj.actionBody.requestId = await this.getBusUid("err");
pobj.actionBody.requestId = rtnerror.requestId;
pobj.actionBody.errorInfo = e.stack; pobj.actionBody.errorInfo = e.stack;
pobj.actionBody.opTitle = ",reqPath:" + req.path; pobj.actionBody.opTitle = ",reqPath:" + req.path;
this.esUtils.addEsLogs(settings.queuedName + "apidoexec-error", pobj.actionBody); this.esUtils.addEsLogs(settings.queuedName + "apidoexec-error", pobj.actionBody);
......
...@@ -35,8 +35,6 @@ class ProducerAPI extends APIBase { ...@@ -35,8 +35,6 @@ class ProducerAPI extends APIBase {
opResult = system.getResult(null, "actionType参数错误"); opResult = system.getResult(null, "actionType参数错误");
break; break;
} }
var uidStr = await this.getBusUid("scz");
opResult.requestId = uidStr;
return opResult; return opResult;
} }
} }
......
...@@ -5,7 +5,6 @@ const bluebird = require("bluebird"); ...@@ -5,7 +5,6 @@ const bluebird = require("bluebird");
bluebird.promisifyAll(redis); bluebird.promisifyAll(redis);
class RedisClient { class RedisClient {
constructor() { constructor() {
this.redisConfig = settings.redis();
this.client = this.getCreateClientInstance(); this.client = this.getCreateClientInstance();
this.subclient = this.client.duplicate(); this.subclient = this.client.duplicate();
...@@ -57,12 +56,12 @@ class RedisClient { ...@@ -57,12 +56,12 @@ class RedisClient {
return this.subclient; return this.subclient;
} }
getCreateClientInstance() { getCreateClientInstance() {
var self = this; const redisConfig = settings.redis()
return redis.createClient({ return redis.createClient({
host: self.redisConfig.host, host: redisConfig.host,
port: self.redisConfig.port, port: redisConfig.port,
password: self.redisConfig.password, password: redisConfig.password,
db: self.redisConfig.db, db: redisConfig.db,
retry_strategy: function (options) { retry_strategy: function (options) {
if (options.total_retry_time > 1000 * 60 * 60) { if (options.total_retry_time > 1000 * 60 * 60) {
return new Error('Retry time exhausted'); return new Error('Retry time exhausted');
...@@ -136,16 +135,34 @@ class RedisClient { ...@@ -136,16 +135,34 @@ class RedisClient {
async zremRangebyscoreData(collectionName, minValue, maxValue) { async zremRangebyscoreData(collectionName, minValue, maxValue) {
return await this.client.zremrangebyscoreAsync(collectionName + "-SORT", minValue, maxValue); return await this.client.zremrangebyscoreAsync(collectionName + "-SORT", minValue, maxValue);
} }
/**
* 设置缓存
* @param {*} key key
* @param {*} val 值
* @param {*} t 过期时间,为空则永久存在
*/
async setWithEx(key, val, t) { async setWithEx(key, val, t) {
var p = this.client.setAsync(key, val); var p = this.client.setAsync(key, val);
if (t) {
this.client.expire(key, t); this.client.expire(key, t);
}
return p; return p;
} }
/**
* 获取缓存
* @param {*} key key
*/
async getCache(key) { async getCache(key) {
return this.client.getAsync(key); return this.client.getAsync(key);
} }
/** /**
* 删除缓存
* @param {*} key key
*/
async delete(key) {
return this.client.delAsync(key);
}
/**
* 设置业务锁 * 设置业务锁
* @param {*} lockKey 锁key * @param {*} lockKey 锁key
*/ */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment