redis 数据同步脚本

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

const Redis = require('ioredis');

const r1 = new Redis({
	port: 6379,
	host: '192.168.1.1',
	password: '123456',
	db: 0,
	keyPrefix: '',
});

r2 = new Redis({
	port: 6379,
	host: '192.168.1.2',
	password: '123456',
	db: 0,
	keyPrefix: '',
});

(async () => {

	let keys = await r1.keys('*');
	for (key of keys) {
		let key_type = await r1.type(key);
		if (key_type == 'string') {
			await r2.set(key, await r1.get(key));
		}
		else if (key_type == 'hash') {
			await r2.hmset(key, await r1.hgetall(key));
		}
		else if (key_type == 'zset') {
			let arr = await r1.zrange(key, 0, -1, 'WITHSCORES');
			for (let i=0; i

 

转载于:https://my.oschina.net/qiongtaoli/blog/1556862

你可能感兴趣的:(redis 数据同步脚本)