pixelplanet/utils/redisMoveCanvas.js

37 lines
949 B
JavaScript
Raw Permalink Normal View History

2022-09-28 20:19:22 +00:00
/*
* move 3d canvas chunks from one redis instance to another
*/
import { createClient, commandOptions } from 'redis';
2022-09-28 20:19:22 +00:00
const urlc = "redis://localhost:6380";
const redisc = createClient({ url: urlc });
const urlt = "redis://localhost:6379";
const redist = createClient({ url: urlt });
2022-06-27 22:36:19 +00:00
const CANVAS_SIZE = 1024;
2022-09-28 20:19:22 +00:00
const THREE_TILE_SIZE = 32;
2022-09-28 20:19:22 +00:00
const CHUNKS_XY = CANVAS_SIZE / THREE_TILE_SIZE;
async function move() {
2022-09-28 20:19:22 +00:00
await redisc.connect();
await redist.connect();
console.log('Moving chunks...');
for (let x = CHUNKS_XY - 1; x >= 0; x--) {
for (let y = CHUNKS_XY - 1; y >= 0; y--) {
2022-09-28 20:19:22 +00:00
const key = `ch:2:${x}:${y}`;
const chunk = await redisc.get(
commandOptions({ returnBuffers: true }),
key,
);
if (chunk) {
2022-09-28 20:19:22 +00:00
const ret = await redist.set(key, Buffer.from(chunk.buffer));
console.log('Moved Chunk ', key, ' to other redis', ret);
}
}
}
console.log("done");
}
2022-09-28 20:19:22 +00:00
move();