Skip to content

Node.js based forum software built for the modern web

expire functionality in dbal

Baris Soner Usakli438f90d859de
diff --git a/src/database/mongo.js b/src/database/mongo.js
index f9b6ee8eea..9f1f8ea6a9 100644
--- a/src/database/mongo.js
+++ b/src/database/mongo.js
@@ -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;
diff --git a/src/database/redis.js b/src/database/redis.js
index 02941be081..a298980fef 100644
--- a/src/database/redis.js
+++ b/src/database/redis.js
@@ -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) {