2017-06-26 18:38:17 +02:00
|
|
|
/* global it, describe, afterEach */
|
|
|
|
|
2020-08-26 04:54:58 +02:00
|
|
|
const assert = require('assert');
|
2011-11-29 02:49:12 +01:00
|
|
|
|
2020-08-26 04:54:58 +02:00
|
|
|
const winston = require('winston');
|
2011-11-29 02:56:41 +01:00
|
|
|
winston.remove(winston.transports.Console);
|
|
|
|
|
2020-08-26 04:54:58 +02:00
|
|
|
const RedisDocumentStore = require('../lib/document_stores/redis');
|
2017-11-01 01:02:59 +01:00
|
|
|
|
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) {
|
2020-08-26 16:04:20 +02:00
|
|
|
let 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) {
|
2017-11-01 01:02:59 +01:00
|
|
|
assert.ok(res > 1);
|
2012-01-13 17:16:42 +01:00
|
|
|
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) {
|
2020-08-26 16:04:20 +02:00
|
|
|
let 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) {
|
2017-11-01 01:02:59 +01:00
|
|
|
assert.equal(-1, res);
|
2012-01-13 17:16:42 +01:00
|
|
|
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) {
|
2020-08-26 16:04:20 +02:00
|
|
|
let 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) {
|
2017-11-01 01:02:59 +01:00
|
|
|
assert.equal(-1, res);
|
2012-01-13 17:16:42 +01:00
|
|
|
done();
|
2011-11-29 02:49:12 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|