moved RedisDB.js to src/redis.js
parent
f7690896cc
commit
efa0649081
@ -1,59 +0,0 @@
|
|||||||
(function(RedisDB) {
|
|
||||||
var PRODUCTION = false,
|
|
||||||
ERROR_LOGS = true,
|
|
||||||
|
|
||||||
redis = require('redis'),
|
|
||||||
db = redis.createClient();
|
|
||||||
|
|
||||||
// todo (holy cow): append,auth,bgrewriteaof,bgsave,bitcount,bitop,blpop,brpop,brpoplpush,client kill,client list,client getname,client setname,config get,config set,config resetstat,dbsize,debug object,debug segfault,decrby,del,discard,dump,echo,eval,evalsha,exec,exists,expire,expireat,flushall,flushdb,getbit,getrange,getset,hdel,hexists,hget,hgetall,hincrby,hincrbyfloat,hkeys,hlen,hmget,hmset,hset,hsetnx,hvals,incrby,incrbyfloat,info,keys,lastsave,lindex,linsert,llen,lpop,lpush,lpushx,lrange,lrem,lset,ltrim,mget,migrate,monitor,move,mset,msetnx,multi,object,persist,pexpire,pexpireat,ping,psetex,psubscribe,pttl,publish,punsubscribe,quit,randomkey,rename,renamenx,restore,rpop,rpoplpush,rpush,rpushx,sadd,save,scard,script exists,script flush,script kill,script load,sdiff,sdiffstore,select,setbit,setex,setnx,setrange,shutdown,sinter,sinterstore,sismember,slaveof,slowlog,smembers,smove,sort,spop,srandmember,srem,strlen,subscribe,sunion,sunionstore,sync,time,ttl,type,unsubscribe,unwatch,watch,zadd,zcard,zcount,zincrby,zinterstore,zrange,zrangebyscore,zrank,zrem,zremrangebyrank,zremrangebyscore,zrevrange,zrevrangebyscore,zrevrank,zscore,zunionstore
|
|
||||||
// done :^) get, set, incr, decr
|
|
||||||
|
|
||||||
function return_handler(error, data, callback, error_handler) {
|
|
||||||
if (error !== null) {
|
|
||||||
if (error_handler !== null) {
|
|
||||||
error_handler(error);
|
|
||||||
} else if (PRODUCTION === false) {
|
|
||||||
throw new Exception('RedisDB Error: ' + error);
|
|
||||||
} else if (ERROR_LOGS === true) {
|
|
||||||
console.log('RedisDB Error: ' + error);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
callback(data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
RedisDB.set = function(key, value) {
|
|
||||||
db.set(key, value);
|
|
||||||
};
|
|
||||||
|
|
||||||
RedisDB.get = function(key, callback, error_handler) {
|
|
||||||
db.get(key, function(error, data) {
|
|
||||||
return_handler(error, data, callback, error_handler);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
// Atomic Operations
|
|
||||||
RedisDB.incr = function(key, callback, error_handler) {
|
|
||||||
db.incr(key, function(error, data) {
|
|
||||||
if (callback) {
|
|
||||||
return_handler(error, data, callback, error_handler);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
RedisDB.decr = function(key) {
|
|
||||||
db.decr(key);
|
|
||||||
};
|
|
||||||
|
|
||||||
// Lists
|
|
||||||
RedisDB.lpush = function(key, item) {
|
|
||||||
db.lpush(key, item);
|
|
||||||
}
|
|
||||||
|
|
||||||
RedisDB.lrange = function(key, start, end, callback, error_handler) {
|
|
||||||
db.lrange(key, start, end, function(error, data) {
|
|
||||||
return_handler(error, data, callback, error_handler);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}(exports));
|
|
Loading…
Reference in New Issue