| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-16 16:24:17 -05:00
										 |  |  | const async = require('async'); | 
					
						
							| 
									
										
										
										
											2021-02-04 00:06:15 -07:00
										 |  |  | const assert = require('assert'); | 
					
						
							|  |  |  | const db = require('../mocks/databasemock'); | 
					
						
							| 
									
										
										
										
											2014-12-31 14:27:16 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | describe('Sorted Set methods', () => { | 
					
						
							|  |  |  | 	before((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); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	describe('sortedSetScan', () => { | 
					
						
							| 
									
										
										
										
											2020-07-02 17:59:20 -04:00
										 |  |  | 		it('should find matches in sorted set containing substring', async () => { | 
					
						
							|  |  |  | 			await db.sortedSetAdd('scanzset', [1, 2, 3, 4, 5, 6], ['aaaa', 'bbbb', 'bbcc', 'ddd', 'dddd', 'fghbc']); | 
					
						
							|  |  |  | 			const data = await db.getSortedSetScan({ | 
					
						
							|  |  |  | 				key: 'scanzset', | 
					
						
							|  |  |  | 				match: '*bc*', | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 			assert(data.includes('bbcc')); | 
					
						
							|  |  |  | 			assert(data.includes('fghbc')); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should find matches in sorted set with scores', async () => { | 
					
						
							|  |  |  | 			const data = await db.getSortedSetScan({ | 
					
						
							|  |  |  | 				key: 'scanzset', | 
					
						
							|  |  |  | 				match: '*bc*', | 
					
						
							|  |  |  | 				withScores: true, | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 			data.sort((a, b) => a.score - b.score); | 
					
						
							|  |  |  | 			assert.deepStrictEqual(data, [{ value: 'bbcc', score: 3 }, { value: 'fghbc', score: 6 }]); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should find matches in sorted set with a limit', async () => { | 
					
						
							|  |  |  | 			await db.sortedSetAdd('scanzset2', [1, 2, 3, 4, 5, 6], ['aaab', 'bbbb', 'bbcb', 'ddb', 'dddd', 'fghbc']); | 
					
						
							|  |  |  | 			const data = await db.getSortedSetScan({ | 
					
						
							|  |  |  | 				key: 'scanzset2', | 
					
						
							|  |  |  | 				match: '*b*', | 
					
						
							|  |  |  | 				limit: 2, | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 			assert.equal(data.length, 2); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should work for special characters', async () => { | 
					
						
							|  |  |  | 			await db.sortedSetAdd('scanzset3', [1, 2, 3, 4, 5], ['aaab{', 'bbbb', 'bbcb{', 'ddb', 'dddd']); | 
					
						
							|  |  |  | 			const data = await db.getSortedSetScan({ | 
					
						
							|  |  |  | 				key: 'scanzset3', | 
					
						
							|  |  |  | 				match: '*b{', | 
					
						
							|  |  |  | 				limit: 2, | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 			assert(data.includes('aaab{')); | 
					
						
							|  |  |  | 			assert(data.includes('bbcb{')); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should find everything starting with string', async () => { | 
					
						
							|  |  |  | 			await db.sortedSetAdd('scanzset4', [1, 2, 3, 4, 5], ['aaab{', 'bbbb', 'bbcb', 'ddb', 'dddd']); | 
					
						
							|  |  |  | 			const data = await db.getSortedSetScan({ | 
					
						
							|  |  |  | 				key: 'scanzset4', | 
					
						
							|  |  |  | 				match: 'b*', | 
					
						
							|  |  |  | 				limit: 2, | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 			assert(data.includes('bbbb')); | 
					
						
							|  |  |  | 			assert(data.includes('bbcb')); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should find everything ending with string', async () => { | 
					
						
							|  |  |  | 			await db.sortedSetAdd('scanzset5', [1, 2, 3, 4, 5, 6], ['aaab{', 'bbbb', 'bbcb', 'ddb', 'dddd', 'adb']); | 
					
						
							|  |  |  | 			const data = await db.getSortedSetScan({ | 
					
						
							|  |  |  | 				key: 'scanzset5', | 
					
						
							|  |  |  | 				match: '*db', | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 			assert.equal(data.length, 2); | 
					
						
							|  |  |  | 			assert(data.includes('ddb')); | 
					
						
							|  |  |  | 			assert(data.includes('adb')); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	describe('sortedSetAdd()', () => { | 
					
						
							|  |  |  | 		it('should add an element to a sorted set', (done) => { | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			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(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should add two elements to a sorted set', (done) => { | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should gracefully handle adding the same element twice', (done) => { | 
					
						
							| 
									
										
										
										
											2018-08-08 14:13:48 -05:00
										 |  |  | 			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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should error if score is null', (done) => { | 
					
						
							|  |  |  | 			db.sortedSetAdd('errorScore', null, 'value1', (err) => { | 
					
						
							| 
									
										
										
										
											2019-02-11 11:23:18 -05:00
										 |  |  | 				assert.equal(err.message, '[[error:invalid-score, null]]'); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should error if any score is undefined', (done) => { | 
					
						
							|  |  |  | 			db.sortedSetAdd('errorScore', [1, undefined], ['value1', 'value2'], (err) => { | 
					
						
							| 
									
										
										
										
											2019-02-11 11:23:18 -05:00
										 |  |  | 				assert.equal(err.message, '[[error:invalid-score, undefined]]'); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should add null value as `null` string', (done) => { | 
					
						
							|  |  |  | 			db.sortedSetAdd('nullValueZSet', 1, null, (err) => { | 
					
						
							| 
									
										
										
										
											2019-02-11 11:23:18 -05:00
										 |  |  | 				assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 				db.getSortedSetRange('nullValueZSet', 0, -1, (err, values) => { | 
					
						
							| 
									
										
										
										
											2019-02-11 11:23:18 -05:00
										 |  |  | 					assert.ifError(err); | 
					
						
							|  |  |  | 					assert.strictEqual(values[0], 'null'); | 
					
						
							|  |  |  | 					done(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2014-12-31 14:27:16 -05:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	describe('sortedSetsAdd()', () => { | 
					
						
							|  |  |  | 		it('should add an element to two sorted sets', (done) => { | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should add an element to two sorted sets with different scores', (done) => { | 
					
						
							|  |  |  | 			db.sortedSetsAdd(['sorted1', 'sorted2'], [4, 5], 'value4', (err) => { | 
					
						
							| 
									
										
										
										
											2019-05-31 15:44:50 -04:00
										 |  |  | 				assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 				db.sortedSetsScore(['sorted1', 'sorted2'], 'value4', (err, scores) => { | 
					
						
							| 
									
										
										
										
											2019-05-31 15:44:50 -04:00
										 |  |  | 					assert.ifError(err); | 
					
						
							|  |  |  | 					assert.deepStrictEqual(scores, [4, 5]); | 
					
						
							|  |  |  | 					done(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should error if keys.length is different than scores.length', (done) => { | 
					
						
							|  |  |  | 			db.sortedSetsAdd(['sorted1', 'sorted2'], [4], 'value4', (err) => { | 
					
						
							| 
									
										
										
										
											2019-05-31 15:44:50 -04:00
										 |  |  | 				assert.equal(err.message, '[[error:invalid-data]]'); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2019-02-11 11:23:18 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should error if score is null', (done) => { | 
					
						
							|  |  |  | 			db.sortedSetsAdd(['sorted1', 'sorted2'], null, 'value1', (err) => { | 
					
						
							| 
									
										
										
										
											2019-02-11 11:23:18 -05:00
										 |  |  | 				assert.equal(err.message, '[[error:invalid-score, null]]'); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2020-05-09 10:38:56 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should error if scores has null', async () => { | 
					
						
							| 
									
										
										
										
											2020-05-09 10:38:56 -04:00
										 |  |  | 			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
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	describe('sortedSetAddMulti()', () => { | 
					
						
							|  |  |  | 		it('should add elements into multiple sorted sets with different scores', (done) => { | 
					
						
							| 
									
										
										
										
											2019-06-24 17:48:13 -04:00
										 |  |  | 			db.sortedSetAddBulk([ | 
					
						
							|  |  |  | 				['bulk1', 1, 'item1'], | 
					
						
							|  |  |  | 				['bulk2', 2, 'item1'], | 
					
						
							|  |  |  | 				['bulk2', 3, 'item2'], | 
					
						
							|  |  |  | 				['bulk3', 4, 'item3'], | 
					
						
							|  |  |  | 			], function (err) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 1); | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 				db.getSortedSetRevRangeWithScores(['bulk1', 'bulk2', 'bulk3'], 0, -1, (err, data) => { | 
					
						
							| 
									
										
										
										
											2019-06-24 17:48:13 -04:00
										 |  |  | 					assert.ifError(err); | 
					
						
							|  |  |  | 					assert.deepStrictEqual(data, [{ value: 'item3', score: 4 }, | 
					
						
							|  |  |  | 						{ value: 'item2', score: 3 }, | 
					
						
							|  |  |  | 						{ value: 'item1', score: 2 }, | 
					
						
							|  |  |  | 						{ value: 'item1', score: 1 }]); | 
					
						
							|  |  |  | 					done(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should not error if data is undefined', (done) => { | 
					
						
							|  |  |  | 			db.sortedSetAddBulk(undefined, (err) => { | 
					
						
							| 
									
										
										
										
											2019-06-24 17:48:13 -04:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2020-05-09 10:38:56 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should error if score is null', async () => { | 
					
						
							| 
									
										
										
										
											2020-05-09 10:38:56 -04:00
										 |  |  | 			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
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	describe('getSortedSetRange()', () => { | 
					
						
							|  |  |  | 		it('should return the lowest scored element', (done) => { | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			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(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return elements sorted by score lowest to highest', (done) => { | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return empty array if set does not exist', (done) => { | 
					
						
							|  |  |  | 			db.getSortedSetRange('doesnotexist', 0, -1, (err, values) => { | 
					
						
							| 
									
										
										
										
											2017-05-27 00:30:07 -04:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert(Array.isArray(values)); | 
					
						
							|  |  |  | 				assert.equal(values.length, 0); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-12-07 20:43:02 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should handle negative start/stop', (done) => { | 
					
						
							|  |  |  | 			db.sortedSetAdd('negatives', [1, 2, 3, 4, 5], ['1', '2', '3', '4', '5'], (err) => { | 
					
						
							| 
									
										
										
										
											2017-12-07 20:43:02 -05:00
										 |  |  | 				assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 				db.getSortedSetRange('negatives', -2, -4, (err, data) => { | 
					
						
							| 
									
										
										
										
											2017-12-07 20:43:02 -05:00
										 |  |  | 					assert.ifError(err); | 
					
						
							|  |  |  | 					assert.deepEqual(data, []); | 
					
						
							|  |  |  | 					done(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should handle negative start/stop', (done) => { | 
					
						
							|  |  |  | 			db.getSortedSetRange('negatives', -4, -2, (err, data) => { | 
					
						
							| 
									
										
										
										
											2017-12-07 20:43:02 -05:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.deepEqual(data, ['2', '3', '4']); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should handle negative start/stop', (done) => { | 
					
						
							|  |  |  | 			db.getSortedSetRevRange('negatives', -4, -2, (err, data) => { | 
					
						
							| 
									
										
										
										
											2017-12-07 20:43:02 -05:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.deepEqual(data, ['4', '3', '2']); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should handle negative start/stop', (done) => { | 
					
						
							|  |  |  | 			db.getSortedSetRange('negatives', -5, -1, (err, data) => { | 
					
						
							| 
									
										
										
										
											2017-12-07 20:43:02 -05:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.deepEqual(data, ['1', '2', '3', '4', '5']); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should handle negative start/stop', (done) => { | 
					
						
							|  |  |  | 			db.getSortedSetRange('negatives', 0, -2, (err, data) => { | 
					
						
							| 
									
										
										
										
											2017-12-07 20:43:02 -05:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.deepEqual(data, ['1', '2', '3', '4']); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-11-11 15:39:17 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return empty array if keys is empty array', (done) => { | 
					
						
							|  |  |  | 			db.getSortedSetRange([], 0, -1, (err, data) => { | 
					
						
							| 
									
										
										
										
											2018-11-11 15:39:17 -05:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.deepStrictEqual(data, []); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-11-25 19:08:38 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return duplicates if two sets have same elements', async () => { | 
					
						
							| 
									
										
										
										
											2019-09-26 21:55:49 -04:00
										 |  |  | 			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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return correct number of elements', async () => { | 
					
						
							| 
									
										
										
										
											2019-09-24 13:31:44 -04:00
										 |  |  | 			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 () { | 
					
						
							| 
									
										
										
										
											2021-08-30 10:23:38 -04:00
										 |  |  | 			this.timeout(100000); | 
					
						
							| 
									
										
										
										
											2020-05-21 22:20:01 -04:00
										 |  |  | 			const keys = []; | 
					
						
							| 
									
										
										
										
											2019-09-24 23:47:45 -04:00
										 |  |  | 			for (let i = 0; i < 400; i++) { | 
					
						
							|  |  |  | 				/* eslint-disable no-await-in-loop */ | 
					
						
							|  |  |  | 				const bulkAdd = []; | 
					
						
							| 
									
										
										
										
											2021-02-03 23:59:08 -07:00
										 |  |  | 				keys.push(`testzset${i}`); | 
					
						
							| 
									
										
										
										
											2019-09-24 23:47:45 -04:00
										 |  |  | 				for (let k = 0; k < 100; k++) { | 
					
						
							| 
									
										
										
										
											2021-02-03 23:59:08 -07:00
										 |  |  | 					bulkAdd.push([`testzset${i}`, 1000000 + k + (i * 100), k + (i * 100)]); | 
					
						
							| 
									
										
										
										
											2019-09-24 23:47:45 -04:00
										 |  |  | 				} | 
					
						
							|  |  |  | 				await db.sortedSetAddBulk(bulkAdd); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			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
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	describe('getSortedSetRevRange()', () => { | 
					
						
							|  |  |  | 		it('should return the highest scored element', (done) => { | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			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(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return elements sorted by score highest to lowest', (done) => { | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			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(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	describe('getSortedSetRangeWithScores()', () => { | 
					
						
							|  |  |  | 		it('should return array of elements sorted by score lowest to highest with scores', (done) => { | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			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(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	describe('getSortedSetRevRangeWithScores()', () => { | 
					
						
							|  |  |  | 		it('should return array of elements sorted by score highest to lowest with scores', (done) => { | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	describe('getSortedSetRangeByScore()', () => { | 
					
						
							|  |  |  | 		it('should get count elements with score between min max sorted by score lowest to highest', (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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return empty array if set does not exist', (done) => { | 
					
						
							|  |  |  | 			db.getSortedSetRangeByScore('doesnotexist', 0, -1, '-inf', 0, (err, values) => { | 
					
						
							| 
									
										
										
										
											2017-05-27 00:30:07 -04:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert(Array.isArray(values)); | 
					
						
							|  |  |  | 				assert.equal(values.length, 0); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2018-10-28 16:20:38 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return empty array if count is 0', (done) => { | 
					
						
							|  |  |  | 			db.getSortedSetRevRangeByScore('sortedSetTest1', 0, 0, '+inf', '-inf', (err, values) => { | 
					
						
							| 
									
										
										
										
											2018-12-14 16:24:17 -05:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.deepEqual(values, []); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return elements from 1 to end', (done) => { | 
					
						
							|  |  |  | 			db.getSortedSetRevRangeByScore('sortedSetTest1', 1, -1, '+inf', '-inf', (err, values) => { | 
					
						
							| 
									
										
										
										
											2018-12-14 16:24:17 -05:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.deepEqual(values, ['value2', 'value1']); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return elements from 3 to last', (done) => { | 
					
						
							|  |  |  | 			db.sortedSetAdd('partialZset', [1, 2, 3, 4, 5], ['value1', 'value2', 'value3', 'value4', 'value5'], (err) => { | 
					
						
							| 
									
										
										
										
											2018-10-28 16:20:38 -04:00
										 |  |  | 				assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 				db.getSortedSetRangeByScore('partialZset', 3, 10, '-inf', '+inf', (err, data) => { | 
					
						
							| 
									
										
										
										
											2018-10-28 16:20:38 -04:00
										 |  |  | 					assert.ifError(err); | 
					
						
							|  |  |  | 					assert.deepStrictEqual(data, ['value4', 'value5']); | 
					
						
							|  |  |  | 					done(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	describe('getSortedSetRevRangeByScore()', () => { | 
					
						
							|  |  |  | 		it('should get count elements with score between max min sorted by score highest to lowest', (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(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	describe('getSortedSetRangeByScoreWithScores()', () => { | 
					
						
							|  |  |  | 		it('should get count elements with score between min max sorted by score lowest to highest with scores', (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(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	describe('getSortedSetRevRangeByScoreWithScores()', () => { | 
					
						
							|  |  |  | 		it('should get count elements with score between max min sorted by score highest to lowest', (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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should work with an array of keys', async () => { | 
					
						
							| 
									
										
										
										
											2019-09-26 21:55:49 -04:00
										 |  |  | 			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
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	describe('sortedSetCount()', () => { | 
					
						
							|  |  |  | 		it('should return 0 for a sorted set that does not exist', (done) => { | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			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(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return number of elements between scores min max inclusive', (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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return number of elements between scores -inf +inf inclusive', (done) => { | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			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
										 |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	describe('sortedSetCard()', () => { | 
					
						
							|  |  |  | 		it('should return 0 for a sorted set that does not exist', (done) => { | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			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(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return number of elements in a sorted set', (done) => { | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			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(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	describe('sortedSetsCard()', () => { | 
					
						
							|  |  |  | 		it('should return the number of elements in sorted sets', (done) => { | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return empty array if keys is falsy', (done) => { | 
					
						
							| 
									
										
										
										
											2018-12-07 16:50:35 -05:00
										 |  |  | 			db.sortedSetsCard(undefined, function (err, counts) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							|  |  |  | 				assert.deepEqual(counts, []); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return empty array if keys is empty array', (done) => { | 
					
						
							| 
									
										
										
										
											2018-12-07 16:50:35 -05:00
										 |  |  | 			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
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	describe('sortedSetsCardSum()', () => { | 
					
						
							|  |  |  | 		it('should return the total number of elements in sorted sets', (done) => { | 
					
						
							| 
									
										
										
										
											2019-06-24 15:21:43 -04:00
										 |  |  | 			db.sortedSetsCardSum(['sortedSetTest1', 'sortedSetTest2', 'doesnotexist'], function (err, sum) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							|  |  |  | 				assert.equal(sum, 5); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return 0 if keys is falsy', (done) => { | 
					
						
							| 
									
										
										
										
											2019-06-24 15:21:43 -04:00
										 |  |  | 			db.sortedSetsCardSum(undefined, function (err, counts) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							|  |  |  | 				assert.deepEqual(counts, 0); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return 0 if keys is empty array', (done) => { | 
					
						
							| 
									
										
										
										
											2019-06-24 15:21:43 -04:00
										 |  |  | 			db.sortedSetsCardSum([], function (err, counts) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							|  |  |  | 				assert.deepEqual(counts, 0); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return the total number of elements in sorted set', (done) => { | 
					
						
							| 
									
										
										
										
											2019-06-24 15:21:43 -04:00
										 |  |  | 			db.sortedSetsCardSum('sortedSetTest1', function (err, sum) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							|  |  |  | 				assert.equal(sum, 3); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	describe('sortedSetRank()', () => { | 
					
						
							|  |  |  | 		it('should return falsy if sorted set does not exist', (done) => { | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			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(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return falsy if element isnt in sorted set', (done) => { | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			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(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return the rank of the element in the sorted set sorted by lowest to highest score', (done) => { | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return the rank sorted by the score and then the value (a)', (done) => { | 
					
						
							| 
									
										
										
										
											2018-01-12 12:32:07 -06:00
										 |  |  | 			db.sortedSetRank('sortedSetTest4', 'a', function (err, rank) { | 
					
						
							|  |  |  | 				assert.equal(err, null); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							|  |  |  | 				assert.equal(rank, 0); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return the rank sorted by the score and then the value (b)', (done) => { | 
					
						
							| 
									
										
										
										
											2018-01-12 12:32:07 -06:00
										 |  |  | 			db.sortedSetRank('sortedSetTest4', 'b', function (err, rank) { | 
					
						
							|  |  |  | 				assert.equal(err, null); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							|  |  |  | 				assert.equal(rank, 1); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return the rank sorted by the score and then the value (c)', (done) => { | 
					
						
							| 
									
										
										
										
											2018-01-12 12:32:07 -06:00
										 |  |  | 			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
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	describe('sortedSetRevRank()', () => { | 
					
						
							|  |  |  | 		it('should return falsy if sorted set doesnot exist', (done) => { | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			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(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return falsy if element isnt in sorted set', (done) => { | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			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(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return the rank of the element in the sorted set sorted by highest to lowest score', (done) => { | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			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(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	describe('sortedSetsRanks()', () => { | 
					
						
							|  |  |  | 		it('should return the ranks of values in sorted sets', (done) => { | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			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(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	describe('sortedSetRanks()', () => { | 
					
						
							|  |  |  | 		it('should return the ranks of values in a sorted set', (done) => { | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return the ranks of values in a sorted set in reverse', (done) => { | 
					
						
							| 
									
										
										
										
											2019-07-03 12:48:26 -04:00
										 |  |  | 			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
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	describe('sortedSetScore()', () => { | 
					
						
							|  |  |  | 		it('should return falsy if sorted set does not exist', (done) => { | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			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(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return falsy if element is not in sorted set', (done) => { | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			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(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return the score of an element', (done) => { | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should not error if key is undefined', (done) => { | 
					
						
							|  |  |  | 			db.sortedSetScore(undefined, 1, (err, score) => { | 
					
						
							| 
									
										
										
										
											2017-04-13 16:36:02 -04:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.strictEqual(score, null); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should not error if value is undefined', (done) => { | 
					
						
							|  |  |  | 			db.sortedSetScore('sortedSetTest1', undefined, (err, score) => { | 
					
						
							| 
									
										
										
										
											2017-04-13 16:36:02 -04:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.strictEqual(score, null); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	describe('sortedSetsScore()', () => { | 
					
						
							|  |  |  | 		it('should return the scores of value in sorted sets', (done) => { | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return scores even if some keys are undefined', (done) => { | 
					
						
							| 
									
										
										
										
											2017-04-13 16:36:02 -04:00
										 |  |  | 			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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return empty array if keys is empty array', (done) => { | 
					
						
							| 
									
										
										
										
											2018-12-14 16:24:17 -05:00
										 |  |  | 			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
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	describe('sortedSetScores()', () => { | 
					
						
							|  |  |  | 		before((done) => { | 
					
						
							| 
									
										
										
										
											2016-08-16 19:52:22 +03:00
										 |  |  | 			db.sortedSetAdd('zeroScore', 0, 'value1', done); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return 0 if score is 0', (done) => { | 
					
						
							|  |  |  | 			db.sortedSetScores('zeroScore', ['value1'], (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(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return the scores of value in sorted sets', (done) => { | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return scores even if some values are undefined', (done) => { | 
					
						
							| 
									
										
										
										
											2017-04-13 16:36:02 -04:00
										 |  |  | 			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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return empty array if values is an empty array', (done) => { | 
					
						
							| 
									
										
										
										
											2018-12-17 18:56:09 -05:00
										 |  |  | 			db.sortedSetScores('sortedSetTest1', [], function (err, scores) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 2); | 
					
						
							|  |  |  | 				assert.deepStrictEqual(scores, []); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return scores properly', (done) => { | 
					
						
							| 
									
										
										
										
											2018-12-07 16:00:56 -05:00
										 |  |  | 			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
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	describe('isSortedSetMember()', () => { | 
					
						
							|  |  |  | 		before((done) => { | 
					
						
							| 
									
										
										
										
											2015-04-20 23:26:02 -04:00
										 |  |  | 			db.sortedSetAdd('zeroscore', 0, 'itemwithzeroscore', done); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return false if sorted set does not exist', (done) => { | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			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(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return false if element is not in sorted set', (done) => { | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			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(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return true if element is in sorted set', (done) => { | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return true if element is in sorted set with score 0', (done) => { | 
					
						
							|  |  |  | 			db.isSortedSetMember('zeroscore', 'itemwithzeroscore', (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
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	describe('isSortedSetMembers()', () => { | 
					
						
							|  |  |  | 		it('should return an array of booleans indicating membership', (done) => { | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return true if element is in sorted set with score 0', (done) => { | 
					
						
							| 
									
										
										
										
											2019-07-09 12:46:49 -04:00
										 |  |  | 			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
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	describe('isMemberOfSortedSets', () => { | 
					
						
							|  |  |  | 		it('should return true for members false for non members', (done) => { | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return empty array if keys is empty array', (done) => { | 
					
						
							| 
									
										
										
										
											2018-12-12 11:15:34 -05:00
										 |  |  | 			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
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	describe('getSortedSetsMembers', () => { | 
					
						
							|  |  |  | 		it('should return members of a sorted set', async () => { | 
					
						
							| 
									
										
										
										
											2020-05-26 22:55:28 -04:00
										 |  |  | 			const result = await db.getSortedSetMembers('sortedSetTest1'); | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 			result.forEach((element) => { | 
					
						
							| 
									
										
										
										
											2020-05-26 22:55:28 -04:00
										 |  |  | 				assert(['value1', 'value2', 'value3'].includes(element)); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return members of multiple sorted sets', (done) => { | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			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], []); | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 				sortedSets[0].forEach((element) => { | 
					
						
							| 
									
										
										
										
											2015-01-21 22:48:22 -05:00
										 |  |  | 					assert.notEqual(['value1', 'value2', 'value3'].indexOf(element), -1); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	describe('sortedSetUnionCard', () => { | 
					
						
							|  |  |  | 		it('should return the number of elements in the union', (done) => { | 
					
						
							|  |  |  | 			db.sortedSetUnionCard(['sortedSetTest2', 'sortedSetTest3'], (err, count) => { | 
					
						
							| 
									
										
										
										
											2016-09-09 13:19:14 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.equal(count, 3); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	describe('getSortedSetUnion()', () => { | 
					
						
							|  |  |  | 		it('should return an array of values from both sorted sets sorted by scores lowest to highest', (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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return an array of values and scores from both sorted sets sorted by scores lowest to highest', (done) => { | 
					
						
							| 
									
										
										
										
											2018-06-14 17:24:29 -04:00
										 |  |  | 			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
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	describe('getSortedSetRevUnion()', () => { | 
					
						
							|  |  |  | 		it('should return an array of values from both sorted sets sorted by scores highest to lowest', (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(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2023-03-10 11:40:02 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		it('should return empty array if sets is empty', async () => { | 
					
						
							|  |  |  | 			const result = await db.getSortedSetRevUnion({ sets: [], start: 0, stop: -1 }); | 
					
						
							|  |  |  | 			assert.deepStrictEqual(result, []); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	describe('sortedSetIncrBy()', () => { | 
					
						
							|  |  |  | 		it('should create a sorted set with a field set to 1', (done) => { | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			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); | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 				db.sortedSetScore('sortedIncr', 'field1', (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(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should increment a field of a sorted set by 5', (done) => { | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			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); | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 				db.sortedSetScore('sortedIncr', 'field1', (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(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2021-11-30 19:59:47 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		it('should increment fields of sorted sets with a single call', async () => { | 
					
						
							|  |  |  | 			const data = await db.sortedSetIncrByBulk([ | 
					
						
							|  |  |  | 				['sortedIncrBulk1', 1, 'value1'], | 
					
						
							|  |  |  | 				['sortedIncrBulk2', 2, 'value2'], | 
					
						
							|  |  |  | 				['sortedIncrBulk3', 3, 'value3'], | 
					
						
							|  |  |  | 				['sortedIncrBulk3', 4, 'value4'], | 
					
						
							|  |  |  | 			]); | 
					
						
							|  |  |  | 			assert.deepStrictEqual(data, [1, 2, 3, 4]); | 
					
						
							|  |  |  | 			assert.deepStrictEqual( | 
					
						
							|  |  |  | 				await db.getSortedSetRangeWithScores('sortedIncrBulk1', 0, -1), | 
					
						
							|  |  |  | 				[{ value: 'value1', score: 1 }], | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 			assert.deepStrictEqual( | 
					
						
							|  |  |  | 				await db.getSortedSetRangeWithScores('sortedIncrBulk2', 0, -1), | 
					
						
							|  |  |  | 				[{ value: 'value2', score: 2 }], | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 			assert.deepStrictEqual( | 
					
						
							|  |  |  | 				await db.getSortedSetRangeWithScores('sortedIncrBulk3', 0, -1), | 
					
						
							|  |  |  | 				[ | 
					
						
							|  |  |  | 					{ value: 'value3', score: 3 }, | 
					
						
							|  |  |  | 					{ value: 'value4', score: 4 }, | 
					
						
							|  |  |  | 				], | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		it('should increment the same field', async () => { | 
					
						
							|  |  |  | 			const data1 = await db.sortedSetIncrByBulk([ | 
					
						
							|  |  |  | 				['sortedIncrBulk5', 5, 'value5'], | 
					
						
							|  |  |  | 			]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			const data2 = await db.sortedSetIncrByBulk([ | 
					
						
							|  |  |  | 				['sortedIncrBulk5', 5, 'value5'], | 
					
						
							|  |  |  | 			]); | 
					
						
							|  |  |  | 			assert.deepStrictEqual( | 
					
						
							|  |  |  | 				await db.getSortedSetRangeWithScores('sortedIncrBulk5', 0, -1), | 
					
						
							|  |  |  | 				[ | 
					
						
							|  |  |  | 					{ value: 'value5', score: 10 }, | 
					
						
							|  |  |  | 				], | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	describe('sortedSetRemove()', () => { | 
					
						
							|  |  |  | 		before((done) => { | 
					
						
							| 
									
										
										
										
											2015-01-15 15:33:22 -05:00
										 |  |  | 			db.sortedSetAdd('sorted3', [1, 2], ['value1', 'value2'], done); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should remove an element from a sorted set', (done) => { | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			db.sortedSetRemove('sorted3', 'value2', function (err) { | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 				assert.equal(err, null); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 1); | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 				db.isSortedSetMember('sorted3', 'value2', (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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-07 17:16:50 -05:00
										 |  |  | 		it('should not think the sorted set exists if the last element is removed', async () => { | 
					
						
							|  |  |  | 			await db.sortedSetRemove('sorted3', 'value1'); | 
					
						
							|  |  |  | 			assert.strictEqual(await db.exists('sorted3'), false); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should remove multiple values from multiple keys', (done) => { | 
					
						
							|  |  |  | 			db.sortedSetAdd('multiTest1', [1, 2, 3, 4], ['one', 'two', 'three', 'four'], (err) => { | 
					
						
							| 
									
										
										
										
											2018-03-17 18:49:33 -04:00
										 |  |  | 				assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 				db.sortedSetAdd('multiTest2', [3, 4, 5, 6], ['three', 'four', 'five', 'six'], (err) => { | 
					
						
							| 
									
										
										
										
											2018-03-17 18:49:33 -04:00
										 |  |  | 					assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 					db.sortedSetRemove(['multiTest1', 'multiTest2'], ['two', 'three', 'four', 'five', 'doesnt exist'], (err) => { | 
					
						
							| 
									
										
										
										
											2018-03-17 18:49:33 -04:00
										 |  |  | 						assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 						db.getSortedSetsMembers(['multiTest1', 'multiTest2'], (err, members) => { | 
					
						
							| 
									
										
										
										
											2018-03-17 18:49:33 -04:00
										 |  |  | 							assert.ifError(err); | 
					
						
							|  |  |  | 							assert.equal(members[0].length, 1); | 
					
						
							|  |  |  | 							assert.equal(members[1].length, 1); | 
					
						
							|  |  |  | 							assert.deepEqual(members, [['one'], ['six']]); | 
					
						
							|  |  |  | 							done(); | 
					
						
							|  |  |  | 						}); | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should remove value from multiple keys', async () => { | 
					
						
							| 
									
										
										
										
											2020-05-19 00:22:54 -04:00
										 |  |  | 			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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should remove multiple values from multiple keys', (done) => { | 
					
						
							|  |  |  | 			db.sortedSetAdd('multiTest5', [1], ['one'], (err) => { | 
					
						
							| 
									
										
										
										
											2018-03-17 19:55:23 -04:00
										 |  |  | 				assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 				db.sortedSetAdd('multiTest6', [2], ['two'], (err) => { | 
					
						
							| 
									
										
										
										
											2018-03-17 19:55:23 -04:00
										 |  |  | 					assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 					db.sortedSetAdd('multiTest7', [3], [333], (err) => { | 
					
						
							| 
									
										
										
										
											2018-03-17 19:55:23 -04:00
										 |  |  | 						assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 						db.sortedSetRemove(['multiTest5', 'multiTest6', 'multiTest7'], ['one', 'two', 333], (err) => { | 
					
						
							| 
									
										
										
										
											2018-03-17 19:55:23 -04:00
										 |  |  | 							assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 							db.getSortedSetsMembers(['multiTest5', 'multiTest6', 'multiTest7'], (err, members) => { | 
					
						
							| 
									
										
										
										
											2018-03-17 19:55:23 -04:00
										 |  |  | 								assert.ifError(err); | 
					
						
							|  |  |  | 								assert.deepEqual(members, [[], [], []]); | 
					
						
							|  |  |  | 								done(); | 
					
						
							|  |  |  | 							}); | 
					
						
							|  |  |  | 						}); | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2019-07-09 12:46:49 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should not remove anything if values is empty array', (done) => { | 
					
						
							|  |  |  | 			db.sortedSetAdd('removeNothing', [1, 2, 3], ['val1', 'val2', 'val3'], (err) => { | 
					
						
							| 
									
										
										
										
											2019-07-09 12:46:49 -04:00
										 |  |  | 				assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 				db.sortedSetRemove('removeNothing', [], (err) => { | 
					
						
							| 
									
										
										
										
											2019-07-09 12:46:49 -04:00
										 |  |  | 					assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 					db.getSortedSetRange('removeNothing', 0, -1, (err, data) => { | 
					
						
							| 
									
										
										
										
											2019-07-09 12:46:49 -04:00
										 |  |  | 						assert.ifError(err); | 
					
						
							|  |  |  | 						assert.deepStrictEqual(data, ['val1', 'val2', 'val3']); | 
					
						
							|  |  |  | 						done(); | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2019-07-12 14:06:09 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should do a bulk remove', async () => { | 
					
						
							| 
									
										
										
										
											2019-07-12 14:06:09 -04:00
										 |  |  | 			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, [[], []]); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2021-10-01 19:36:42 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		it('should not remove wrong elements in bulk remove', async () => { | 
					
						
							|  |  |  | 			await db.sortedSetAddBulk([ | 
					
						
							|  |  |  | 				['bulkRemove4', 1, 'value1'], | 
					
						
							|  |  |  | 				['bulkRemove4', 2, 'value2'], | 
					
						
							|  |  |  | 				['bulkRemove4', 3, 'value4'], | 
					
						
							|  |  |  | 				['bulkRemove5', 1, 'value1'], | 
					
						
							|  |  |  | 				['bulkRemove5', 2, 'value2'], | 
					
						
							|  |  |  | 				['bulkRemove5', 3, 'value3'], | 
					
						
							|  |  |  | 			]); | 
					
						
							|  |  |  | 			await db.sortedSetRemoveBulk([ | 
					
						
							|  |  |  | 				['bulkRemove4', 'value1'], | 
					
						
							|  |  |  | 				['bulkRemove4', 'value3'], | 
					
						
							|  |  |  | 				['bulkRemove5', 'value1'], | 
					
						
							|  |  |  | 				['bulkRemove5', 'value4'], | 
					
						
							|  |  |  | 			]); | 
					
						
							|  |  |  | 			const members = await Promise.all([ | 
					
						
							|  |  |  | 				db.getSortedSetRange('bulkRemove4', 0, -1), | 
					
						
							|  |  |  | 				db.getSortedSetRange('bulkRemove5', 0, -1), | 
					
						
							|  |  |  | 			]); | 
					
						
							|  |  |  | 			assert.deepStrictEqual(members[0], ['value2', 'value4']); | 
					
						
							|  |  |  | 			assert.deepStrictEqual(members[1], ['value2', 'value3']); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	describe('sortedSetsRemove()', () => { | 
					
						
							|  |  |  | 		before((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); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should remove element from multiple sorted sets', (done) => { | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			db.sortedSetsRemove(['sorted4', 'sorted5'], 'value1', function (err) { | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 				assert.equal(err, null); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 1); | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 				db.sortedSetsScore(['sorted4', 'sorted5'], 'value1', (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(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	describe('sortedSetsRemoveRangeByScore()', () => { | 
					
						
							|  |  |  | 		before((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
										 |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should remove elements with scores between min max inclusive', (done) => { | 
					
						
							| 
									
										
										
										
											2016-10-13 11:43:39 +02:00
										 |  |  | 			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); | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 				db.getSortedSetRange('sorted6', 0, -1, (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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should remove elements with if strin score is passed in', (done) => { | 
					
						
							|  |  |  | 			db.sortedSetAdd('sortedForRemove', [11, 22, 33], ['value1', 'value2', 'value3'], (err) => { | 
					
						
							| 
									
										
										
										
											2017-08-20 20:41:25 -04:00
										 |  |  | 				assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 				db.sortedSetsRemoveRangeByScore(['sortedForRemove'], '22', '22', (err) => { | 
					
						
							| 
									
										
										
										
											2017-08-20 20:41:25 -04:00
										 |  |  | 					assert.ifError(err); | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 					db.getSortedSetRange('sortedForRemove', 0, -1, (err, values) => { | 
					
						
							| 
									
										
										
										
											2017-08-20 20:41:25 -04:00
										 |  |  | 						assert.ifError(err); | 
					
						
							|  |  |  | 						assert.deepEqual(values, ['value1', 'value3']); | 
					
						
							|  |  |  | 						done(); | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2014-12-31 15:52:52 -05:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	describe('getSortedSetIntersect', () => { | 
					
						
							|  |  |  | 		before((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); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return the intersection of two sets', (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, | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 			}, (err, data) => { | 
					
						
							| 
									
										
										
										
											2016-08-15 19:23:10 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.deepEqual(['value2', 'value3'], data); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return the intersection of two sets with scores', (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, | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 			}, (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(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return the reverse intersection of two sets', (done) => { | 
					
						
							| 
									
										
										
										
											2017-11-08 16:32:34 -05:00
										 |  |  | 			db.getSortedSetRevIntersect({ | 
					
						
							|  |  |  | 				sets: ['interSet1', 'interSet2'], | 
					
						
							|  |  |  | 				start: 0, | 
					
						
							|  |  |  | 				stop: 2, | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 			}, (err, data) => { | 
					
						
							| 
									
										
										
										
											2017-11-08 16:32:34 -05:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.deepEqual(['value3', 'value2'], data); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return the intersection of two sets with scores aggregate MIN', (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', | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 			}, (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(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return the intersection of two sets with scores aggregate MAX', (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', | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 			}, (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(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return the intersection with scores modified by weights', (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], | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 			}, (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(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return empty array if sets do not exist', (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, | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 			}, (err, data) => { | 
					
						
							| 
									
										
										
										
											2016-08-15 19:23:10 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.equal(data.length, 0); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return empty array if one set does not exist', (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, | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 			}, (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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return correct results if sorting by different zset', async () => { | 
					
						
							| 
									
										
										
										
											2020-05-21 22:12:58 -04:00
										 |  |  | 			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 }]); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return correct results when intersecting big zsets', async () => { | 
					
						
							| 
									
										
										
										
											2020-05-21 22:12:58 -04:00
										 |  |  | 			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
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	describe('sortedSetIntersectCard', () => { | 
					
						
							|  |  |  | 		before((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); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return # of elements in intersection', (done) => { | 
					
						
							|  |  |  | 			db.sortedSetIntersectCard(['interCard1', 'interCard2', 'interCard3'], (err, count) => { | 
					
						
							| 
									
										
										
										
											2016-09-16 13:01:11 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.strictEqual(count, 1); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return 0 if intersection is empty', (done) => { | 
					
						
							|  |  |  | 			db.sortedSetIntersectCard(['interCard1', 'interCard4'], (err, count) => { | 
					
						
							| 
									
										
										
										
											2016-09-16 13:01:11 +03:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.strictEqual(count, 0); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	describe('getSortedSetRangeByLex', () => { | 
					
						
							|  |  |  | 		it('should return an array of all values', (done) => { | 
					
						
							|  |  |  | 			db.getSortedSetRangeByLex('sortedSetLex', '-', '+', (err, data) => { | 
					
						
							| 
									
										
										
										
											2016-10-17 14:22:50 -04:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.deepEqual(data, ['a', 'b', 'c', 'd']); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return an array with an inclusive range by default', (done) => { | 
					
						
							|  |  |  | 			db.getSortedSetRangeByLex('sortedSetLex', 'a', 'd', (err, data) => { | 
					
						
							| 
									
										
										
										
											2016-10-17 14:22:50 -04:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.deepEqual(data, ['a', 'b', 'c', 'd']); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return an array with an inclusive range', (done) => { | 
					
						
							|  |  |  | 			db.getSortedSetRangeByLex('sortedSetLex', '[a', '[d', (err, data) => { | 
					
						
							| 
									
										
										
										
											2016-10-17 14:22:50 -04:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.deepEqual(data, ['a', 'b', 'c', 'd']); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return an array with an exclusive range', (done) => { | 
					
						
							|  |  |  | 			db.getSortedSetRangeByLex('sortedSetLex', '(a', '(d', (err, data) => { | 
					
						
							| 
									
										
										
										
											2016-10-17 14:22:50 -04:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.deepEqual(data, ['b', 'c']); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return an array limited to the first two values', (done) => { | 
					
						
							|  |  |  | 			db.getSortedSetRangeByLex('sortedSetLex', '-', '+', 0, 2, (err, data) => { | 
					
						
							| 
									
										
										
										
											2016-10-17 14:22:50 -04:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.deepEqual(data, ['a', 'b']); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2020-09-11 21:12:49 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return correct result', async () => { | 
					
						
							| 
									
										
										
										
											2020-09-11 21:12:49 -04:00
										 |  |  | 			await db.sortedSetAdd('sortedSetLexSearch', [0, 0, 0], ['baris:usakli:1', 'baris usakli:2', 'baris soner:3']); | 
					
						
							|  |  |  | 			const query = 'baris:'; | 
					
						
							|  |  |  | 			const min = query; | 
					
						
							| 
									
										
										
										
											2022-03-31 19:49:56 +02:00
										 |  |  | 			const max = query.slice(0, -1) + String.fromCharCode(query.charCodeAt(query.length - 1) + 1); | 
					
						
							| 
									
										
										
										
											2020-09-11 21:12:49 -04:00
										 |  |  | 			const result = await db.getSortedSetRangeByLex('sortedSetLexSearch', min, max, 0, -1); | 
					
						
							|  |  |  | 			assert.deepStrictEqual(result, ['baris:usakli:1']); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2016-10-17 14:22:50 -04:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	describe('getSortedSetRevRangeByLex', () => { | 
					
						
							|  |  |  | 		it('should return an array of all values reversed', (done) => { | 
					
						
							|  |  |  | 			db.getSortedSetRevRangeByLex('sortedSetLex', '+', '-', (err, data) => { | 
					
						
							| 
									
										
										
										
											2016-10-17 14:22:50 -04:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.deepEqual(data, ['d', 'c', 'b', 'a']); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return an array with an inclusive range by default reversed', (done) => { | 
					
						
							|  |  |  | 			db.getSortedSetRevRangeByLex('sortedSetLex', 'd', 'a', (err, data) => { | 
					
						
							| 
									
										
										
										
											2016-10-17 14:22:50 -04:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.deepEqual(data, ['d', 'c', 'b', 'a']); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return an array with an inclusive range reversed', (done) => { | 
					
						
							|  |  |  | 			db.getSortedSetRevRangeByLex('sortedSetLex', '[d', '[a', (err, data) => { | 
					
						
							| 
									
										
										
										
											2016-10-17 14:22:50 -04:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.deepEqual(data, ['d', 'c', 'b', 'a']); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return an array with an exclusive range reversed', (done) => { | 
					
						
							|  |  |  | 			db.getSortedSetRevRangeByLex('sortedSetLex', '(d', '(a', (err, data) => { | 
					
						
							| 
									
										
										
										
											2016-10-17 14:22:50 -04:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.deepEqual(data, ['c', 'b']); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return an array limited to the first two values reversed', (done) => { | 
					
						
							|  |  |  | 			db.getSortedSetRevRangeByLex('sortedSetLex', '+', '-', 0, 2, (err, data) => { | 
					
						
							| 
									
										
										
										
											2016-10-17 14:22:50 -04:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.deepEqual(data, ['d', 'c']); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	describe('sortedSetLexCount', () => { | 
					
						
							|  |  |  | 		it('should return the count of all values', (done) => { | 
					
						
							|  |  |  | 			db.sortedSetLexCount('sortedSetLex', '-', '+', (err, data) => { | 
					
						
							| 
									
										
										
										
											2016-10-17 14:22:50 -04:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.strictEqual(data, 4); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return the count with an inclusive range by default', (done) => { | 
					
						
							|  |  |  | 			db.sortedSetLexCount('sortedSetLex', 'a', 'd', (err, data) => { | 
					
						
							| 
									
										
										
										
											2016-10-17 14:22:50 -04:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.strictEqual(data, 4); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return the count with an inclusive range', (done) => { | 
					
						
							|  |  |  | 			db.sortedSetLexCount('sortedSetLex', '[a', '[d', (err, data) => { | 
					
						
							| 
									
										
										
										
											2016-10-17 14:22:50 -04:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.strictEqual(data, 4); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should return the count with an exclusive range', (done) => { | 
					
						
							|  |  |  | 			db.sortedSetLexCount('sortedSetLex', '(a', '(d', (err, data) => { | 
					
						
							| 
									
										
										
										
											2016-10-17 14:22:50 -04:00
										 |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.strictEqual(data, 2); | 
					
						
							|  |  |  | 				done(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 	describe('sortedSetRemoveRangeByLex', () => { | 
					
						
							|  |  |  | 		before((done) => { | 
					
						
							| 
									
										
										
										
											2016-10-17 14:22:50 -04:00
										 |  |  | 			db.sortedSetAdd('sortedSetLex2', [0, 0, 0, 0, 0, 0, 0], ['a', 'b', 'c', 'd', 'e', 'f', 'g'], done); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should remove an inclusive range by default', (done) => { | 
					
						
							| 
									
										
										
										
											2016-10-17 14:22:50 -04:00
										 |  |  | 			db.sortedSetRemoveRangeByLex('sortedSetLex2', 'a', 'b', function (err) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 1); | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 				db.getSortedSetRangeByLex('sortedSetLex2', '-', '+', (err, data) => { | 
					
						
							| 
									
										
										
										
											2016-10-17 14:22:50 -04:00
										 |  |  | 					assert.ifError(err); | 
					
						
							|  |  |  | 					assert.deepEqual(data, ['c', 'd', 'e', 'f', 'g']); | 
					
						
							|  |  |  | 					done(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should remove an inclusive range', (done) => { | 
					
						
							| 
									
										
										
										
											2016-10-17 14:22:50 -04:00
										 |  |  | 			db.sortedSetRemoveRangeByLex('sortedSetLex2', '[c', '[d', function (err) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 1); | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 				db.getSortedSetRangeByLex('sortedSetLex2', '-', '+', (err, data) => { | 
					
						
							| 
									
										
										
										
											2016-10-17 14:22:50 -04:00
										 |  |  | 					assert.ifError(err); | 
					
						
							|  |  |  | 					assert.deepEqual(data, ['e', 'f', 'g']); | 
					
						
							|  |  |  | 					done(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should remove an exclusive range', (done) => { | 
					
						
							| 
									
										
										
										
											2016-10-17 14:22:50 -04:00
										 |  |  | 			db.sortedSetRemoveRangeByLex('sortedSetLex2', '(e', '(g', function (err) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 1); | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 				db.getSortedSetRangeByLex('sortedSetLex2', '-', '+', (err, data) => { | 
					
						
							| 
									
										
										
										
											2016-10-17 14:22:50 -04:00
										 |  |  | 					assert.ifError(err); | 
					
						
							|  |  |  | 					assert.deepEqual(data, ['e', 'g']); | 
					
						
							|  |  |  | 					done(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 		it('should remove all values', (done) => { | 
					
						
							| 
									
										
										
										
											2016-10-17 14:22:50 -04:00
										 |  |  | 			db.sortedSetRemoveRangeByLex('sortedSetLex2', '-', '+', function (err) { | 
					
						
							|  |  |  | 				assert.ifError(err); | 
					
						
							|  |  |  | 				assert.equal(arguments.length, 1); | 
					
						
							| 
									
										
										
										
											2021-02-04 00:01:39 -07:00
										 |  |  | 				db.getSortedSetRangeByLex('sortedSetLex2', '-', '+', (err, data) => { | 
					
						
							| 
									
										
										
										
											2016-10-17 14:22:50 -04:00
										 |  |  | 					assert.ifError(err); | 
					
						
							|  |  |  | 					assert.deepEqual(data, []); | 
					
						
							|  |  |  | 					done(); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2014-12-31 14:27:16 -05:00
										 |  |  | }); |