From 86abebf9bfc5b63a58564ba94b2c62ec21308db9 Mon Sep 17 00:00:00 2001 From: calzoneman Date: Thu, 28 Jan 2016 19:51:59 -0800 Subject: [PATCH] Add RedisClusterClient --- src/io/cluster/redisclusterclient.js | 17 +++++++++++++++++ src/server.js | 13 +++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 src/io/cluster/redisclusterclient.js diff --git a/src/io/cluster/redisclusterclient.js b/src/io/cluster/redisclusterclient.js new file mode 100644 index 00000000..b4c7eb83 --- /dev/null +++ b/src/io/cluster/redisclusterclient.js @@ -0,0 +1,17 @@ +class RedisClusterClient { + constructor(frontendPool) { + this.frontendPool = frontendPool; + } + + getSocketConfig(channel) { + return this.frontendPool.getFrontends(channel).then(result => { + if (!Array.isArray(result)) { + result = []; + } + + return { servers: result }; + }); + } +} + +export { RedisClusterClient }; diff --git a/src/server.js b/src/server.js index 6dfca796..1381cdab 100644 --- a/src/server.js +++ b/src/server.js @@ -46,6 +46,8 @@ import LocalChannelIndex from './web/localchannelindex'; import IOConfiguration from './configuration/ioconfig'; import WebConfiguration from './configuration/webconfig'; import NullClusterClient from './io/cluster/nullclusterclient'; +import { RedisClusterClient } from './io/cluster/redisclusterclient'; +import { FrontendPool } from 'cytube-common/lib/redis/frontendpool'; import session from './session'; var Server = function () { @@ -64,10 +66,16 @@ var Server = function () { self.db.init(); ChannelStore.init(); + // redis init + const redis = require('redis'); + Promise.promisifyAll(redis.RedisClient.prototype); + Promise.promisifyAll(redis.Multi.prototype); + // webserver init ----------------------------------------------------- const ioConfig = IOConfiguration.fromOldConfig(Config); const webConfig = WebConfiguration.fromOldConfig(Config); - const clusterClient = new NullClusterClient(ioConfig); + const frontendPool = new FrontendPool(redis.createClient()); + const clusterClient = new RedisClusterClient(frontendPool); const channelIndex = new LocalChannelIndex(); self.express = express(); require("./web/webserver").init(self.express, @@ -140,9 +148,6 @@ var Server = function () { return '127.0.0.1'; } }; - const redis = require('redis'); - Promise.promisifyAll(redis.RedisClient.prototype); - Promise.promisifyAll(redis.Multi.prototype); const backend = new IOBackend(listenerConfig, sioEmitter, redis.createClient()); // background tasks init ----------------------------------------------