nodejs遍历redis里所有数据进行
var redis = require('redis');
var async = require('async')
var client = redis.createClient({
"host": "127.0.0.1",
"port": "6379",
"db": 0,
"password": ""
});
var cursor = '0'; //遍历游标
function scan() {
client.scan(
cursor,
'MATCH', 'string:url_info:short_id:*',
'COUNT', '1000',
function (err, res) {
if (err) throw err;
cursor = res[0];
var keys = res[1];
async.mapLimit(keys,50,function(key,done){
client.get(key, function (error, result) {
//xxxx 此处添加逻辑
done()
})
},function(err,result){
if (cursor === '0') {
//游标回到原点 则遍历结束
return console.log('Iteration complete');
}
return scan();
})
})
}
scan();