-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathredis-pop.js
More file actions
69 lines (62 loc) · 1.86 KB
/
redis-pop.js
File metadata and controls
69 lines (62 loc) · 1.86 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
'use strict';
const async = require('async');
const redis = require('./redis');
const uuid = require('uuid');
const data = JSON.stringify({
hello: 'world',
this: 'is new world'
});
let startId = 1;
function get() {
return startId++ + '-' + uuid.v4();
}
const maxCount = 200;
const maxList = new Array(maxCount);
function done(callback) {
async.eachLimit(maxList, 10, function(item, callback) {
setImmediate(function() {
const key = get();
async.series([
function(callback) {
redis.set(key, data, function(err) {
if(err) {
console.error(err)
return callback(err);
}
redis.expire(key, 24 * 3600);
return callback(err);
});
},
function(callback) {
redis.hset('test-redis-hash', key, null, function(err) {
if(err) {
console.error(err);
redis.del(key);
return callback(err);
}
callback();
});
},
function(callback) {
redis.rpush('test-redis-mq', key, function(err) {
if(err) {
console.error(err);
}
callback();
});
}
], function(err) {
if(err) {
return callback(err);
}
callback();
});
});
}, function(err) {
if(err) {
return callback(err);
}
callback();
});
}
module.exports = done;