-
Notifications
You must be signed in to change notification settings - Fork 13
/
example-redis5.js
43 lines (36 loc) · 1.09 KB
/
example-redis5.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
42
43
var Redis = require('.');
//var Redis = require('redis-fast-driver');
var r = new Redis({
//host: '/tmp/redis.sock', //unix domain
host: '127.0.0.1', //can be IP or hostname
port: 6379,
maxretries: 10, //reconnect retries, default -1 (infinity)
// auth: '123',
// db: 5
});
//happen only once
r.on('ready', function(){
console.log('redis ready');
});
//happen each time when reconnected
r.on('connected', function(){
console.log('redis connected');
});
r.on('disconnected', function(){
console.log('redis disconnected');
});
r.on('error', function(e){
console.log('redis error', e);
});
//rawCall function has 2 arguments,
//1 - array which contain a redis command
//2 - optional callback
//Redis command is case insesitive, e.g. you can specify HMGET as HMGET, hmget or HmGeT
//but keys and value are case sensitive, foo, Foo, FoO not the same...
r.rawCall(['zadd', 'z', 1, 1, 2, 2, 3, 3, 4, 4], function(err, resp){
console.log('SET via zadd command returns err: %s, resp: %s', err, resp);
});
r.rawCall(['zpopmin', 'z', '2'], function(e, resp){
console.log('zpopmin', e, resp);
r.end();
});