-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathiterator-sscan-example.js
More file actions
42 lines (35 loc) · 1.07 KB
/
Copy pathiterator-sscan-example.js
File metadata and controls
42 lines (35 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
* Spade SSCAN iterator example
*/
var log = console.log
, Spade = require( '../' )
, client = Spade()
, cback = function ( err, data, iterate ) {
// if ( ! data[ 0 ] ) return iterator.next();
if ( ! data[ 0 ] ) return iterate();
etime = Date.now();
log( '\n- %s properties scanned from set key \'%s\' through %s iterations.', data[ 3 ], skey, data[ 2 ] );
log( '- elapsed time: %d secs.\n', ( ( etime - stime ) / 1000 ).toFixed( 1 ) );
}
, i = 0
// Spade default options for SCAN ZSCAN SSCAN HSCAN commands.
, opt = {
match : null
, count : 10
}
, skey = 'skey'
, n = 1000
, stime = -1
, etime = -1
;
// enable cli logging
client.cli();
// client.commands.flushdb();
// push 1000 test keys to force multiple iterations with COUNT
for ( ; i < n; ++i ) client.commands.sadd( skey, 'el:' + i, i );
client.connect();
// load files from iterators directory
client.loadIterators();
stime = Date.now();
// get a SSCAN iterator
client.iterators.sscan( skey, 0, opt, cback ).next();