Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add expire along with hmset #123

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions lib/ExpressRedisCache/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,29 +50,29 @@ module.exports = (function () {
};

var size = require('../sizeof')(entry);
var calculated_size = (size / 1024).toFixed(2);

var prefix = self.prefix.match(/:$/) ? self.prefix.replace(/:$/, '')
: self.prefix;

/* Save as a Redis hash */
var redisKey = prefix + ':' + name;
self.client.hmset(redisKey, entry,
domain.intercept(function (res) {
var calculated_size = (size / 1024).toFixed(2);
/** If @expire then tell Redis to expire **/
if ( typeof entry.expire === 'number' && entry.expire > 0 ) {
self.client.expire(redisKey, +entry.expire,
domain.intercept(function () {
self.emit('message', require('util').format('SET %s ~%d Kb %d TTL (sec)', redisKey, calculated_size, +entry.expire));
callback(null, name, entry, res);
}));
}
else
{
if ( typeof entry.expire === 'number' && entry.expire > 0 ) {
/** If @expire then tell Redis to expire **/
self.client.multi()
.hmset(redisKey, entry)
.expire(redisKey, +entry.expire)
.exec(domain.intercept(function (res) {
self.emit('message', require('util').format('SET %s ~%d Kb %d TTL (sec)', redisKey, calculated_size, +entry.expire));
callback(null, name, entry, res);
}));
} else {
self.client.hmset(redisKey, entry,
domain.intercept(function (res) {
self.emit('message', require('util').format('SET %s ~%d Kb', redisKey, calculated_size));
callback(null, name, entry, res);
}
}));
}));
}
});
}

Expand Down