1. 工具
node_redis
ioredis
2.
Redis=require('ioredis')
const redis= new Redis()
redis.set 与命令相同
(async()=>{
const abc = await redis.get('abc')
const hgetall = await redis.hgetall('myhash1')
const smembers = await redis.smembers('mset')
let set = new Set(...smembers )
})()
.then(r=>{
})
.catch(e=>{})
3. bluebird 异步代码
4. 爬虫,有目标,制定爬取计划,随机爬取,防止IP被封禁。
5.redis_service
const Redis = require('ioredis')
const redis = new Redis();
const ACFUN_ID_SET_REDIS_KEY:'acfun_id_set';
async function generateAcfunIdsToRedis(min,max){
for(let i= min;i<max;i++){
for(let j= 0;j<10000;j++){ -- 解决IO瓶颈
arr.push(i*10000+j)
}
await redis.sadd(ACFUN_ID_SET_REDIS_KEY,...arr)
}
}
async function getRandomAcfunIds(count){
}
moule.export={
generateAcfunIdsToRedis,
}
6.spider
const RedisService = require('./redis_service')
switch(process.argv[2]){
case 'generate_ids':
RedisService.generateAcfunIdsToRedis(Number(process.argv[3]),Number(process.argv[4]))
.then(r=>{
console.log('done')
process.exit(0)
}
)
.catch(e=>{
console.log(1)
process.exit(1)
}
}
7. 爬虫工具:axios, cherrio
8. for(let id of ids){ -- foreach
}