// tslint:disable:no-console import * as redis from 'redis'; // import * as mongoose from 'mongoose'; // import { chevre } from '../../../lib/index'; async function main() { const client = redis.createClient({ host: process.env.REDIS_HOST, port: Number(process.env.REDIS_PORT), password: process.env.REDIS_KEY, tls: { servername: process.env.REDIS_HOST } }); const newClient = redis.createClient({ host: process.env.NEW_REDIS_HOST, port: Number(process.env.NEW_REDIS_PORT), password: process.env.NEW_REDIS_KEY }); client.keys('chevre:itemAvailability:screeningEvent:*', async (err, keysreply) => { console.log(err, keysreply.length, 'keys found'); const targetKeys = keysreply; await Promise.all(targetKeys.map(async (targetKey) => { const newKey = targetKey; return new Promise((resolve, reject) => { client.hgetall(targetKey, (hgetallerr, reply) => { console.log('reply:', reply); if (hgetallerr !== null) { reject(hgetallerr); } else { if (reply !== null) { client.ttl(targetKey, (__, ttl) => { console.log('ttl:', ttl); const args = Object.keys(reply) .reduce( (a: any[], b) => { return [...a, b, reply[b]]; }, [] ); console.log(args.length, 'args ready'); newClient.multi() .hmset(newKey, ...args) .expire(newKey, ttl) .exec((hmsetErr, execreply) => { console.log('hmset result:', hmsetErr, execreply); resolve(); }); }); } else { reject(new Error('targetKey not found')); } } }); }); })); }); client.keys('chevre:reservationNumber:*', async (err, keysreply) => { console.log(err, keysreply.length, 'keys found'); const targetKeys = keysreply; await Promise.all(targetKeys.map(async (targetKey) => { const newKey = targetKey; return new Promise((resolve, reject) => { client.get(targetKey, (hgetallerr, reply) => { console.log('reply:', reply); if (hgetallerr !== null) { reject(hgetallerr); } else { if (reply !== null) { client.ttl(targetKey, (__, ttl) => { console.log('ttl:', ttl); const args = reply; newClient.multi() .set(newKey, args) .expire(newKey, ttl) .exec((setErr, execreply) => { console.log('set result:', setErr, execreply); resolve(); }); }); } else { reject(new Error('targetKey not found')); } } }); }); })); }); } main() .then(console.log) .catch(console.error);