فهرست منبع

Add a config to disable redis

poeti8 6 سال پیش
والد
کامیت
aacb981820
2فایلهای تغییر یافته به همراه15 افزوده شده و 8 حذف شده
  1. 1 0
      server/config.example.js
  2. 14 8
      server/redis.js

+ 1 - 0
server/config.example.js

@@ -10,6 +10,7 @@ module.exports = {
   DB_PASSWORD: '',
 
   /* Redis host and port */
+  REDIS_DISABLED: false,
   REDIS_HOST: '127.0.0.1',
   REDIS_PORT: 6379,
   REDIS_PASSWORD: '',

+ 14 - 8
server/redis.js

@@ -2,12 +2,18 @@ const { promisify } = require('util');
 const redis = require('redis');
 const config = require('./config');
 
-const client = redis.createClient({
-  host: config.REDIS_HOST || '127.0.0.1',
-  port: config.REDIS_PORT || 6379,
-  password: config.REDIS_PASSWORD || '',
-});
+if (config.REDIS_DISABLED === true) {
+  exports.get = () => Promise.resolve(null);
+  exports.set = () => Promise.resolve(null);
+  exports.del = () => Promise.resolve(null);
+} else {
+  const client = redis.createClient({
+    host: config.REDIS_HOST || '127.0.0.1',
+    port: config.REDIS_PORT || 6379,
+    password: config.REDIS_PASSWORD || '',
+  });
 
-exports.get = promisify(client.get).bind(client);
-exports.set = promisify(client.set).bind(client);
-exports.del = promisify(client.del).bind(client);
+  exports.get = promisify(client.get).bind(client);
+  exports.set = promisify(client.set).bind(client);
+  exports.del = promisify(client.del).bind(client);
+}