From 7592be7150d41b021794132d2dfaa0b96919b1ce Mon Sep 17 00:00:00 2001 From: yinhewang Date: Tue, 7 Aug 2018 01:59:12 +0800 Subject: [PATCH] Apply ioredis, and add has redis cluster condition --- index.js | 10 +++++++++- package.json | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 78b58d5..52b3860 100644 --- a/index.js +++ b/index.js @@ -16,6 +16,7 @@ var EventEmitter = require('events').EventEmitter; var debug = require('debug')('koa-redis'); var redis = require('redis'); +var ioredis = require("ioredis"); var redisWrapper = require('co-redis'); var util = require('util'); var wrap = require('co-wrap-all'); @@ -43,7 +44,14 @@ var RedisStore = module.exports = function (options) { options.path = options.path || options.socket || null; // For backwards compatibility if (!options.client) { debug('Init redis new client'); - client = redis.createClient(options); + // client = redis.createClient(options); + // + // Apply ioredis, Add has redis cluster condition: + if (!options.isRedisCluster) { + client = redis.createClient(options); + } else { + client = new ioredis.Cluster(options.nodes, {redisOptions: options.redisOptions}); + } } else { if (options.duplicate) { // Duplicate client and update with options provided debug('Duplicating provided client with new options (if provided)'); diff --git a/package.json b/package.json index cc19fc2..eaa42ed 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "co-redis": "^2.1.1", "co-wrap-all": "^1.0.0", "debug": "^3.1.0", + "ioredis": "^3.2.2", "redis": "^2.8.0" }, "devDependencies": {