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