2012-06-02 04:13:41 +08:00
|
|
|
require('../helper');
|
2012-06-02 03:47:47 +08:00
|
|
|
var _ = require('underscore')
|
2011-06-17 00:23:38 +08:00
|
|
|
, redis_pool = require('../../app/models/redis_pool')
|
2012-06-02 03:47:47 +08:00
|
|
|
, assert = require('assert');
|
2011-06-17 00:23:38 +08:00
|
|
|
|
2012-07-13 04:54:12 +08:00
|
|
|
suite('redis_pool', function() {
|
|
|
|
|
|
|
|
test('test truth', function(){
|
2012-06-02 04:13:41 +08:00
|
|
|
assert.ok(true, 'it is');
|
2012-07-13 04:54:12 +08:00
|
|
|
});
|
2011-06-17 00:23:38 +08:00
|
|
|
|
2012-07-13 04:54:12 +08:00
|
|
|
test('test can instantiate a RedisPool object', function(){
|
2011-06-17 00:23:38 +08:00
|
|
|
assert.ok(redis_pool);
|
2012-07-13 04:54:12 +08:00
|
|
|
});
|
2011-06-17 00:23:38 +08:00
|
|
|
|
2012-07-13 04:54:12 +08:00
|
|
|
test('test pool object has an aquire function', function(){
|
|
|
|
assert.ok(_.includes(_.functions(redis_pool), 'acquire'));
|
|
|
|
});
|
2011-06-17 00:23:38 +08:00
|
|
|
|
2012-07-13 04:54:12 +08:00
|
|
|
test('test calling aquire returns a redis client object that can get/set', function(done){
|
2013-03-14 18:58:30 +08:00
|
|
|
redis_pool.acquire(0, function(err, client){
|
|
|
|
assert.ok(!err);
|
2012-06-02 04:13:41 +08:00
|
|
|
client.set("key","value");
|
2011-06-17 00:23:38 +08:00
|
|
|
client.get("key", function(err,data){
|
2012-07-13 04:54:12 +08:00
|
|
|
assert.equal(data, "value");
|
2012-06-02 04:13:41 +08:00
|
|
|
redis_pool.release(0, client);
|
2012-07-13 04:54:12 +08:00
|
|
|
done();
|
2012-06-02 04:13:41 +08:00
|
|
|
});
|
2011-06-17 00:23:38 +08:00
|
|
|
});
|
2012-07-13 04:54:12 +08:00
|
|
|
});
|
2011-06-17 00:23:38 +08:00
|
|
|
|
2012-07-13 04:54:12 +08:00
|
|
|
test('test calling aquire on another DB returns a redis client object that can get/set', function(done){
|
2013-03-14 18:58:30 +08:00
|
|
|
redis_pool.acquire("MYDATABASE", function(err, client){
|
|
|
|
assert.ok(!err);
|
2012-06-02 04:13:41 +08:00
|
|
|
client.set("key","value");
|
2011-06-17 00:23:38 +08:00
|
|
|
client.get("key", function(err,data){
|
2012-07-13 04:54:12 +08:00
|
|
|
assert.equal(data, "value");
|
2012-06-02 04:13:41 +08:00
|
|
|
redis_pool.release("MYDATABASE", client);
|
2013-03-14 18:58:30 +08:00
|
|
|
redis_pool.acquire("MYDATABASE", function(err, client){
|
|
|
|
assert.ok(!err);
|
2012-07-13 00:08:21 +08:00
|
|
|
client.get("key", function(err,data){
|
2012-07-13 04:54:12 +08:00
|
|
|
assert.equal(data, "value");
|
2012-07-13 00:08:21 +08:00
|
|
|
redis_pool.release("MYDATABASE", client);
|
2012-07-13 04:54:12 +08:00
|
|
|
done();
|
2012-07-13 00:08:21 +08:00
|
|
|
});
|
|
|
|
});
|
2011-06-17 00:23:38 +08:00
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2012-07-13 04:54:12 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|