expire functionality in dbal

v1.18.x
Baris Soner Usakli 11 years ago
parent 742c8fb43c
commit 438f90d859

@ -50,13 +50,20 @@
function createCollections() {
db.createCollection('objects', function(err, collection) {
if(err) {
winston.error("Error creating collection " + err.message);
winston.error('Error creating collection ' + err.message);
return;
}
if(collection) {
collection.ensureIndex({_key :1}, {background:true}, function(err, name){
collection.ensureIndex({_key :1}, {background:true}, function(err, name) {
if(err) {
winston.error('Error creating index ' + err.message);
}
});
collection.ensureIndex({'expireAt':1}, {expireAfterSeconds:0, background:true}, function(err, name) {
if(err) {
winston.error("Error creating index " + err.message);
winston.error('Error creating index ' + err.message);
}
});
}
@ -64,13 +71,13 @@
db.createCollection('search', function(err, collection) {
if(err) {
winston.error("Error creating collection " + err.message);
winston.error('Error creating collection ' + err.message);
return;
}
if(collection) {
collection.ensureIndex({content:'text'}, {background:true}, function(err, name){
if(err) {
winston.error("Error creating index " + err.message);
winston.error('Error creating index ' + err.message);
}
});
}
@ -241,6 +248,14 @@
});
}
module.expire = function(key, seconds, callback) {
module.expireAt(key, Math.round(Date.now() / 1000) + seconds, callback);
}
module.expireAt = function(key, timestamp, callback) {
module.setObjectField(key, 'expireAt', new Date(timestamp * 1000), callback);
}
//hashes
module.setObject = function(key, data, callback) {
data['_key'] = key;

@ -211,6 +211,14 @@
redisClient.keys(key, callback);
}
module.expire = function(key, seconds, callback) {
redisClient.expire(key, seconds, callback);
}
module.expireAt = function(key, timestamp, callback) {
redisClient.expireat(key, timestamp, callback);
}
//hashes
module.setObject = function(key, data, callback) {

Loading…
Cancel
Save