fixed tests, and added getSortedSetUnion method to redis db, added test for new redis method

v1.18.x
Julian Lam 11 years ago
parent 840a56006c
commit 6e597a9cdb

@ -73,4 +73,33 @@ module.exports = function(redisClient, module) {
multi.exec(callback);
};
module.getSortedSetUnion = function(sets, start, stop, callback) {
// start and stop optional
if (typeof start === 'function') {
callback = start;
start = 0;
stop = -1;
} else if (typeof stop === 'function') {
callback = stop;
stop = -1;
}
var multi = redisClient.multi();
// zunionstore prep
sets.unshift(sets.length);
sets.unshift('temp');
multi.zunionstore.apply(multi, sets);
multi.zrange('temp', start, stop);
multi.del('temp');
multi.exec(function(err, results) {
if (!err && typeof callback === 'function') {
callback(null, results[1]);
} else if (err) {
callback(err);
}
});
}
};

@ -54,9 +54,10 @@ module.exports = function(app, middleware, controllers) {
});
app.get('/test', function(req, res) {
var privileges = require('../privileges');
privileges.topics.get(1299, 1, function(err, result) {
res.json(result);
var db = require('../database');
db.getSortedSetUnion(['uid:1:posts', 'uid:3:posts'], function(err, pids) {
console.log(err);
res.json(pids);
});
});
});

@ -23,6 +23,8 @@ module.exports = function(Topics) {
next(err);
});
}, callback);
} else {
callback();
}
};

@ -20,7 +20,7 @@ describe('Test database', function() {
}
function set(callback) {
db.set('testingStr', 'opppa gangastayla', function(err, data) {
db.set('testingStr', 'oppa gangnam style', function(err, data) {
callback(err, {'set': data});
});
}
@ -324,6 +324,12 @@ describe('Test database', function() {
});
}
function getSortedSetUnion(callback) {
db.getSortedSetUnion(['users:joindate', 'users:derp', 'users:postcount'], function(err, data) {
callback(err, {'sortedSetUnion': data});
});
}
var sortedSetTasks = [
sortedSetAdd,
sortedSetAdd,
@ -337,7 +343,8 @@ describe('Test database', function() {
sortedSetCount,
sortedSetScore,
sortedSetsScore,
getSortedSetRevRangeByScore
getSortedSetRevRangeByScore,
getSortedSetUnion
];
async.series(sortedSetTasks, function(err, results) {

@ -14,7 +14,7 @@ describe('Groups', function() {
},
function(next) {
// Create a new user
User.create({
User.create({
username: 'testuser',
email: 'b@c.com'
}, done);

@ -3,31 +3,42 @@
var assert = require('assert'),
db = require('../mocks/databasemock'),
topics = require('../src/topics'),
categories = require('../src/categories');
categories = require('../src/categories'),
User = require('../src/user');
describe('Topic\'s', function() {
var topic,
categoryObj;
before(function(done) {
var userData = {
username: 'John Smith',
password: 'swordfish',
email: 'john@example.com',
callback: undefined
};
categories.create({
name: 'Test Category',
description: 'Test category created by testing script',
icon: 'fa-check',
blockclass: 'category-blue',
order: '5'
}, function(err, category) {
categoryObj = category;
User.create({username: userData.username, password: userData.password, email: userData.email}, function(err, uid) {
categories.create({
name: 'Test Category',
description: 'Test category created by testing script',
icon: 'fa-check',
blockclass: 'category-blue',
order: '5'
}, function(err, category) {
categoryObj = category;
topic = {
userId: 1,
categoryId: categoryObj.cid,
title: 'Test Topic Title',
content: 'The content of test topic'
};
done();
topic = {
userId: uid,
categoryId: categoryObj.cid,
title: 'Test Topic Title',
content: 'The content of test topic'
};
done();
});
});
});
describe('.post', function() {

Loading…
Cancel
Save