2017-06-26 18:38:17 +02:00
|
|
|
/* global it, describe, afterEach */
|
|
|
|
|
2012-01-21 21:19:55 +01:00
|
|
|
var RedisDocumentStore = require('../lib/document_stores/redis');
|
2011-11-29 02:49:12 +01:00
|
|
|
|
2011-11-29 02:56:41 +01:00
|
|
|
var winston = require('winston');
|
|
|
|
winston.remove(winston.transports.Console);
|
|
|
|
|
2011-11-29 02:49:12 +01:00
|
|
|
describe('redis_document_store', function() {
|
|
|
|
|
2011-11-29 02:56:41 +01:00
|
|
|
/* reconnect to redis on each test */
|
|
|
|
afterEach(function() {
|
|
|
|
if (RedisDocumentStore.client) {
|
|
|
|
RedisDocumentStore.client.quit();
|
|
|
|
RedisDocumentStore.client = false;
|
|
|
|
}
|
|
|
|
});
|
2017-06-26 18:38:17 +02:00
|
|
|
|
2011-11-29 02:49:12 +01:00
|
|
|
describe('set', function() {
|
|
|
|
|
2012-01-13 17:16:42 +01:00
|
|
|
it('should be able to set a key and have an expiration set', function(done) {
|
2011-11-29 02:49:12 +01:00
|
|
|
var store = new RedisDocumentStore({ expire: 10 });
|
2012-01-13 17:16:42 +01:00
|
|
|
store.set('hello1', 'world', function() {
|
2011-11-29 02:49:12 +01:00
|
|
|
RedisDocumentStore.client.ttl('hello1', function(err, res) {
|
2012-01-13 17:16:42 +01:00
|
|
|
res.should.be.above(1);
|
|
|
|
done();
|
2011-11-29 02:49:12 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2012-01-13 17:16:42 +01:00
|
|
|
it('should not set an expiration when told not to', function(done) {
|
2011-11-29 02:49:12 +01:00
|
|
|
var store = new RedisDocumentStore({ expire: 10 });
|
2012-01-13 17:16:42 +01:00
|
|
|
store.set('hello2', 'world', function() {
|
2011-11-29 02:49:12 +01:00
|
|
|
RedisDocumentStore.client.ttl('hello2', function(err, res) {
|
2012-01-13 17:16:42 +01:00
|
|
|
res.should.equal(-1);
|
|
|
|
done();
|
2011-11-29 02:49:12 +01:00
|
|
|
});
|
2012-01-13 17:16:42 +01:00
|
|
|
}, true);
|
2011-11-29 02:49:12 +01:00
|
|
|
});
|
|
|
|
|
2012-01-13 17:16:42 +01:00
|
|
|
it('should not set an expiration when expiration is off', function(done) {
|
2011-11-29 02:49:12 +01:00
|
|
|
var store = new RedisDocumentStore({ expire: false });
|
2017-06-26 18:38:17 +02:00
|
|
|
store.set('hello3', 'world', function() {
|
2011-11-29 02:49:12 +01:00
|
|
|
RedisDocumentStore.client.ttl('hello3', function(err, res) {
|
2012-01-13 17:16:42 +01:00
|
|
|
res.should.equal(-1);
|
|
|
|
done();
|
2011-11-29 02:49:12 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|