mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 19:46:01 +01:00
expire functionality in dbal
This commit is contained in:
@@ -50,13 +50,20 @@
|
|||||||
function createCollections() {
|
function createCollections() {
|
||||||
db.createCollection('objects', function(err, collection) {
|
db.createCollection('objects', function(err, collection) {
|
||||||
if(err) {
|
if(err) {
|
||||||
winston.error("Error creating collection " + err.message);
|
winston.error('Error creating collection ' + err.message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(collection) {
|
if(collection) {
|
||||||
collection.ensureIndex({_key :1}, {background:true}, function(err, name){
|
collection.ensureIndex({_key :1}, {background:true}, function(err, name) {
|
||||||
if(err) {
|
if(err) {
|
||||||
winston.error("Error creating index " + err.message);
|
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);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -64,13 +71,13 @@
|
|||||||
|
|
||||||
db.createCollection('search', function(err, collection) {
|
db.createCollection('search', function(err, collection) {
|
||||||
if(err) {
|
if(err) {
|
||||||
winston.error("Error creating collection " + err.message);
|
winston.error('Error creating collection ' + err.message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(collection) {
|
if(collection) {
|
||||||
collection.ensureIndex({content:'text'}, {background:true}, function(err, name){
|
collection.ensureIndex({content:'text'}, {background:true}, function(err, name){
|
||||||
if(err) {
|
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
|
//hashes
|
||||||
module.setObject = function(key, data, callback) {
|
module.setObject = function(key, data, callback) {
|
||||||
data['_key'] = key;
|
data['_key'] = key;
|
||||||
|
|||||||
@@ -211,6 +211,14 @@
|
|||||||
redisClient.keys(key, callback);
|
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
|
//hashes
|
||||||
|
|
||||||
module.setObject = function(key, data, callback) {
|
module.setObject = function(key, data, callback) {
|
||||||
|
|||||||
Reference in New Issue
Block a user