| 
									
										
										
										
											2014-12-31 14:27:16 -05:00
										 |  |  | 'use strict'; | 
					
						
							| 
									
										
										
										
											2017-02-17 21:55:19 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-31 14:27:16 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-17 20:20:42 -07:00
										 |  |  | var	async = require('async'); | 
					
						
							|  |  |  | var assert = require('assert'); | 
					
						
							|  |  |  | var db = require('../mocks/databasemock'); | 
					
						
							| 
									
										
										
										
											2014-12-31 14:27:16 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | describe('Sorted Set methods', function () { | 
					
						
							|  |  |  | 	before(function (done) { | 
					
						
							| 
									
										
										
										
											2015-01-15 15:33:22 -05:00
										 |  |  | 		async.parallel([ | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			function (next) { | 
					
						
							| 
									
										
										
										
											2016-12-11 15:59:28 +01:00
										 |  |  | 				db.sortedSetAdd('sortedSetTest1', [1.1, 1.2, 1.3], ['value1', 'value2', 'value3'], next); | 
					
						
							| 
									
										
										
										
											2015-01-15 15:33:22 -05:00
										 |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			function (next) { | 
					
						
							| 
									
										
										
										
											2015-01-15 15:33:22 -05:00
										 |  |  | 				db.sortedSetAdd('sortedSetTest2', [1, 4], ['value1', 'value4'], next); | 
					
						
							|  |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			function (next) { | 
					
						
							| 
									
										
										
										
											2015-01-15 15:33:22 -05:00
										 |  |  | 				db.sortedSetAdd('sortedSetTest3', [2, 4], ['value2', 'value4'], next); | 
					
						
							| 
									
										
										
										
											2016-10-17 14:22:50 -04:00
										 |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2018-01-12 12:32:07 -06:00
										 |  |  | 			function (next) { | 
					
						
							|  |  |  | 				db.sortedSetAdd('sortedSetTest4', [1, 1, 2, 3, 5], ['b', 'a', 'd', 'e', 'c'], next); | 
					
						
							|  |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2016-10-17 14:22:50 -04:00
										 |  |  | 			function (next) { | 
					
						
							| 
									
										
										
										
											2016-10-17 16:35:33 -04:00
										 |  |  | 				db.sortedSetAdd('sortedSetLex', [0, 0, 0, 0], ['a', 'b', 'c', 'd'], next); | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 			}, | 
					
						
							| 
									
										
										
										
											2015-01-15 15:33:22 -05:00
										 |  |  | 		], done); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	describe('sortedSetAdd()', function () { | 
					
						
							|  |  |  | 		it('should add an element to a sorted set', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetAdd('sorted1', 1, 'value1', function (err) { | 
					
						
							| 
									
										
										
										
											2014-12-31 14:27:16 -05:00
										 |  |  | 				assert.equal(err, null); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 1); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		it('should add two elements to a sorted set', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetAdd('sorted2', [1, 2], ['value1', 'value2'], function (err) { | 
					
						
							| 
									
										
										
										
											2014-12-31 14:27:16 -05:00
										 |  |  | 				assert.equal(err, null); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 1); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-08-08 14:13:48 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		it('should gracefully handle adding the same element twice', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetAdd('sorted2', [1, 2], ['value1', 'value1'], function (err) { | 
					
						
							|  |  |  | 				assert.equal(err, null); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				db.sortedSetScore('sorted2', 'value1', function (err, score) { | 
					
						
							|  |  |  | 					assert.equal(err, null); | 
					
						
							|  |  |  | 					assert.equal(score, 2); | 
					
						
							|  |  |  | 					assert.equal(arguments.length, 2); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					done(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2019-02-11 11:23:18 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		it('should error if score is null', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetAdd('errorScore', null, 'value1', function (err) { | 
					
						
							|  |  |  | 				assert.equal(err.message, '[[error:invalid-score, null]]'); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should error if any score is undefined', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetAdd('errorScore', [1, undefined], ['value1', 'value2'], function (err) { | 
					
						
							|  |  |  | 				assert.equal(err.message, '[[error:invalid-score, undefined]]'); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should add null value as `null` string', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetAdd('nullValueZSet', 1, null, function (err) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				db.getSortedSetRange('nullValueZSet', 0, -1, function (err, values) { | 
					
						
							|  |  |  | 					assert.ifError(err); | 
					
						
							|  |  |  | 					assert.strictEqual(values[0], 'null'); | 
					
						
							|  |  |  | 					done(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2014-12-31 14:27:16 -05:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	describe('sortedSetsAdd()', function () { | 
					
						
							|  |  |  | 		it('should add an element to two sorted sets', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetsAdd(['sorted1', 'sorted2'], 3, 'value3', function (err) { | 
					
						
							| 
									
										
										
										
											2014-12-31 14:27:16 -05:00
										 |  |  | 				assert.equal(err, null); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 1); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2019-02-11 11:23:18 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-31 15:44:50 -04:00
										 |  |  | 		it('should add an element to two sorted sets with different scores', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetsAdd(['sorted1', 'sorted2'], [4, 5], 'value4', function (err) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				db.sortedSetsScore(['sorted1', 'sorted2'], 'value4', function (err, scores) { | 
					
						
							|  |  |  | 					assert.ifError(err); | 
					
						
							|  |  |  | 					assert.deepStrictEqual(scores, [4, 5]); | 
					
						
							|  |  |  | 					done(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should error if keys.length is different than scores.length', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetsAdd(['sorted1', 'sorted2'], [4], 'value4', function (err) { | 
					
						
							|  |  |  | 				assert.equal(err.message, '[[error:invalid-data]]'); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2019-02-11 11:23:18 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		it('should error if score is null', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetsAdd(['sorted1', 'sorted2'], null, 'value1', function (err) { | 
					
						
							|  |  |  | 				assert.equal(err.message, '[[error:invalid-score, null]]'); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2020-05-09 10:38:56 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		it('should error if scores has null', async function () { | 
					
						
							|  |  |  | 			let err; | 
					
						
							|  |  |  | 			try { | 
					
						
							|  |  |  | 				await db.sortedSetsAdd(['sorted1', 'sorted2'], [1, null], 'dontadd'); | 
					
						
							|  |  |  | 			} catch (_err) { | 
					
						
							|  |  |  | 				err = _err; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			assert.equal(err.message, '[[error:invalid-score, 1,]]'); | 
					
						
							|  |  |  | 			assert.strictEqual(await db.isSortedSetMember('sorted1', 'dontadd'), false); | 
					
						
							|  |  |  | 			assert.strictEqual(await db.isSortedSetMember('sorted2', 'dontadd'), false); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2014-12-31 14:27:16 -05:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-24 17:48:13 -04:00
										 |  |  | 	describe('sortedSetAddMulti()', function () { | 
					
						
							|  |  |  | 		it('should add elements into multiple sorted sets with different scores', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetAddBulk([ | 
					
						
							|  |  |  | 				['bulk1', 1, 'item1'], | 
					
						
							|  |  |  | 				['bulk2', 2, 'item1'], | 
					
						
							|  |  |  | 				['bulk2', 3, 'item2'], | 
					
						
							|  |  |  | 				['bulk3', 4, 'item3'], | 
					
						
							|  |  |  | 			], function (err) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 1); | 
					
						
							|  |  |  | 				db.getSortedSetRevRangeWithScores(['bulk1', 'bulk2', 'bulk3'], 0, -1, function (err, data) { | 
					
						
							|  |  |  | 					assert.ifError(err); | 
					
						
							|  |  |  | 					assert.deepStrictEqual(data, [{ value: 'item3', score: 4 }, | 
					
						
							|  |  |  | 						{ value: 'item2', score: 3 }, | 
					
						
							|  |  |  | 						{ value: 'item1', score: 2 }, | 
					
						
							|  |  |  | 						{ value: 'item1', score: 1 }]); | 
					
						
							|  |  |  | 					done(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 		it('should not error if data is undefined', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetAddBulk(undefined, function (err) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2020-05-09 10:38:56 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		it('should error if score is null', async function () { | 
					
						
							|  |  |  | 			let err; | 
					
						
							|  |  |  | 			try { | 
					
						
							|  |  |  | 				await db.sortedSetAddBulk([ | 
					
						
							|  |  |  | 					['bulk4', 0, 'dontadd'], | 
					
						
							|  |  |  | 					['bulk5', null, 'dontadd'], | 
					
						
							|  |  |  | 				]); | 
					
						
							|  |  |  | 			} catch (_err) { | 
					
						
							|  |  |  | 				err = _err; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			assert.equal(err.message, '[[error:invalid-score, null]]'); | 
					
						
							|  |  |  | 			assert.strictEqual(await db.isSortedSetMember('bulk4', 'dontadd'), false); | 
					
						
							|  |  |  | 			assert.strictEqual(await db.isSortedSetMember('bulk5', 'dontadd'), false); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2019-06-24 17:48:13 -04:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	describe('getSortedSetRange()', function () { | 
					
						
							|  |  |  | 		it('should return the lowest scored element', function (done) { | 
					
						
							|  |  |  | 			db.getSortedSetRange('sortedSetTest1', 0, 0, function (err, value) { | 
					
						
							| 
									
										
										
										
											2014-12-31 14:41:58 -05:00
										 |  |  | 				assert.equal(err, null); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							| 
									
										
										
										
											2016-08-12 02:59:19 +03:00
										 |  |  | 				assert.deepEqual(value, ['value1']); | 
					
						
							| 
									
										
										
										
											2014-12-31 14:41:58 -05:00
										 |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		it('should return elements sorted by score lowest to highest', function (done) { | 
					
						
							|  |  |  | 			db.getSortedSetRange('sortedSetTest1', 0, -1, function (err, values) { | 
					
						
							| 
									
										
										
										
											2014-12-31 14:41:58 -05:00
										 |  |  | 				assert.equal(err, null); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							| 
									
										
										
										
											2016-08-12 02:59:19 +03:00
										 |  |  | 				assert.deepEqual(values, ['value1', 'value2', 'value3']); | 
					
						
							| 
									
										
										
										
											2014-12-31 14:41:58 -05:00
										 |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-05-27 00:30:07 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		it('should return empty array if set does not exist', function (done) { | 
					
						
							|  |  |  | 			db.getSortedSetRange('doesnotexist', 0, -1, function (err, values) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert(Array.isArray(values)); | 
					
						
							|  |  |  | 				assert.equal(values.length, 0); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-12-07 20:43:02 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		it('should handle negative start/stop', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetAdd('negatives', [1, 2, 3, 4, 5], ['1', '2', '3', '4', '5'], function (err) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				db.getSortedSetRange('negatives', -2, -4, function (err, data) { | 
					
						
							|  |  |  | 					assert.ifError(err); | 
					
						
							|  |  |  | 					assert.deepEqual(data, []); | 
					
						
							|  |  |  | 					done(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should handle negative start/stop', function (done) { | 
					
						
							|  |  |  | 			db.getSortedSetRange('negatives', -4, -2, function (err, data) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.deepEqual(data, ['2', '3', '4']); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should handle negative start/stop', function (done) { | 
					
						
							|  |  |  | 			db.getSortedSetRevRange('negatives', -4, -2, function (err, data) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.deepEqual(data, ['4', '3', '2']); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should handle negative start/stop', function (done) { | 
					
						
							|  |  |  | 			db.getSortedSetRange('negatives', -5, -1, function (err, data) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.deepEqual(data, ['1', '2', '3', '4', '5']); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should handle negative start/stop', function (done) { | 
					
						
							|  |  |  | 			db.getSortedSetRange('negatives', 0, -2, function (err, data) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.deepEqual(data, ['1', '2', '3', '4']); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-11-11 15:39:17 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		it('should return empty array if keys is empty array', function (done) { | 
					
						
							|  |  |  | 			db.getSortedSetRange([], 0, -1, function (err, data) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.deepStrictEqual(data, []); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-11-25 19:08:38 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-26 21:55:49 -04:00
										 |  |  | 		it('should return duplicates if two sets have same elements', async function () { | 
					
						
							|  |  |  | 			await db.sortedSetAdd('dupezset1', [1, 2], ['value 1', 'value 2']); | 
					
						
							|  |  |  | 			await db.sortedSetAdd('dupezset2', [2, 3], ['value 2', 'value 3']); | 
					
						
							|  |  |  | 			const data = await db.getSortedSetRange(['dupezset1', 'dupezset2'], 0, -1); | 
					
						
							|  |  |  | 			assert.deepStrictEqual(data, ['value 1', 'value 2', 'value 2', 'value 3']); | 
					
						
							| 
									
										
										
										
											2018-11-25 19:08:38 -05:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2019-09-24 13:31:44 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		it('should return correct number of elements', async function () { | 
					
						
							|  |  |  | 			await db.sortedSetAdd('dupezset3', [1, 2, 3], ['value 1', 'value 2', 'value3']); | 
					
						
							|  |  |  | 			await db.sortedSetAdd('dupezset4', [0, 5], ['value 0', 'value5']); | 
					
						
							|  |  |  | 			const data = await db.getSortedSetRevRange(['dupezset3', 'dupezset4'], 0, 1); | 
					
						
							|  |  |  | 			assert.deepStrictEqual(data, ['value5', 'value3']); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2019-09-24 23:47:45 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		it('should work with big arrays (length > 100) ', async function () { | 
					
						
							|  |  |  | 			for (let i = 0; i < 400; i++) { | 
					
						
							|  |  |  | 				/* eslint-disable no-await-in-loop */ | 
					
						
							|  |  |  | 				const bulkAdd = []; | 
					
						
							|  |  |  | 				for (let k = 0; k < 100; k++) { | 
					
						
							|  |  |  | 					bulkAdd.push(['testzset' + i, 1000000 + k + (i * 100), k + (i * 100)]); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				await db.sortedSetAddBulk(bulkAdd); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			const keys = []; | 
					
						
							|  |  |  | 			for (let i = 0; i < 400; i++) { | 
					
						
							|  |  |  | 				keys.push('testzset' + i); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			let data = await db.getSortedSetRevRange(keys, 0, 3); | 
					
						
							|  |  |  | 			assert.deepStrictEqual(data, ['39999', '39998', '39997', '39996']); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			data = await db.getSortedSetRevRangeWithScores(keys, 0, 3); | 
					
						
							|  |  |  | 			assert.deepStrictEqual(data, [ | 
					
						
							|  |  |  | 				{ value: '39999', score: 1039999 }, | 
					
						
							|  |  |  | 				{ value: '39998', score: 1039998 }, | 
					
						
							|  |  |  | 				{ value: '39997', score: 1039997 }, | 
					
						
							|  |  |  | 				{ value: '39996', score: 1039996 }, | 
					
						
							|  |  |  | 			]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			data = await db.getSortedSetRevRange(keys, 0, -1); | 
					
						
							|  |  |  | 			assert.equal(data.length, 40000); | 
					
						
							| 
									
										
										
										
											2019-09-25 21:06:57 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			data = await db.getSortedSetRange(keys, 9998, 10002); | 
					
						
							|  |  |  | 			assert.deepStrictEqual(data, ['9998', '9999', '10000', '10001', '10002']); | 
					
						
							| 
									
										
										
										
											2019-09-24 23:47:45 -04:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2014-12-31 14:41:58 -05:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	describe('getSortedSetRevRange()', function () { | 
					
						
							|  |  |  | 		it('should return the highest scored element', function (done) { | 
					
						
							|  |  |  | 			db.getSortedSetRevRange('sortedSetTest1', 0, 0, function (err, value) { | 
					
						
							| 
									
										
										
										
											2014-12-31 14:41:58 -05:00
										 |  |  | 				assert.equal(err, null); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							| 
									
										
										
										
											2016-08-12 02:59:19 +03:00
										 |  |  | 				assert.deepEqual(value, ['value3']); | 
					
						
							| 
									
										
										
										
											2014-12-31 14:41:58 -05:00
										 |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		it('should return elements sorted by score highest to lowest', function (done) { | 
					
						
							|  |  |  | 			db.getSortedSetRevRange('sortedSetTest1', 0, -1, function (err, values) { | 
					
						
							| 
									
										
										
										
											2014-12-31 14:41:58 -05:00
										 |  |  | 				assert.equal(err, null); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							| 
									
										
										
										
											2016-08-12 02:59:19 +03:00
										 |  |  | 				assert.deepEqual(values, ['value3', 'value2', 'value1']); | 
					
						
							| 
									
										
										
										
											2014-12-31 14:41:58 -05:00
										 |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	describe('getSortedSetRangeWithScores()', function () { | 
					
						
							|  |  |  | 		it('should return array of elements sorted by score lowest to highest with scores', function (done) { | 
					
						
							|  |  |  | 			db.getSortedSetRangeWithScores('sortedSetTest1', 0, -1, function (err, values) { | 
					
						
							| 
									
										
										
										
											2014-12-31 14:41:58 -05:00
										 |  |  | 				assert.equal(err, null); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 				assert.deepEqual(values, [{ value: 'value1', score: 1.1 }, { value: 'value2', score: 1.2 }, { value: 'value3', score: 1.3 }]); | 
					
						
							| 
									
										
										
										
											2014-12-31 14:41:58 -05:00
										 |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	describe('getSortedSetRevRangeWithScores()', function () { | 
					
						
							|  |  |  | 		it('should return array of elements sorted by score highest to lowest with scores', function (done) { | 
					
						
							|  |  |  | 			db.getSortedSetRevRangeWithScores('sortedSetTest1', 0, -1, function (err, values) { | 
					
						
							| 
									
										
										
										
											2014-12-31 14:41:58 -05:00
										 |  |  | 				assert.equal(err, null); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 				assert.deepEqual(values, [{ value: 'value3', score: 1.3 }, { value: 'value2', score: 1.2 }, { value: 'value1', score: 1.1 }]); | 
					
						
							| 
									
										
										
										
											2014-12-31 14:41:58 -05:00
										 |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2014-12-31 14:27:16 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	describe('getSortedSetRangeByScore()', function () { | 
					
						
							|  |  |  | 		it('should get count elements with score between min max sorted by score lowest to highest', function (done) { | 
					
						
							| 
									
										
										
										
											2016-12-11 15:59:28 +01:00
										 |  |  | 			db.getSortedSetRangeByScore('sortedSetTest1', 0, -1, '-inf', 1.2, function (err, values) { | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 				assert.equal(err, null); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							| 
									
										
										
										
											2016-08-12 02:59:19 +03:00
										 |  |  | 				assert.deepEqual(values, ['value1', 'value2']); | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-05-27 00:30:07 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		it('should return empty array if set does not exist', function (done) { | 
					
						
							|  |  |  | 			db.getSortedSetRangeByScore('doesnotexist', 0, -1, '-inf', 0, function (err, values) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert(Array.isArray(values)); | 
					
						
							|  |  |  | 				assert.equal(values.length, 0); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-10-28 16:20:38 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-14 16:24:17 -05:00
										 |  |  | 		it('should return empty array if count is 0', function (done) { | 
					
						
							|  |  |  | 			db.getSortedSetRevRangeByScore('sortedSetTest1', 0, 0, '+inf', '-inf', function (err, values) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.deepEqual(values, []); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should return elements from 1 to end', function (done) { | 
					
						
							|  |  |  | 			db.getSortedSetRevRangeByScore('sortedSetTest1', 1, -1, '+inf', '-inf', function (err, values) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.deepEqual(values, ['value2', 'value1']); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-28 16:20:38 -04:00
										 |  |  | 		it('should return elements from 3 to last', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetAdd('partialZset', [1, 2, 3, 4, 5], ['value1', 'value2', 'value3', 'value4', 'value5'], function (err) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				db.getSortedSetRangeByScore('partialZset', 3, 10, '-inf', '+inf', function (err, data) { | 
					
						
							|  |  |  | 					assert.ifError(err); | 
					
						
							|  |  |  | 					assert.deepStrictEqual(data, ['value4', 'value5']); | 
					
						
							|  |  |  | 					done(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	describe('getSortedSetRevRangeByScore()', function () { | 
					
						
							|  |  |  | 		it('should get count elements with score between max min sorted by score highest to lowest', function (done) { | 
					
						
							| 
									
										
										
										
											2016-12-11 15:59:28 +01:00
										 |  |  | 			db.getSortedSetRevRangeByScore('sortedSetTest1', 0, -1, '+inf', 1.2, function (err, values) { | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 				assert.equal(err, null); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							| 
									
										
										
										
											2016-08-12 02:59:19 +03:00
										 |  |  | 				assert.deepEqual(values, ['value3', 'value2']); | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	describe('getSortedSetRangeByScoreWithScores()', function () { | 
					
						
							|  |  |  | 		it('should get count elements with score between min max sorted by score lowest to highest with scores', function (done) { | 
					
						
							| 
									
										
										
										
											2016-12-11 15:59:28 +01:00
										 |  |  | 			db.getSortedSetRangeByScoreWithScores('sortedSetTest1', 0, -1, '-inf', 1.2, function (err, values) { | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 				assert.equal(err, null); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 				assert.deepEqual(values, [{ value: 'value1', score: 1.1 }, { value: 'value2', score: 1.2 }]); | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	describe('getSortedSetRevRangeByScoreWithScores()', function () { | 
					
						
							|  |  |  | 		it('should get count elements with score between max min sorted by score highest to lowest', function (done) { | 
					
						
							| 
									
										
										
										
											2016-12-11 15:59:28 +01:00
										 |  |  | 			db.getSortedSetRevRangeByScoreWithScores('sortedSetTest1', 0, -1, '+inf', 1.2, function (err, values) { | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 				assert.equal(err, null); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 				assert.deepEqual(values, [{ value: 'value3', score: 1.3 }, { value: 'value2', score: 1.2 }]); | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2019-09-26 21:55:49 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		it('should work with an array of keys', async function () { | 
					
						
							|  |  |  | 			await db.sortedSetAddBulk([ | 
					
						
							|  |  |  | 				['byScoreWithScoresKeys1', 1, 'value1'], | 
					
						
							|  |  |  | 				['byScoreWithScoresKeys2', 2, 'value2'], | 
					
						
							|  |  |  | 			]); | 
					
						
							|  |  |  | 			const data = await db.getSortedSetRevRangeByScoreWithScores(['byScoreWithScoresKeys1', 'byScoreWithScoresKeys2'], 0, -1, 5, -5); | 
					
						
							|  |  |  | 			assert.deepStrictEqual(data, [{ value: 'value2', score: 2 }, { value: 'value1', score: 1 }]); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	describe('sortedSetCount()', function () { | 
					
						
							|  |  |  | 		it('should return 0 for a sorted set that does not exist', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetCount('doesnotexist', 0, 10, function (err, count) { | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 				assert.equal(err, null); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							|  |  |  | 				assert.equal(count, 0); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		it('should return number of elements between scores min max inclusive', function (done) { | 
					
						
							| 
									
										
										
										
											2016-12-11 15:59:28 +01:00
										 |  |  | 			db.sortedSetCount('sortedSetTest1', '-inf', 1.2, function (err, count) { | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 				assert.equal(err, null); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							|  |  |  | 				assert.equal(count, 2); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2015-03-06 15:21:00 -05:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2015-03-06 15:12:55 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		it('should return number of elements between scores -inf +inf inclusive', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetCount('sortedSetTest1', '-inf', '+inf', function (err, count) { | 
					
						
							| 
									
										
										
										
											2015-03-06 15:12:55 -05:00
										 |  |  | 				assert.equal(err, null); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							|  |  |  | 				assert.equal(count, 3); | 
					
						
							|  |  |  | 				done(); | 
					
						
							| 
									
										
										
										
											2015-03-06 15:21:00 -05:00
										 |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	describe('sortedSetCard()', function () { | 
					
						
							|  |  |  | 		it('should return 0 for a sorted set that does not exist', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetCard('doesnotexist', function (err, count) { | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 				assert.equal(err, null); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							|  |  |  | 				assert.equal(count, 0); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		it('should return number of elements in a sorted set', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetCard('sortedSetTest1', function (err, count) { | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 				assert.equal(err, null); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							|  |  |  | 				assert.equal(count, 3); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	describe('sortedSetsCard()', function () { | 
					
						
							|  |  |  | 		it('should return the number of elements in sorted sets', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetsCard(['sortedSetTest1', 'sortedSetTest2', 'doesnotexist'], function (err, counts) { | 
					
						
							| 
									
										
										
										
											2019-06-24 15:21:43 -04:00
										 |  |  | 				assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							| 
									
										
										
										
											2015-01-15 15:33:22 -05:00
										 |  |  | 				assert.deepEqual(counts, [3, 2, 0]); | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-12-07 16:50:35 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		it('should return empty array if keys is falsy', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetsCard(undefined, function (err, counts) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							|  |  |  | 				assert.deepEqual(counts, []); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should return empty array if keys is empty array', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetsCard([], function (err, counts) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							|  |  |  | 				assert.deepEqual(counts, []); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-24 15:21:43 -04:00
										 |  |  | 	describe('sortedSetsCardSum()', function () { | 
					
						
							|  |  |  | 		it('should return the total number of elements in sorted sets', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetsCardSum(['sortedSetTest1', 'sortedSetTest2', 'doesnotexist'], function (err, sum) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							|  |  |  | 				assert.equal(sum, 5); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should return 0 if keys is falsy', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetsCardSum(undefined, function (err, counts) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							|  |  |  | 				assert.deepEqual(counts, 0); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should return 0 if keys is empty array', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetsCardSum([], function (err, counts) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							|  |  |  | 				assert.deepEqual(counts, 0); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should return the total number of elements in sorted set', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetsCardSum('sortedSetTest1', function (err, sum) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							|  |  |  | 				assert.equal(sum, 3); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	describe('sortedSetRank()', function () { | 
					
						
							|  |  |  | 		it('should return falsy if sorted set does not exist', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetRank('doesnotexist', 'value1', function (err, rank) { | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 				assert.equal(err, null); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							|  |  |  | 				assert.equal(!!rank, false); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		it('should return falsy if element isnt in sorted set', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetRank('sortedSetTest1', 'value5', function (err, rank) { | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 				assert.equal(err, null); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							|  |  |  | 				assert.equal(!!rank, false); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		it('should return the rank of the element in the sorted set sorted by lowest to highest score', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetRank('sortedSetTest1', 'value1', function (err, rank) { | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 				assert.equal(err, null); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							|  |  |  | 				assert.equal(rank, 0); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-01-12 12:32:07 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		it('should return the rank sorted by the score and then the value (a)', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetRank('sortedSetTest4', 'a', function (err, rank) { | 
					
						
							|  |  |  | 				assert.equal(err, null); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							|  |  |  | 				assert.equal(rank, 0); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should return the rank sorted by the score and then the value (b)', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetRank('sortedSetTest4', 'b', function (err, rank) { | 
					
						
							|  |  |  | 				assert.equal(err, null); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							|  |  |  | 				assert.equal(rank, 1); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should return the rank sorted by the score and then the value (c)', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetRank('sortedSetTest4', 'c', function (err, rank) { | 
					
						
							|  |  |  | 				assert.equal(err, null); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							|  |  |  | 				assert.equal(rank, 4); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	describe('sortedSetRevRank()', function () { | 
					
						
							|  |  |  | 		it('should return falsy if sorted set doesnot exist', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetRevRank('doesnotexist', 'value1', function (err, rank) { | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 				assert.equal(err, null); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							|  |  |  | 				assert.equal(!!rank, false); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		it('should return falsy if element isnt in sorted set', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetRevRank('sortedSetTest1', 'value5', function (err, rank) { | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 				assert.equal(err, null); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							|  |  |  | 				assert.equal(!!rank, false); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		it('should return the rank of the element in the sorted set sorted by highest to lowest score', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetRevRank('sortedSetTest1', 'value1', function (err, rank) { | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 				assert.equal(err, null); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							|  |  |  | 				assert.equal(rank, 2); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	describe('sortedSetsRanks()', function () { | 
					
						
							|  |  |  | 		it('should return the ranks of values in sorted sets', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetsRanks(['sortedSetTest1', 'sortedSetTest2'], ['value1', 'value4'], function (err, ranks) { | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 				assert.equal(err, null); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							|  |  |  | 				assert.deepEqual(ranks, [0, 1]); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	describe('sortedSetRanks()', function () { | 
					
						
							|  |  |  | 		it('should return the ranks of values in a sorted set', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetRanks('sortedSetTest1', ['value2', 'value1', 'value3', 'value4'], function (err, ranks) { | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 				assert.equal(err, null); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							|  |  |  | 				assert.deepEqual(ranks, [1, 0, 2, null]); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2019-07-03 12:48:26 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		it('should return the ranks of values in a sorted set in reverse', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetRevRanks('sortedSetTest1', ['value2', 'value1', 'value3', 'value4'], function (err, ranks) { | 
					
						
							|  |  |  | 				assert.equal(err, null); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							|  |  |  | 				assert.deepEqual(ranks, [1, 2, 0, null]); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	describe('sortedSetScore()', function () { | 
					
						
							|  |  |  | 		it('should return falsy if sorted set does not exist', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetScore('doesnotexist', 'value1', function (err, score) { | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 				assert.equal(err, null); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							|  |  |  | 				assert.equal(!!score, false); | 
					
						
							| 
									
										
										
										
											2017-05-19 14:52:36 -04:00
										 |  |  | 				assert.strictEqual(score, null); | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		it('should return falsy if element is not in sorted set', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetScore('sortedSetTest1', 'value5', function (err, score) { | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 				assert.equal(err, null); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							|  |  |  | 				assert.equal(!!score, false); | 
					
						
							| 
									
										
										
										
											2017-05-19 14:52:36 -04:00
										 |  |  | 				assert.strictEqual(score, null); | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		it('should return the score of an element', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetScore('sortedSetTest1', 'value2', function (err, score) { | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 				assert.equal(err, null); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							| 
									
										
										
										
											2018-12-07 16:00:56 -05:00
										 |  |  | 				assert.strictEqual(score, 1.2); | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-04-13 16:36:02 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		it('should not error if key is undefined', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetScore(undefined, 1, function (err, score) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.strictEqual(score, null); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should not error if value is undefined', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetScore('sortedSetTest1', undefined, function (err, score) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.strictEqual(score, null); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	describe('sortedSetsScore()', function () { | 
					
						
							|  |  |  | 		it('should return the scores of value in sorted sets', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetsScore(['sortedSetTest1', 'sortedSetTest2', 'doesnotexist'], 'value1', function (err, scores) { | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 				assert.equal(err, null); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							| 
									
										
										
										
											2016-12-11 15:59:28 +01:00
										 |  |  | 				assert.deepEqual(scores, [1.1, 1, null]); | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-04-13 16:36:02 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		it('should return scores even if some keys are undefined', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetsScore(['sortedSetTest1', undefined, 'doesnotexist'], 'value1', function (err, scores) { | 
					
						
							|  |  |  | 				assert.equal(err, null); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							|  |  |  | 				assert.deepEqual(scores, [1.1, null, null]); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-12-14 16:24:17 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		it('should return empty array if keys is empty array', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetsScore([], 'value1', function (err, scores) { | 
					
						
							|  |  |  | 				assert.equal(err, null); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							|  |  |  | 				assert.deepEqual(scores, []); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	describe('sortedSetScores()', function () { | 
					
						
							|  |  |  | 		before(function (done) { | 
					
						
							| 
									
										
										
										
											2016-08-16 19:52:22 +03:00
										 |  |  | 			db.sortedSetAdd('zeroScore', 0, 'value1', done); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		it('should return 0 if score is 0', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetScores('zeroScore', ['value1'], function (err, scores) { | 
					
						
							| 
									
										
										
										
											2016-08-16 19:52:22 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2019-07-09 12:46:49 -04:00
										 |  |  | 				assert.strictEqual(scores[0], 0); | 
					
						
							| 
									
										
										
										
											2016-08-16 19:52:22 +03:00
										 |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		it('should return the scores of value in sorted sets', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetScores('sortedSetTest1', ['value2', 'value1', 'doesnotexist'], function (err, scores) { | 
					
						
							| 
									
										
										
										
											2018-12-07 16:00:56 -05:00
										 |  |  | 				assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							| 
									
										
										
										
											2018-12-07 16:00:56 -05:00
										 |  |  | 				assert.deepStrictEqual(scores, [1.2, 1.1, null]); | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-04-13 16:36:02 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		it('should return scores even if some values are undefined', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetScores('sortedSetTest1', ['value2', undefined, 'doesnotexist'], function (err, scores) { | 
					
						
							| 
									
										
										
										
											2018-12-07 16:00:56 -05:00
										 |  |  | 				assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2017-04-13 16:36:02 -04:00
										 |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							| 
									
										
										
										
											2018-12-07 16:00:56 -05:00
										 |  |  | 				assert.deepStrictEqual(scores, [1.2, null, null]); | 
					
						
							| 
									
										
										
										
											2017-04-13 16:36:02 -04:00
										 |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-12-07 16:00:56 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-17 18:56:09 -05:00
										 |  |  | 		it('should return empty array if values is an empty array', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetScores('sortedSetTest1', [], function (err, scores) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							|  |  |  | 				assert.deepStrictEqual(scores, []); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-07 16:00:56 -05:00
										 |  |  | 		it('should return scores properly', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetsScore(['zeroScore', 'sortedSetTest1', 'doesnotexist'], 'value1', function (err, scores) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							|  |  |  | 				assert.deepStrictEqual(scores, [0, 1.1, null]); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2018-12-07 16:19:47 -05:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	describe('isSortedSetMember()', function () { | 
					
						
							|  |  |  | 		before(function (done) { | 
					
						
							| 
									
										
										
										
											2015-04-20 23:26:02 -04:00
										 |  |  | 			db.sortedSetAdd('zeroscore', 0, 'itemwithzeroscore', done); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		it('should return false if sorted set does not exist', function (done) { | 
					
						
							|  |  |  | 			db.isSortedSetMember('doesnotexist', 'value1', function (err, isMember) { | 
					
						
							| 
									
										
										
										
											2016-10-25 19:14:49 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							|  |  |  | 				assert.equal(isMember, false); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		it('should return false if element is not in sorted set', function (done) { | 
					
						
							|  |  |  | 			db.isSortedSetMember('sorted2', 'value5', function (err, isMember) { | 
					
						
							| 
									
										
										
										
											2016-10-25 19:14:49 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							|  |  |  | 				assert.equal(isMember, false); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		it('should return true if element is in sorted set', function (done) { | 
					
						
							|  |  |  | 			db.isSortedSetMember('sortedSetTest1', 'value2', function (err, isMember) { | 
					
						
							| 
									
										
										
										
											2016-10-25 19:14:49 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							| 
									
										
										
										
											2016-10-25 19:14:49 +03:00
										 |  |  | 				assert.strictEqual(isMember, true); | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2015-04-20 23:26:02 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-09 12:46:49 -04:00
										 |  |  | 		it('should return true if element is in sorted set with score 0', function (done) { | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			db.isSortedSetMember('zeroscore', 'itemwithzeroscore', function (err, isMember) { | 
					
						
							| 
									
										
										
										
											2015-04-20 23:26:02 -04:00
										 |  |  | 				assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2016-10-25 19:14:49 +03:00
										 |  |  | 				assert.strictEqual(isMember, true); | 
					
						
							| 
									
										
										
										
											2015-04-20 23:26:02 -04:00
										 |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	describe('isSortedSetMembers()', function () { | 
					
						
							|  |  |  | 		it('should return an array of booleans indicating membership', function (done) { | 
					
						
							|  |  |  | 			db.isSortedSetMembers('sortedSetTest1', ['value1', 'value2', 'value5'], function (err, isMembers) { | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 				assert.equal(err, null); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							|  |  |  | 				assert.deepEqual(isMembers, [true, true, false]); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2019-07-09 12:46:49 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		it('should return true if element is in sorted set with score 0', function (done) { | 
					
						
							|  |  |  | 			db.isSortedSetMembers('zeroscore', ['itemwithzeroscore'], function (err, isMembers) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							|  |  |  | 				assert.deepEqual(isMembers, [true]); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	describe('isMemberOfSortedSets', function () { | 
					
						
							|  |  |  | 		it('should return true for members false for non members', function (done) { | 
					
						
							|  |  |  | 			db.isMemberOfSortedSets(['doesnotexist', 'sortedSetTest1', 'sortedSetTest2'], 'value2', function (err, isMembers) { | 
					
						
							| 
									
										
										
										
											2015-01-21 22:48:22 -05:00
										 |  |  | 				assert.equal(err, null); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							|  |  |  | 				assert.deepEqual(isMembers, [false, true, false]); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-12-12 11:15:34 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		it('should return empty array if keys is empty array', function (done) { | 
					
						
							|  |  |  | 			db.isMemberOfSortedSets([], 'value2', function (err, isMembers) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							|  |  |  | 				assert.deepEqual(isMembers, []); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2015-01-21 22:48:22 -05:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	describe('getSortedSetsMembers', function () { | 
					
						
							|  |  |  | 		it('should return members of multiple sorted sets', function (done) { | 
					
						
							|  |  |  | 			db.getSortedSetsMembers(['doesnotexist', 'sortedSetTest1'], function (err, sortedSets) { | 
					
						
							| 
									
										
										
										
											2015-01-21 22:48:22 -05:00
										 |  |  | 				assert.equal(err, null); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							|  |  |  | 				assert.deepEqual(sortedSets[0], []); | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 				sortedSets[0].forEach(function (element) { | 
					
						
							| 
									
										
										
										
											2015-01-21 22:48:22 -05:00
										 |  |  | 					assert.notEqual(['value1', 'value2', 'value3'].indexOf(element), -1); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	describe('sortedSetUnionCard', function () { | 
					
						
							|  |  |  | 		it('should return the number of elements in the union', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetUnionCard(['sortedSetTest2', 'sortedSetTest3'], function (err, count) { | 
					
						
							| 
									
										
										
										
											2016-09-09 13:19:14 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.equal(count, 3); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	describe('getSortedSetUnion()', function () { | 
					
						
							|  |  |  | 		it('should return an array of values from both sorted sets sorted by scores lowest to highest', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 			db.getSortedSetUnion({ sets: ['sortedSetTest2', 'sortedSetTest3'], start: 0, stop: -1 }, function (err, values) { | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 				assert.equal(err, null); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							| 
									
										
										
										
											2015-01-15 15:33:22 -05:00
										 |  |  | 				assert.deepEqual(values, ['value1', 'value2', 'value4']); | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-06-14 17:24:29 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		it('should return an array of values and scores from both sorted sets sorted by scores lowest to highest', function (done) { | 
					
						
							|  |  |  | 			db.getSortedSetUnion({ sets: ['sortedSetTest2', 'sortedSetTest3'], start: 0, stop: -1, withScores: true }, function (err, data) { | 
					
						
							|  |  |  | 				assert.equal(err, null); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							|  |  |  | 				assert.deepEqual(data, [{ value: 'value1', score: 1 }, { value: 'value2', score: 2 }, { value: 'value4', score: 8 }]); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	describe('getSortedSetRevUnion()', function () { | 
					
						
							|  |  |  | 		it('should return an array of values from both sorted sets sorted by scores highest to lowest', function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 			db.getSortedSetRevUnion({ sets: ['sortedSetTest2', 'sortedSetTest3'], start: 0, stop: -1 }, function (err, values) { | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 				assert.equal(err, null); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							| 
									
										
										
										
											2015-01-15 15:33:22 -05:00
										 |  |  | 				assert.deepEqual(values, ['value4', 'value2', 'value1']); | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	describe('sortedSetIncrBy()', function () { | 
					
						
							|  |  |  | 		it('should create a sorted set with a field set to 1', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetIncrBy('sortedIncr', 1, 'field1', function (err, newValue) { | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 				assert.equal(err, null); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							| 
									
										
										
										
											2016-10-25 19:14:49 +03:00
										 |  |  | 				assert.strictEqual(newValue, 1); | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 				db.sortedSetScore('sortedIncr', 'field1', function (err, score) { | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 					assert.equal(err, null); | 
					
						
							| 
									
										
										
										
											2016-10-25 19:14:49 +03:00
										 |  |  | 					assert.strictEqual(score, 1); | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 					done(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		it('should increment a field of a sorted set by 5', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetIncrBy('sortedIncr', 5, 'field1', function (err, newValue) { | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 				assert.equal(err, null); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							| 
									
										
										
										
											2016-10-25 19:14:49 +03:00
										 |  |  | 				assert.strictEqual(newValue, 6); | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 				db.sortedSetScore('sortedIncr', 'field1', function (err, score) { | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 					assert.equal(err, null); | 
					
						
							| 
									
										
										
										
											2016-10-25 19:14:49 +03:00
										 |  |  | 					assert.strictEqual(score, 6); | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 					done(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	describe('sortedSetRemove()', function () { | 
					
						
							|  |  |  | 		before(function (done) { | 
					
						
							| 
									
										
										
										
											2015-01-15 15:33:22 -05:00
										 |  |  | 			db.sortedSetAdd('sorted3', [1, 2], ['value1', 'value2'], done); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		it('should remove an element from a sorted set', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetRemove('sorted3', 'value2', function (err) { | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 				assert.equal(err, null); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 1); | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 				db.isSortedSetMember('sorted3', 'value2', function (err, isMember) { | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 					assert.equal(err, null); | 
					
						
							|  |  |  | 					assert.equal(isMember, false); | 
					
						
							|  |  |  | 					done(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-03-17 18:49:33 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		it('should remove multiple values from multiple keys', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetAdd('multiTest1', [1, 2, 3, 4], ['one', 'two', 'three', 'four'], function (err) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				db.sortedSetAdd('multiTest2', [3, 4, 5, 6], ['three', 'four', 'five', 'six'], function (err) { | 
					
						
							|  |  |  | 					assert.ifError(err); | 
					
						
							|  |  |  | 					db.sortedSetRemove(['multiTest1', 'multiTest2'], ['two', 'three', 'four', 'five', 'doesnt exist'], function (err) { | 
					
						
							|  |  |  | 						assert.ifError(err); | 
					
						
							|  |  |  | 						db.getSortedSetsMembers(['multiTest1', 'multiTest2'], function (err, members) { | 
					
						
							|  |  |  | 							assert.ifError(err); | 
					
						
							|  |  |  | 							assert.equal(members[0].length, 1); | 
					
						
							|  |  |  | 							assert.equal(members[1].length, 1); | 
					
						
							|  |  |  | 							assert.deepEqual(members, [['one'], ['six']]); | 
					
						
							|  |  |  | 							done(); | 
					
						
							|  |  |  | 						}); | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-19 00:22:54 -04:00
										 |  |  | 		it('should remove value from multiple keys', async function () { | 
					
						
							|  |  |  | 			await db.sortedSetAdd('multiTest3', [1, 2, 3, 4], ['one', 'two', 'three', 'four']); | 
					
						
							|  |  |  | 			await db.sortedSetAdd('multiTest4', [3, 4, 5, 6], ['three', 'four', 'five', 'six']); | 
					
						
							|  |  |  | 			await db.sortedSetRemove(['multiTest3', 'multiTest4'], 'three'); | 
					
						
							|  |  |  | 			assert.deepStrictEqual(await db.getSortedSetRange('multiTest3', 0, -1), ['one', 'two', 'four']); | 
					
						
							|  |  |  | 			assert.deepStrictEqual(await db.getSortedSetRange('multiTest4', 0, -1), ['four', 'five', 'six']); | 
					
						
							| 
									
										
										
										
											2018-03-17 18:49:33 -04:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-03-17 19:55:23 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		it('should remove multiple values from multiple keys', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetAdd('multiTest5', [1], ['one'], function (err) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				db.sortedSetAdd('multiTest6', [2], ['two'], function (err) { | 
					
						
							|  |  |  | 					assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2018-10-11 16:23:05 -04:00
										 |  |  | 					db.sortedSetAdd('multiTest7', [3], [333], function (err) { | 
					
						
							| 
									
										
										
										
											2018-03-17 19:55:23 -04:00
										 |  |  | 						assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2018-10-11 16:23:05 -04:00
										 |  |  | 						db.sortedSetRemove(['multiTest5', 'multiTest6', 'multiTest7'], ['one', 'two', 333], function (err) { | 
					
						
							| 
									
										
										
										
											2018-03-17 19:55:23 -04:00
										 |  |  | 							assert.ifError(err); | 
					
						
							|  |  |  | 							db.getSortedSetsMembers(['multiTest5', 'multiTest6', 'multiTest7'], function (err, members) { | 
					
						
							|  |  |  | 								assert.ifError(err); | 
					
						
							|  |  |  | 								assert.deepEqual(members, [[], [], []]); | 
					
						
							|  |  |  | 								done(); | 
					
						
							|  |  |  | 							}); | 
					
						
							|  |  |  | 						}); | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2019-07-09 12:46:49 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		it('should not remove anything if values is empty array', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetAdd('removeNothing', [1, 2, 3], ['val1', 'val2', 'val3'], function (err) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				db.sortedSetRemove('removeNothing', [], function (err) { | 
					
						
							|  |  |  | 					assert.ifError(err); | 
					
						
							|  |  |  | 					db.getSortedSetRange('removeNothing', 0, -1, function (err, data) { | 
					
						
							|  |  |  | 						assert.ifError(err); | 
					
						
							|  |  |  | 						assert.deepStrictEqual(data, ['val1', 'val2', 'val3']); | 
					
						
							|  |  |  | 						done(); | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2019-07-12 14:06:09 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		it('should do a bulk remove', async function () { | 
					
						
							|  |  |  | 			await db.sortedSetAddBulk([ | 
					
						
							|  |  |  | 				['bulkRemove1', 1, 'value1'], | 
					
						
							|  |  |  | 				['bulkRemove1', 2, 'value2'], | 
					
						
							|  |  |  | 				['bulkRemove2', 3, 'value2'], | 
					
						
							|  |  |  | 			]); | 
					
						
							|  |  |  | 			await db.sortedSetRemoveBulk([ | 
					
						
							|  |  |  | 				['bulkRemove1', 'value1'], | 
					
						
							|  |  |  | 				['bulkRemove1', 'value2'], | 
					
						
							|  |  |  | 				['bulkRemove2', 'value2'], | 
					
						
							|  |  |  | 			]); | 
					
						
							|  |  |  | 			const members = await db.getSortedSetsMembers(['bulkRemove1', 'bulkRemove2']); | 
					
						
							|  |  |  | 			assert.deepStrictEqual(members, [[], []]); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	describe('sortedSetsRemove()', function () { | 
					
						
							|  |  |  | 		before(function (done) { | 
					
						
							| 
									
										
										
										
											2015-01-15 15:33:22 -05:00
										 |  |  | 			async.parallel([ | 
					
						
							| 
									
										
										
										
											2017-02-18 01:31:47 -07:00
										 |  |  | 				async.apply(db.sortedSetAdd, 'sorted4', [1, 2], ['value1', 'value2']), | 
					
						
							|  |  |  | 				async.apply(db.sortedSetAdd, 'sorted5', [1, 2], ['value1', 'value3']), | 
					
						
							| 
									
										
										
										
											2015-01-15 15:33:22 -05:00
										 |  |  | 			], done); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		it('should remove element from multiple sorted sets', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetsRemove(['sorted4', 'sorted5'], 'value1', function (err) { | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 				assert.equal(err, null); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 1); | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 				db.sortedSetsScore(['sorted4', 'sorted5'], 'value1', function (err, scores) { | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 					assert.equal(err, null); | 
					
						
							| 
									
										
										
										
											2018-12-07 16:00:56 -05:00
										 |  |  | 					assert.deepStrictEqual(scores, [null, null]); | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 					done(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	describe('sortedSetsRemoveRangeByScore()', function () { | 
					
						
							|  |  |  | 		before(function (done) { | 
					
						
							| 
									
										
										
										
											2017-02-18 01:31:47 -07:00
										 |  |  | 			db.sortedSetAdd('sorted6', [1, 2, 3, 4, 5], ['value1', 'value2', 'value3', 'value4', 'value5'], done); | 
					
						
							| 
									
										
										
										
											2015-01-15 15:33:22 -05:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		it('should remove elements with scores between min max inclusive', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetsRemoveRangeByScore(['sorted6'], 4, 5, function (err) { | 
					
						
							| 
									
										
										
										
											2017-08-20 20:41:25 -04:00
										 |  |  | 				assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 				assert.equal(arguments.length, 1); | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 				db.getSortedSetRange('sorted6', 0, -1, function (err, values) { | 
					
						
							| 
									
										
										
										
											2017-08-20 20:41:25 -04:00
										 |  |  | 					assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2015-01-15 15:33:22 -05:00
										 |  |  | 					assert.deepEqual(values, ['value1', 'value2', 'value3']); | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 					done(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-08-20 20:41:25 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		it('should remove elements with if strin score is passed in', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetAdd('sortedForRemove', [11, 22, 33], ['value1', 'value2', 'value3'], function (err) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				db.sortedSetsRemoveRangeByScore(['sortedForRemove'], '22', '22', function (err) { | 
					
						
							|  |  |  | 					assert.ifError(err); | 
					
						
							|  |  |  | 					db.getSortedSetRange('sortedForRemove', 0, -1, function (err, values) { | 
					
						
							|  |  |  | 						assert.ifError(err); | 
					
						
							|  |  |  | 						assert.deepEqual(values, ['value1', 'value3']); | 
					
						
							|  |  |  | 						done(); | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	describe('getSortedSetIntersect', function () { | 
					
						
							|  |  |  | 		before(function (done) { | 
					
						
							| 
									
										
										
										
											2016-08-15 19:23:10 +03:00
										 |  |  | 			async.parallel([ | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 				function (next) { | 
					
						
							| 
									
										
										
										
											2017-02-18 01:31:47 -07:00
										 |  |  | 					db.sortedSetAdd('interSet1', [1, 2, 3], ['value1', 'value2', 'value3'], next); | 
					
						
							| 
									
										
										
										
											2016-08-15 19:23:10 +03:00
										 |  |  | 				}, | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 				function (next) { | 
					
						
							| 
									
										
										
										
											2017-02-18 01:31:47 -07:00
										 |  |  | 					db.sortedSetAdd('interSet2', [4, 5, 6], ['value2', 'value3', 'value5'], next); | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 				}, | 
					
						
							| 
									
										
										
										
											2016-08-15 19:23:10 +03:00
										 |  |  | 			], done); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		it('should return the intersection of two sets', function (done) { | 
					
						
							| 
									
										
										
										
											2016-08-15 19:23:10 +03:00
										 |  |  | 			db.getSortedSetIntersect({ | 
					
						
							|  |  |  | 				sets: ['interSet1', 'interSet2'], | 
					
						
							|  |  |  | 				start: 0, | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 				stop: -1, | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			}, function (err, data) { | 
					
						
							| 
									
										
										
										
											2016-08-15 19:23:10 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.deepEqual(['value2', 'value3'], data); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		it('should return the intersection of two sets with scores', function (done) { | 
					
						
							| 
									
										
										
										
											2016-08-15 19:23:10 +03:00
										 |  |  | 			db.getSortedSetIntersect({ | 
					
						
							|  |  |  | 				sets: ['interSet1', 'interSet2'], | 
					
						
							|  |  |  | 				start: 0, | 
					
						
							|  |  |  | 				stop: -1, | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 				withScores: true, | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			}, function (err, data) { | 
					
						
							| 
									
										
										
										
											2016-08-15 19:23:10 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 				assert.deepEqual([{ value: 'value2', score: 6 }, { value: 'value3', score: 8 }], data); | 
					
						
							| 
									
										
										
										
											2016-08-15 19:23:10 +03:00
										 |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-08 16:32:34 -05:00
										 |  |  | 		it('should return the reverse intersection of two sets', function (done) { | 
					
						
							|  |  |  | 			db.getSortedSetRevIntersect({ | 
					
						
							|  |  |  | 				sets: ['interSet1', 'interSet2'], | 
					
						
							|  |  |  | 				start: 0, | 
					
						
							|  |  |  | 				stop: 2, | 
					
						
							|  |  |  | 			}, function (err, data) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.deepEqual(['value3', 'value2'], data); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		it('should return the intersection of two sets with scores aggregate MIN', function (done) { | 
					
						
							| 
									
										
										
										
											2016-08-15 19:23:10 +03:00
										 |  |  | 			db.getSortedSetIntersect({ | 
					
						
							|  |  |  | 				sets: ['interSet1', 'interSet2'], | 
					
						
							|  |  |  | 				start: 0, | 
					
						
							|  |  |  | 				stop: -1, | 
					
						
							|  |  |  | 				withScores: true, | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 				aggregate: 'MIN', | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			}, function (err, data) { | 
					
						
							| 
									
										
										
										
											2016-08-15 19:23:10 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 				assert.deepEqual([{ value: 'value2', score: 2 }, { value: 'value3', score: 3 }], data); | 
					
						
							| 
									
										
										
										
											2016-08-15 19:23:10 +03:00
										 |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		it('should return the intersection of two sets with scores aggregate MAX', function (done) { | 
					
						
							| 
									
										
										
										
											2016-08-15 19:23:10 +03:00
										 |  |  | 			db.getSortedSetIntersect({ | 
					
						
							|  |  |  | 				sets: ['interSet1', 'interSet2'], | 
					
						
							|  |  |  | 				start: 0, | 
					
						
							|  |  |  | 				stop: -1, | 
					
						
							|  |  |  | 				withScores: true, | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 				aggregate: 'MAX', | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			}, function (err, data) { | 
					
						
							| 
									
										
										
										
											2016-08-15 19:23:10 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 				assert.deepEqual([{ value: 'value2', score: 4 }, { value: 'value3', score: 5 }], data); | 
					
						
							| 
									
										
										
										
											2016-08-15 19:23:10 +03:00
										 |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		it('should return the intersection with scores modified by weights', function (done) { | 
					
						
							| 
									
										
										
										
											2016-08-15 19:23:10 +03:00
										 |  |  | 			db.getSortedSetIntersect({ | 
					
						
							|  |  |  | 				sets: ['interSet1', 'interSet2'], | 
					
						
							|  |  |  | 				start: 0, | 
					
						
							|  |  |  | 				stop: -1, | 
					
						
							|  |  |  | 				withScores: true, | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 				weights: [1, 0.5], | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			}, function (err, data) { | 
					
						
							| 
									
										
										
										
											2016-08-15 19:23:10 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2017-02-18 12:30:49 -07:00
										 |  |  | 				assert.deepEqual([{ value: 'value2', score: 4 }, { value: 'value3', score: 5.5 }], data); | 
					
						
							| 
									
										
										
										
											2016-08-15 19:23:10 +03:00
										 |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		it('should return empty array if sets do not exist', function (done) { | 
					
						
							| 
									
										
										
										
											2016-08-15 19:23:10 +03:00
										 |  |  | 			db.getSortedSetIntersect({ | 
					
						
							|  |  |  | 				sets: ['interSet10', 'interSet12'], | 
					
						
							|  |  |  | 				start: 0, | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 				stop: -1, | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			}, function (err, data) { | 
					
						
							| 
									
										
										
										
											2016-08-15 19:23:10 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.equal(data.length, 0); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		it('should return empty array if one set does not exist', function (done) { | 
					
						
							| 
									
										
										
										
											2016-08-15 19:23:10 +03:00
										 |  |  | 			db.getSortedSetIntersect({ | 
					
						
							|  |  |  | 				sets: ['interSet1', 'interSet12'], | 
					
						
							|  |  |  | 				start: 0, | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 				stop: -1, | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			}, function (err, data) { | 
					
						
							| 
									
										
										
										
											2016-08-15 19:23:10 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.equal(data.length, 0); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2020-05-21 22:12:58 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		it('should return correct results if sorting by different zset', async function () { | 
					
						
							|  |  |  | 			await db.sortedSetAdd('bigzset', [1, 2, 3, 4, 5, 6], ['a', 'b', 'c', 'd', 'e', 'f']); | 
					
						
							|  |  |  | 			await db.sortedSetAdd('smallzset', [3, 2, 1], ['b', 'e', 'g']); | 
					
						
							|  |  |  | 			const data = await db.getSortedSetRevIntersect({ | 
					
						
							|  |  |  | 				sets: ['bigzset', 'smallzset'], | 
					
						
							|  |  |  | 				start: 0, | 
					
						
							|  |  |  | 				stop: 19, | 
					
						
							|  |  |  | 				weights: [1, 0], | 
					
						
							|  |  |  | 				withScores: true, | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 			assert.deepStrictEqual(data, [{ value: 'e', score: 5 }, { value: 'b', score: 2 }]); | 
					
						
							|  |  |  | 			const data2 = await db.getSortedSetRevIntersect({ | 
					
						
							|  |  |  | 				sets: ['bigzset', 'smallzset'], | 
					
						
							|  |  |  | 				start: 0, | 
					
						
							|  |  |  | 				stop: 19, | 
					
						
							|  |  |  | 				weights: [0, 1], | 
					
						
							|  |  |  | 				withScores: true, | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 			assert.deepStrictEqual(data2, [{ value: 'b', score: 3 }, { value: 'e', score: 2 }]); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should return correct results when intersecting big zsets', async function () { | 
					
						
							|  |  |  | 			const scores = []; | 
					
						
							|  |  |  | 			const values = []; | 
					
						
							|  |  |  | 			for (let i = 0; i < 30000; i++) { | 
					
						
							|  |  |  | 				scores.push((i + 1) * 1000); | 
					
						
							|  |  |  | 				values.push(String(i + 1)); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			await db.sortedSetAdd('verybigzset', scores, values); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			scores.length = 0; | 
					
						
							|  |  |  | 			values.length = 0; | 
					
						
							|  |  |  | 			for (let i = 15000; i < 45000; i++) { | 
					
						
							|  |  |  | 				scores.push((i + 1) * 1000); | 
					
						
							|  |  |  | 				values.push(String(i + 1)); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			await db.sortedSetAdd('anotherbigzset', scores, values); | 
					
						
							|  |  |  | 			const data = await db.getSortedSetRevIntersect({ | 
					
						
							|  |  |  | 				sets: ['verybigzset', 'anotherbigzset'], | 
					
						
							|  |  |  | 				start: 0, | 
					
						
							|  |  |  | 				stop: 3, | 
					
						
							|  |  |  | 				weights: [1, 0], | 
					
						
							|  |  |  | 				withScores: true, | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 			assert.deepStrictEqual(data, [ | 
					
						
							|  |  |  | 				{ value: '30000', score: 30000000 }, | 
					
						
							|  |  |  | 				{ value: '29999', score: 29999000 }, | 
					
						
							|  |  |  | 				{ value: '29998', score: 29998000 }, | 
					
						
							|  |  |  | 				{ value: '29997', score: 29997000 }, | 
					
						
							|  |  |  | 			]); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2016-08-15 19:23:10 +03:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 	describe('sortedSetIntersectCard', function () { | 
					
						
							|  |  |  | 		before(function (done) { | 
					
						
							| 
									
										
										
										
											2016-09-16 13:01:11 +03:00
										 |  |  | 			async.parallel([ | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 				function (next) { | 
					
						
							| 
									
										
										
										
											2016-09-16 13:01:11 +03:00
										 |  |  | 					db.sortedSetAdd('interCard1', [0, 0, 0], ['value1', 'value2', 'value3'], next); | 
					
						
							|  |  |  | 				}, | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 				function (next) { | 
					
						
							| 
									
										
										
										
											2016-09-16 13:01:11 +03:00
										 |  |  | 					db.sortedSetAdd('interCard2', [0, 0, 0], ['value2', 'value3', 'value4'], next); | 
					
						
							|  |  |  | 				}, | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 				function (next) { | 
					
						
							| 
									
										
										
										
											2016-09-16 13:01:11 +03:00
										 |  |  | 					db.sortedSetAdd('interCard3', [0, 0, 0], ['value3', 'value4', 'value5'], next); | 
					
						
							|  |  |  | 				}, | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 				function (next) { | 
					
						
							| 
									
										
										
										
											2016-09-16 13:01:11 +03:00
										 |  |  | 					db.sortedSetAdd('interCard4', [0, 0, 0], ['value4', 'value5', 'value6'], next); | 
					
						
							| 
									
										
										
										
											2017-02-17 19:31:21 -07:00
										 |  |  | 				}, | 
					
						
							| 
									
										
										
										
											2016-09-16 13:01:11 +03:00
										 |  |  | 			], done); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		it('should return # of elements in intersection', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetIntersectCard(['interCard1', 'interCard2', 'interCard3'], function (err, count) { | 
					
						
							| 
									
										
										
										
											2016-09-16 13:01:11 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.strictEqual(count, 1); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 		it('should return 0 if intersection is empty', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetIntersectCard(['interCard1', 'interCard4'], function (err, count) { | 
					
						
							| 
									
										
										
										
											2016-09-16 13:01:11 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.strictEqual(count, 0); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-17 14:22:50 -04:00
										 |  |  | 	describe('getSortedSetRangeByLex', function () { | 
					
						
							|  |  |  | 		it('should return an array of all values', function (done) { | 
					
						
							|  |  |  | 			db.getSortedSetRangeByLex('sortedSetLex', '-', '+', function (err, data) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.deepEqual(data, ['a', 'b', 'c', 'd']); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should return an array with an inclusive range by default', function (done) { | 
					
						
							|  |  |  | 			db.getSortedSetRangeByLex('sortedSetLex', 'a', 'd', function (err, data) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.deepEqual(data, ['a', 'b', 'c', 'd']); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should return an array with an inclusive range', function (done) { | 
					
						
							|  |  |  | 			db.getSortedSetRangeByLex('sortedSetLex', '[a', '[d', function (err, data) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.deepEqual(data, ['a', 'b', 'c', 'd']); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should return an array with an exclusive range', function (done) { | 
					
						
							|  |  |  | 			db.getSortedSetRangeByLex('sortedSetLex', '(a', '(d', function (err, data) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.deepEqual(data, ['b', 'c']); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should return an array limited to the first two values', function (done) { | 
					
						
							|  |  |  | 			db.getSortedSetRangeByLex('sortedSetLex', '-', '+', 0, 2, function (err, data) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.deepEqual(data, ['a', 'b']); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	describe('getSortedSetRevRangeByLex', function () { | 
					
						
							|  |  |  | 		it('should return an array of all values reversed', function (done) { | 
					
						
							|  |  |  | 			db.getSortedSetRevRangeByLex('sortedSetLex', '+', '-', function (err, data) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.deepEqual(data, ['d', 'c', 'b', 'a']); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should return an array with an inclusive range by default reversed', function (done) { | 
					
						
							|  |  |  | 			db.getSortedSetRevRangeByLex('sortedSetLex', 'd', 'a', function (err, data) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.deepEqual(data, ['d', 'c', 'b', 'a']); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should return an array with an inclusive range reversed', function (done) { | 
					
						
							|  |  |  | 			db.getSortedSetRevRangeByLex('sortedSetLex', '[d', '[a', function (err, data) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.deepEqual(data, ['d', 'c', 'b', 'a']); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should return an array with an exclusive range reversed', function (done) { | 
					
						
							|  |  |  | 			db.getSortedSetRevRangeByLex('sortedSetLex', '(d', '(a', function (err, data) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.deepEqual(data, ['c', 'b']); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should return an array limited to the first two values reversed', function (done) { | 
					
						
							|  |  |  | 			db.getSortedSetRevRangeByLex('sortedSetLex', '+', '-', 0, 2, function (err, data) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.deepEqual(data, ['d', 'c']); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	describe('sortedSetLexCount', function () { | 
					
						
							|  |  |  | 		it('should return the count of all values', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetLexCount('sortedSetLex', '-', '+', function (err, data) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.strictEqual(data, 4); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should return the count with an inclusive range by default', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetLexCount('sortedSetLex', 'a', 'd', function (err, data) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.strictEqual(data, 4); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should return the count with an inclusive range', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetLexCount('sortedSetLex', '[a', '[d', function (err, data) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.strictEqual(data, 4); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should return the count with an exclusive range', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetLexCount('sortedSetLex', '(a', '(d', function (err, data) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.strictEqual(data, 2); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	describe('sortedSetRemoveRangeByLex', function () { | 
					
						
							|  |  |  | 		before(function (done) { | 
					
						
							|  |  |  | 			db.sortedSetAdd('sortedSetLex2', [0, 0, 0, 0, 0, 0, 0], ['a', 'b', 'c', 'd', 'e', 'f', 'g'], done); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should remove an inclusive range by default', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetRemoveRangeByLex('sortedSetLex2', 'a', 'b', function (err) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 1); | 
					
						
							|  |  |  | 				db.getSortedSetRangeByLex('sortedSetLex2', '-', '+', function (err, data) { | 
					
						
							|  |  |  | 					assert.ifError(err); | 
					
						
							|  |  |  | 					assert.deepEqual(data, ['c', 'd', 'e', 'f', 'g']); | 
					
						
							|  |  |  | 					done(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should remove an inclusive range', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetRemoveRangeByLex('sortedSetLex2', '[c', '[d', function (err) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 1); | 
					
						
							|  |  |  | 				db.getSortedSetRangeByLex('sortedSetLex2', '-', '+', function (err, data) { | 
					
						
							|  |  |  | 					assert.ifError(err); | 
					
						
							|  |  |  | 					assert.deepEqual(data, ['e', 'f', 'g']); | 
					
						
							|  |  |  | 					done(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should remove an exclusive range', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetRemoveRangeByLex('sortedSetLex2', '(e', '(g', function (err) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 1); | 
					
						
							|  |  |  | 				db.getSortedSetRangeByLex('sortedSetLex2', '-', '+', function (err, data) { | 
					
						
							|  |  |  | 					assert.ifError(err); | 
					
						
							|  |  |  | 					assert.deepEqual(data, ['e', 'g']); | 
					
						
							|  |  |  | 					done(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should remove all values', function (done) { | 
					
						
							|  |  |  | 			db.sortedSetRemoveRangeByLex('sortedSetLex2', '-', '+', function (err) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 1); | 
					
						
							|  |  |  | 				db.getSortedSetRangeByLex('sortedSetLex2', '-', '+', function (err, data) { | 
					
						
							|  |  |  | 					assert.ifError(err); | 
					
						
							|  |  |  | 					assert.deepEqual(data, []); | 
					
						
							|  |  |  | 					done(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2014-12-31 14:27:16 -05:00
										 |  |  | }); |