admin管理员组文章数量:814948
Redis节点设置的最佳做法
我已经在单独的文件上设置了redis客户端
export function getRedisClient() {
const port: number = redisConfig.port || 6379;
const host = redisConfig.host;
const client = redis.createClient(port, host, {
no_ready_check: true,
retry_strategy: function(options) {
if (options.error && options.error.code === 'ECONNREFUSED') {
// End reconnecting on a specific error and flush all commands with
// a individual error
return new Error('The server refused the connection');
}
if (options.total_retry_time > 1000 * 60 * 60) {
// End reconnecting after a specific timeout and flush all commands
// with a individual error
return new Error('Retry time exhausted');
}
if (options.attempt > 10) {
// End reconnecting with built in error
return undefined;
}
// reconnect after
return Math.min(options.attempt * 100, 3000);
},
});
client.on('error', function(error) {
console.error(error);
});
client.on('ready', function() {
console.log('Redis Server Connected...');
});
return client;
}
问题是它让我max number of clients reached
。
每次调用函数时,调用函数都会创建一个新客户端吗?
如果可以的话,你们建议我在多服务中实现Redis的更好做法。
回答如下:您不必每次都创建另一个客户端。只需创建一个客户端并导出即可。每当您想使用redis时都将其导入。
本文标签: Redis节点设置的最佳做法
版权声明:本文标题:Redis节点设置的最佳做法 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/biancheng/1715207677a822516.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论