-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathiterator-scan-example.js
41 lines (34 loc) · 985 Bytes
/
iterator-scan-example.js
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
/*
* Spade SCAN 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 keys scanned through %s iterations.', data[ 3 ], 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
}
, n = 500
, stime = -1
, etime = -1
;
// enable cli logging
client.cli();
// client.commands.flushdb();
// push 500 test keys
for ( ; i < n; ++i ) client.commands.set( 'key:' + i, i );
client.connect();
// load files from iterators directory
client.loadIterators();
stime = Date.now();
// get a SCAN iterator
client.iterators.scan( 0, opt, cback ).next();