Fix typo, tune redis2

This commit is contained in:
Anatoliy Chakkaev 2012-09-09 16:51:53 +04:00
parent 44591111b6
commit a2618dd3a2
2 changed files with 22 additions and 7 deletions

View File

@ -6,7 +6,7 @@ var safeRequire = require('../utils').safeRequire;
var redis = safeRequire('redis');
exports.initialize = function initializeSchema(schema, callback) {
console.log('GOOD NEWS! Redis this redis adapter version is deprecated, use redis2 instead. A lot of improvements, and new indexes incompatible with old (sorry about that): now we only store id and not ModelName:id in indexes. Also dates format in indexes changed to unix timestamp for better sorting and filtering performance');
console.log('GOOD NEWS! This redis adapter version is deprecated, use redis2 instead. A lot of improvements, and new indexes incompatible with old (sorry about that): now we only store id and not ModelName:id in indexes. Also dates format in indexes changed to unix timestamp for better sorting and filtering performance');
if (!redis) return;
if (schema.settings.url) {

View File

@ -86,12 +86,12 @@ commands.forEach(function (cmd) {
});
Client.prototype.multi = function (commands, callback) {
if (commands.length === 0) return callback();
if (commands.length === 0) return callback && callback();
if (commands.length === 1) {
return this[commands[0].shift().toLowerCase()].call(
this,
commands[0],
function (e, r) { callback(e, [r]) });
callback && function (e, r) { callback(e, [r]) });
}
var log = this._adapter.logger('MULTI\n ' + commands.map(function (x) {
return x.join(' ');
@ -99,7 +99,7 @@ Client.prototype.multi = function (commands, callback) {
this._client.multi(commands).exec(function (err, replies) {
if (err) console.log(err);
log();
callback(err, replies);
callback && callback(err, replies);
});
};
@ -260,13 +260,28 @@ BridgeToRedis.prototype.create = function (model, data, callback) {
});
// push the id to the list of user ids for sorting
this.client.sadd(["s:" + model, upsert ? data : data.id]);
this.client.sadd(['s:' + model, data.id]);
}
};
BridgeToRedis.prototype.updateOrCreate = function (model, data, callback) {
if (!data.id) return this.create(model, data, callback);
this.save(model, data, callback);
if (!data.id) {
return this.create(model, data, callback);
}
var client = this.client;
this.save(model, data, function (error, obj) {
var key = 'id:' + model;
client.get(key, function (err, id) {
if (!id || data.id > parseInt(id, 10)) {
client.set([key, data.id], ok);
} else {
ok();
}
});
function ok() {
callback(error, obj);
}
});
};
BridgeToRedis.prototype.exists = function (model, id, callback) {