Commit 785d6efc by 宋毅

tj

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