mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-03-05 12:01:17 +01:00
redis.js - cleanup
This commit is contained in:
42
src/redis.js
42
src/redis.js
@@ -1,5 +1,8 @@
|
||||
(function(RedisDB) {
|
||||
var redis = require('redis'),
|
||||
(function(module) {
|
||||
'use strict';
|
||||
|
||||
var RedisDB,
|
||||
redis = require('redis'),
|
||||
utils = require('./../public/src/utils.js'),
|
||||
winston = require('winston'),
|
||||
nconf = require('nconf'),
|
||||
@@ -7,45 +10,46 @@
|
||||
|
||||
if (redis_socket_or_host && redis_socket_or_host.indexOf('/')>=0) {
|
||||
/* If redis.host contains a path name character, use the unix dom sock connection. ie, /tmp/redis.sock */
|
||||
RedisDB.exports = redis.createClient(nconf.get('redis:host'))
|
||||
RedisDB = redis.createClient(nconf.get('redis:host'));
|
||||
} else {
|
||||
/* Else, connect over tcp/ip */
|
||||
RedisDB.exports = redis.createClient(nconf.get('redis:port'), nconf.get('redis:host'));
|
||||
RedisDB = redis.createClient(nconf.get('redis:port'), nconf.get('redis:host'));
|
||||
}
|
||||
|
||||
if (nconf.get('redis:password')) {
|
||||
RedisDB.exports.auth(nconf.get('redis:password'));
|
||||
RedisDB.auth(nconf.get('redis:password'));
|
||||
}
|
||||
|
||||
if( (db = nconf.get('redis:database')) ){
|
||||
RedisDB.exports.select(db, function(error){
|
||||
var db = nconf.get('redis:database');
|
||||
if (db){
|
||||
RedisDB.select(db, function(error){
|
||||
if(error !== null){
|
||||
winston.err(error);
|
||||
if (global.env !== 'production') {
|
||||
throw new Error(error);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
RedisDB.exports.handle = function(error) {
|
||||
RedisDB.handle = function(error) {
|
||||
if (error !== null) {
|
||||
winston.err(error);
|
||||
if (global.env !== 'production') {
|
||||
throw new Error(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* A possibly more efficient way of doing multiple sismember calls
|
||||
*/
|
||||
RedisDB.exports.sismembers = function(key, needles, callback) {
|
||||
RedisDB.sismembers = function(key, needles, callback) {
|
||||
var tempkey = key + ':temp:' + utils.generateUUID();
|
||||
RedisDB.exports.sadd(tempkey, needles, function() {
|
||||
RedisDB.exports.sinter(key, tempkey, function(err, data) {
|
||||
RedisDB.exports.del(tempkey);
|
||||
RedisDB.sadd(tempkey, needles, function() {
|
||||
RedisDB.sinter(key, tempkey, function(err, data) {
|
||||
RedisDB.del(tempkey);
|
||||
callback(err, data);
|
||||
});
|
||||
});
|
||||
@@ -54,8 +58,8 @@
|
||||
/*
|
||||
* gets fields of a hash as an object instead of an array
|
||||
*/
|
||||
RedisDB.exports.hmgetObject = function(key, fields, callback) {
|
||||
RedisDB.exports.hmget(key, fields, function(err, data) {
|
||||
RedisDB.hmgetObject = function(key, fields, callback) {
|
||||
RedisDB.hmget(key, fields, function(err, data) {
|
||||
if (err === null) {
|
||||
var returnData = {};
|
||||
|
||||
@@ -69,8 +73,8 @@
|
||||
callback(err, null);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = RedisDB;
|
||||
|
||||
|
||||
}(module));
|
||||
}(module));
|
||||
Reference in New Issue
Block a user