update utils

This commit is contained in:
HF 2020-01-31 00:18:26 +01:00
parent 210ac828ab
commit c2dbb45572
2 changed files with 47 additions and 1 deletions

View File

@ -19,7 +19,7 @@ async function copyChunks() {
for (let x = 0; x < CHUNKS_XY; x++) {
for (let y = 0; y < CHUNKS_XY; y++) {
const oldkey = `chunk:${x}:${y}`;
const newkey = `ch:0:${i}:${j}`;
const newkey = `ch:0:${x}:${y}`;
const chunk = await oldredis.getAsync(oldkey);
if (chunk) {
const setNXArgs = [newkey, chunk];

46
utils/redisUnprotect.js Normal file
View File

@ -0,0 +1,46 @@
/* @flow */
//this script just copies chunks from one redis to another with a different key as needed
import redis from 'redis';
import bluebird from 'bluebird';
bluebird.promisifyAll(redis.RedisClient.prototype);
bluebird.promisifyAll(redis.Multi.prototype);
//ATTENTION Make suer to set the rdis URLs right!!!
const url = "redis://localhost:6379";
const redis = redis.createClient(url, { return_buffers: true });
const CANVAS_SIZE = 256 * 256;
const TILE_SIZE = 256;
const CHUNKS_XY = CANVAS_SIZE / TILE_SIZE;
async function moveProtection() {
for (let x = 0; x < CHUNKS_XY; x++) {
for (let y = 0; y < CHUNKS_XY; y++) {
const key = `ch:0:${x}:${y}`;
const chunk = await redis.getAsync(key);
if (chunk) {
const buffer = new Uint8Array(chunk);
let changed = false;
for (let u = 0; u < buffer.length; ++u) {
const bit = buffer[u];
if (bit & 0x20) {
// move protected bit from 0x20 to 0x80
buffer[u] = (bit & 0x1F) | 0x80;
changed = true;
}
}
if (changed) {
const setNXArgs = [key, Buffer.from(buffer.buffer).toString('binary')]
await redis.sendCommandAsync('SETNX', setNXArgs);
console.log("Changed Chunk ", key);
}
}
}
}
}
moveProtection();