change redisMoveCanvas script

This commit is contained in:
HF 2022-09-28 22:19:22 +02:00
parent d835a93e8c
commit 3ab076c917

View File

@ -1,32 +1,36 @@
// this script moves chunks of a canvas, i.e. to center it after changing size /*
* move 3d canvas chunks from one redis instance to another
*/
import { createClient, commandOptions } from 'redis';
import { createClient } from 'redis'; const urlc = "redis://localhost:6380";
const redisc = createClient({ url: urlc });
//ATTENTION Make suer to set the rdis URLs right!!! const urlt = "redis://localhost:6379";
const url = "redis://localhost:6379"; const redist = createClient({ url: urlt });
const redisc = createClient({ url });
const CANVAS_SIZE = 1024; const CANVAS_SIZE = 1024;
const TILE_SIZE = 256; const THREE_TILE_SIZE = 32;
const offset = (2048 - 1024) / 2 / 256;
const CHUNKS_XY = CANVAS_SIZE / TILE_SIZE; const CHUNKS_XY = CANVAS_SIZE / THREE_TILE_SIZE;
async function move() { async function move() {
await redisc.connect();
await redist.connect();
console.log('Moving chunks...');
for (let x = CHUNKS_XY - 1; x >= 0; x--) { for (let x = CHUNKS_XY - 1; x >= 0; x--) {
for (let y = CHUNKS_XY - 1; y >= 0; y--) { for (let y = CHUNKS_XY - 1; y >= 0; y--) {
const key = `ch:8:${x}:${y}`; const key = `ch:2:${x}:${y}`;
const chunk = await redisc.get(key, { returnBuffers: true }); const chunk = await redisc.get(
commandOptions({ returnBuffers: true }),
key,
);
if (chunk) { if (chunk) {
const newKey = `ch:8:${x + offset}:${y + offset}` const ret = await redist.set(key, Buffer.from(chunk.buffer));
await redisc.set(newKey, chunk); console.log('Moved Chunk ', key, ' to other redis', ret);
await redisc.del(key);
console.log('Moved Chunk ', key, ' to ', newKey);
} }
} }
} }
console.log("done"); console.log("done");
} }
redisc.connect() move();
.then(() => move());