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