update node-redis

This commit is contained in:
HF 2022-04-05 21:37:33 +02:00
parent f6902ca73c
commit 4fd94ebd65
27 changed files with 268 additions and 243 deletions

243
package-lock.json generated
View File

@ -11,10 +11,9 @@
"bcrypt": "^5.0.1",
"bluebird": "^3.5.0",
"compression": "^1.7.3",
"connect-redis": "^6.0.0",
"connect-redis": "^6.1.3",
"cookie": "^0.4.1",
"core-js": "^3.20.2",
"cors": "^2.8.4",
"etag": "^1.8.1",
"express": "^4.17.2",
"express-session": "^1.17.2",
@ -43,8 +42,7 @@
"react-responsive": "^8.2.0",
"react-stay-scrolled": "^7.4.0",
"react-toggle-button": "^2.1.0",
"redis": "^3.1.2",
"redlock": "^4.0.0",
"redis": "^4.0.6",
"redux": "^4.1.2",
"redux-logger": "^3.0.6",
"redux-persist": "^6.0.0",
@ -2129,6 +2127,60 @@
"dev": true,
"optional": true
},
"node_modules/@node-redis/bloom": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/@node-redis/bloom/-/bloom-1.0.1.tgz",
"integrity": "sha512-mXEBvEIgF4tUzdIN89LiYsbi6//EdpFA7L8M+DHCvePXg+bfHWi+ct5VI6nHUFQE5+ohm/9wmgihCH3HSkeKsw==",
"peerDependencies": {
"@node-redis/client": "^1.0.0"
}
},
"node_modules/@node-redis/client": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/@node-redis/client/-/client-1.0.5.tgz",
"integrity": "sha512-ESZ3bd1f+od62h4MaBLKum+klVJfA4wAeLHcVQBkoXa1l0viFesOWnakLQqKg+UyrlJhZmXJWtu0Y9v7iTMrig==",
"dependencies": {
"cluster-key-slot": "1.1.0",
"generic-pool": "3.8.2",
"redis-parser": "3.0.0",
"yallist": "4.0.0"
},
"engines": {
"node": ">=12"
}
},
"node_modules/@node-redis/graph": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/@node-redis/graph/-/graph-1.0.0.tgz",
"integrity": "sha512-mRSo8jEGC0cf+Rm7q8mWMKKKqkn6EAnA9IA2S3JvUv/gaWW/73vil7GLNwion2ihTptAm05I9LkepzfIXUKX5g==",
"peerDependencies": {
"@node-redis/client": "^1.0.0"
}
},
"node_modules/@node-redis/json": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/@node-redis/json/-/json-1.0.2.tgz",
"integrity": "sha512-qVRgn8WfG46QQ08CghSbY4VhHFgaTY71WjpwRBGEuqGPfWwfRcIf3OqSpR7Q/45X+v3xd8mvYjywqh0wqJ8T+g==",
"peerDependencies": {
"@node-redis/client": "^1.0.0"
}
},
"node_modules/@node-redis/search": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/@node-redis/search/-/search-1.0.5.tgz",
"integrity": "sha512-MCOL8iCKq4v+3HgEQv8zGlSkZyXSXtERgrAJ4TSryIG/eLFy84b57KmNNa/V7M1Q2Wd2hgn2nPCGNcQtk1R1OQ==",
"peerDependencies": {
"@node-redis/client": "^1.0.0"
}
},
"node_modules/@node-redis/time-series": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/@node-redis/time-series/-/time-series-1.0.2.tgz",
"integrity": "sha512-HGQ8YooJ8Mx7l28tD7XjtB3ImLEjlUxG1wC1PAjxu6hPJqjPshUZxAICzDqDjtIbhDTf48WXXUcx8TQJB1XTKA==",
"peerDependencies": {
"@node-redis/client": "^1.0.0"
}
},
"node_modules/@nodelib/fs.scandir": {
"version": "2.1.5",
"resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz",
@ -3542,6 +3594,14 @@
"node": ">=6"
}
},
"node_modules/cluster-key-slot": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/cluster-key-slot/-/cluster-key-slot-1.1.0.tgz",
"integrity": "sha512-2Nii8p3RwAPiFwsnZvukotvow2rIHM+yQ6ZcBXGHdniadkYGZYiGmkHJIbZPIV9nfv7m/U1IPMVVcAhoWFeklw==",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/co": {
"version": "4.6.0",
"resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz",
@ -3774,9 +3834,9 @@
"dev": true
},
"node_modules/connect-redis": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/connect-redis/-/connect-redis-6.0.0.tgz",
"integrity": "sha512-6eGEAAPHYvcfbRNCMmPzBIjrqRWLw7at9lCUH4G6NQ8gwWDJelaUmFNOqPIhehbw941euVmIuqWsaWiKXfb+5g==",
"version": "6.1.3",
"resolved": "https://registry.npmjs.org/connect-redis/-/connect-redis-6.1.3.tgz",
"integrity": "sha512-aaNluLlAn/3JPxRwdzw7lhvEoU6Enb+d83xnokUNhC9dktqBoawKWL+WuxinxvBLTz6q9vReTnUDnUslaz74aw==",
"engines": {
"node": ">=12"
}
@ -4001,18 +4061,6 @@
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz",
"integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ=="
},
"node_modules/cors": {
"version": "2.8.5",
"resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz",
"integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==",
"dependencies": {
"object-assign": "^4",
"vary": "^1"
},
"engines": {
"node": ">= 0.10"
}
},
"node_modules/cosmiconfig": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-6.0.0.tgz",
@ -5480,6 +5528,14 @@
"integrity": "sha512-JJS6CTkCIJeiqJay/mqrO005vbyLeozcyQvJf5AbToN7zsBewlu1Zk4dLiTV1+S/jJUUFjjn/ng9rjdbsJYyXw==",
"dev": true
},
"node_modules/generic-pool": {
"version": "3.8.2",
"resolved": "https://registry.npmjs.org/generic-pool/-/generic-pool-3.8.2.tgz",
"integrity": "sha512-nGToKy6p3PAbYQ7p1UlWl6vSPwfwU6TMSWK7TTu+WUY4ZjyZQGniGGt2oNVvyNSpyZYSB43zMXVLcBm08MTMkg==",
"engines": {
"node": ">= 4"
}
},
"node_modules/gensync": {
"version": "1.0.0-beta.2",
"resolved": "https://registry.npmjs.org/gensync/-/gensync-1.0.0-beta.2.tgz",
@ -8687,28 +8743,18 @@
}
},
"node_modules/redis": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/redis/-/redis-3.1.2.tgz",
"integrity": "sha512-grn5KoZLr/qrRQVwoSkmzdbw6pwF+/rwODtrOr6vuBRiR/f3rjSTGupbF90Zpqm2oenix8Do6RV7pYEkGwlKkw==",
"version": "4.0.6",
"resolved": "https://registry.npmjs.org/redis/-/redis-4.0.6.tgz",
"integrity": "sha512-IaPAxgF5dV0jx+A9l6yd6R9/PAChZIoAskDVRzUODeLDNhsMlq7OLLTmu0AwAr0xjrJ1bibW5xdpRwqIQ8Q0Xg==",
"dependencies": {
"denque": "^1.5.0",
"redis-commands": "^1.7.0",
"redis-errors": "^1.2.0",
"redis-parser": "^3.0.0"
},
"engines": {
"node": ">=10"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/node-redis"
"@node-redis/bloom": "1.0.1",
"@node-redis/client": "1.0.5",
"@node-redis/graph": "1.0.0",
"@node-redis/json": "1.0.2",
"@node-redis/search": "1.0.5",
"@node-redis/time-series": "1.0.2"
}
},
"node_modules/redis-commands": {
"version": "1.7.0",
"resolved": "https://registry.npmjs.org/redis-commands/-/redis-commands-1.7.0.tgz",
"integrity": "sha512-nJWqw3bTFy21hX/CPKHth6sfhZbdiHP6bTawSgQBlKOVRG7EZkfHbbHwQJnrE4vsQf0CMNE+3gJ4Fmm16vdVlQ=="
},
"node_modules/redis-errors": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/redis-errors/-/redis-errors-1.2.0.tgz",
@ -8728,25 +8774,6 @@
"node": ">=4"
}
},
"node_modules/redis/node_modules/denque": {
"version": "1.5.1",
"resolved": "https://registry.npmjs.org/denque/-/denque-1.5.1.tgz",
"integrity": "sha512-XwE+iZ4D6ZUB7mfYRMb5wByE8L74HCn30FBN7sWnXksWc1LO1bPDl67pBR9o/kC4z/xSNAwkMYcGgqDV3BE3Hw==",
"engines": {
"node": ">=0.10"
}
},
"node_modules/redlock": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/redlock/-/redlock-4.2.0.tgz",
"integrity": "sha512-j+oQlG+dOwcetUt2WJWttu4CZVeRzUrcVcISFmEmfyuwCVSJ93rDT7YSgg7H7rnxwoRyk/jU46kycVka5tW7jA==",
"dependencies": {
"bluebird": "^3.7.2"
},
"engines": {
"node": ">=8.0.0"
}
},
"node_modules/redux": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/redux/-/redux-4.1.2.tgz",
@ -12339,6 +12366,47 @@
"dev": true,
"optional": true
},
"@node-redis/bloom": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/@node-redis/bloom/-/bloom-1.0.1.tgz",
"integrity": "sha512-mXEBvEIgF4tUzdIN89LiYsbi6//EdpFA7L8M+DHCvePXg+bfHWi+ct5VI6nHUFQE5+ohm/9wmgihCH3HSkeKsw==",
"requires": {}
},
"@node-redis/client": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/@node-redis/client/-/client-1.0.5.tgz",
"integrity": "sha512-ESZ3bd1f+od62h4MaBLKum+klVJfA4wAeLHcVQBkoXa1l0viFesOWnakLQqKg+UyrlJhZmXJWtu0Y9v7iTMrig==",
"requires": {
"cluster-key-slot": "1.1.0",
"generic-pool": "3.8.2",
"redis-parser": "3.0.0",
"yallist": "4.0.0"
}
},
"@node-redis/graph": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/@node-redis/graph/-/graph-1.0.0.tgz",
"integrity": "sha512-mRSo8jEGC0cf+Rm7q8mWMKKKqkn6EAnA9IA2S3JvUv/gaWW/73vil7GLNwion2ihTptAm05I9LkepzfIXUKX5g==",
"requires": {}
},
"@node-redis/json": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/@node-redis/json/-/json-1.0.2.tgz",
"integrity": "sha512-qVRgn8WfG46QQ08CghSbY4VhHFgaTY71WjpwRBGEuqGPfWwfRcIf3OqSpR7Q/45X+v3xd8mvYjywqh0wqJ8T+g==",
"requires": {}
},
"@node-redis/search": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/@node-redis/search/-/search-1.0.5.tgz",
"integrity": "sha512-MCOL8iCKq4v+3HgEQv8zGlSkZyXSXtERgrAJ4TSryIG/eLFy84b57KmNNa/V7M1Q2Wd2hgn2nPCGNcQtk1R1OQ==",
"requires": {}
},
"@node-redis/time-series": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/@node-redis/time-series/-/time-series-1.0.2.tgz",
"integrity": "sha512-HGQ8YooJ8Mx7l28tD7XjtB3ImLEjlUxG1wC1PAjxu6hPJqjPshUZxAICzDqDjtIbhDTf48WXXUcx8TQJB1XTKA==",
"requires": {}
},
"@nodelib/fs.scandir": {
"version": "2.1.5",
"resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz",
@ -13452,6 +13520,11 @@
"shallow-clone": "^3.0.0"
}
},
"cluster-key-slot": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/cluster-key-slot/-/cluster-key-slot-1.1.0.tgz",
"integrity": "sha512-2Nii8p3RwAPiFwsnZvukotvow2rIHM+yQ6ZcBXGHdniadkYGZYiGmkHJIbZPIV9nfv7m/U1IPMVVcAhoWFeklw=="
},
"co": {
"version": "4.6.0",
"resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz",
@ -13661,9 +13734,9 @@
"dev": true
},
"connect-redis": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/connect-redis/-/connect-redis-6.0.0.tgz",
"integrity": "sha512-6eGEAAPHYvcfbRNCMmPzBIjrqRWLw7at9lCUH4G6NQ8gwWDJelaUmFNOqPIhehbw941euVmIuqWsaWiKXfb+5g=="
"version": "6.1.3",
"resolved": "https://registry.npmjs.org/connect-redis/-/connect-redis-6.1.3.tgz",
"integrity": "sha512-aaNluLlAn/3JPxRwdzw7lhvEoU6Enb+d83xnokUNhC9dktqBoawKWL+WuxinxvBLTz6q9vReTnUDnUslaz74aw=="
},
"console-control-strings": {
"version": "1.1.0",
@ -13820,15 +13893,6 @@
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz",
"integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ=="
},
"cors": {
"version": "2.8.5",
"resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz",
"integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==",
"requires": {
"object-assign": "^4",
"vary": "^1"
}
},
"cosmiconfig": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-6.0.0.tgz",
@ -14972,6 +15036,11 @@
"integrity": "sha512-JJS6CTkCIJeiqJay/mqrO005vbyLeozcyQvJf5AbToN7zsBewlu1Zk4dLiTV1+S/jJUUFjjn/ng9rjdbsJYyXw==",
"dev": true
},
"generic-pool": {
"version": "3.8.2",
"resolved": "https://registry.npmjs.org/generic-pool/-/generic-pool-3.8.2.tgz",
"integrity": "sha512-nGToKy6p3PAbYQ7p1UlWl6vSPwfwU6TMSWK7TTu+WUY4ZjyZQGniGGt2oNVvyNSpyZYSB43zMXVLcBm08MTMkg=="
},
"gensync": {
"version": "1.0.0-beta.2",
"resolved": "https://registry.npmjs.org/gensync/-/gensync-1.0.0-beta.2.tgz",
@ -17370,28 +17439,18 @@
}
},
"redis": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/redis/-/redis-3.1.2.tgz",
"integrity": "sha512-grn5KoZLr/qrRQVwoSkmzdbw6pwF+/rwODtrOr6vuBRiR/f3rjSTGupbF90Zpqm2oenix8Do6RV7pYEkGwlKkw==",
"version": "4.0.6",
"resolved": "https://registry.npmjs.org/redis/-/redis-4.0.6.tgz",
"integrity": "sha512-IaPAxgF5dV0jx+A9l6yd6R9/PAChZIoAskDVRzUODeLDNhsMlq7OLLTmu0AwAr0xjrJ1bibW5xdpRwqIQ8Q0Xg==",
"requires": {
"denque": "^1.5.0",
"redis-commands": "^1.7.0",
"redis-errors": "^1.2.0",
"redis-parser": "^3.0.0"
},
"dependencies": {
"denque": {
"version": "1.5.1",
"resolved": "https://registry.npmjs.org/denque/-/denque-1.5.1.tgz",
"integrity": "sha512-XwE+iZ4D6ZUB7mfYRMb5wByE8L74HCn30FBN7sWnXksWc1LO1bPDl67pBR9o/kC4z/xSNAwkMYcGgqDV3BE3Hw=="
}
"@node-redis/bloom": "1.0.1",
"@node-redis/client": "1.0.5",
"@node-redis/graph": "1.0.0",
"@node-redis/json": "1.0.2",
"@node-redis/search": "1.0.5",
"@node-redis/time-series": "1.0.2"
}
},
"redis-commands": {
"version": "1.7.0",
"resolved": "https://registry.npmjs.org/redis-commands/-/redis-commands-1.7.0.tgz",
"integrity": "sha512-nJWqw3bTFy21hX/CPKHth6sfhZbdiHP6bTawSgQBlKOVRG7EZkfHbbHwQJnrE4vsQf0CMNE+3gJ4Fmm16vdVlQ=="
},
"redis-errors": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/redis-errors/-/redis-errors-1.2.0.tgz",
@ -17405,14 +17464,6 @@
"redis-errors": "^1.0.0"
}
},
"redlock": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/redlock/-/redlock-4.2.0.tgz",
"integrity": "sha512-j+oQlG+dOwcetUt2WJWttu4CZVeRzUrcVcISFmEmfyuwCVSJ93rDT7YSgg7H7rnxwoRyk/jU46kycVka5tW7jA==",
"requires": {
"bluebird": "^3.7.2"
}
},
"redux": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/redux/-/redux-4.1.2.tgz",

View File

@ -24,9 +24,8 @@
],
"dependencies": {
"bcrypt": "^5.0.1",
"bluebird": "^3.5.0",
"compression": "^1.7.3",
"connect-redis": "^6.0.0",
"connect-redis": "^6.1.3",
"cookie": "^0.4.1",
"core-js": "^3.20.2",
"etag": "^1.8.1",
@ -57,7 +56,7 @@
"react-responsive": "^8.2.0",
"react-stay-scrolled": "^7.4.0",
"react-toggle-button": "^2.1.0",
"redis": "^3.1.2",
"redis": "^4.0.6",
"redux": "^4.1.2",
"redux-logger": "^3.0.6",
"redux-persist": "^6.0.0",

View File

@ -16,7 +16,6 @@ import os from 'os';
import { spawn } from 'child_process';
import path from 'path';
import redis from 'redis';
import bluebird from 'bluebird';
import {
@ -39,9 +38,6 @@ try {
}
bluebird.promisifyAll(redis.RedisClient.prototype);
bluebird.promisifyAll(redis.Multi.prototype);
const [
CANVAS_REDIS_URL,
BACKUP_REDIS_URL,
@ -58,9 +54,9 @@ if (!CANVAS_REDIS_URL || !BACKUP_REDIS_URL || !BACKUP_DIR) {
}
const canvasRedis = redis
.createClient(CANVAS_REDIS_URL, { return_buffers: true });
.createClient(CANVAS_REDIS_URL);
const backupRedis = redis
.createClient(BACKUP_REDIS_URL, { return_buffers: true });
.createClient(BACKUP_REDIS_URL);
canvasRedis.on('error', () => {
console.error('Could not connect to canvas redis');
process.exit(1);
@ -119,7 +115,7 @@ async function dailyBackup() {
fs.mkdirSync(backupDir, { recursive: true });
}
await backupRedis.flushallAsync('ASYNC');
await backupRedis.flushall('ASYNC');
try {
await updateBackupRedis(canvasRedis, backupRedis, canvases);

View File

@ -508,7 +508,7 @@ export class ChatProvider {
static async checkIfMuted(user) {
const key = `mute:${user.id}`;
const ttl: number = await redis.ttlAsync(key);
const ttl: number = await redis.ttl(key);
return ttl;
}
@ -527,7 +527,7 @@ export class ChatProvider {
const key = `mute:${id}`;
if (timeMin) {
const ttl = timeMin * 60;
await redis.setAsync(key, '', 'EX', ttl);
await redis.set(key, '', 'EX', ttl);
if (printChannel) {
this.broadcastChatMessage(
'info',
@ -539,7 +539,7 @@ export class ChatProvider {
);
}
} else {
await redis.setAsync(key, '');
await redis.set(key, '');
if (printChannel) {
this.broadcastChatMessage(
'info',
@ -567,7 +567,7 @@ export class ChatProvider {
}
const userPing = `@[${name}](${id})`;
const key = `mute:${id}`;
const delKeys = await redis.delAsync(key);
const delKeys = await redis.del(key);
if (delKeys !== 1) {
return `User ${userPing} is not muted`;
}

View File

@ -143,7 +143,7 @@ export async function createZoomTileFromChunk(
let chunk = null;
for (let dy = 0; dy < TILE_ZOOM_LEVEL; dy += 1) {
for (let dx = 0; dx < TILE_ZOOM_LEVEL; dx += 1) {
chunk = await redisClient.getAsync(
chunk = await redisClient.get(
`ch:${canvasId}:${xabs + dx}:${yabs + dy}`,
);
if (!chunk || chunk.length !== TILE_SIZE * TILE_SIZE) {
@ -354,7 +354,7 @@ export async function createTexture(
} else {
for (let dy = 0; dy < amount; dy += 1) {
for (let dx = 0; dx < amount; dx += 1) {
chunk = await redisClient.getAsync(`ch:${canvasId}:${dx}:${dy}`);
chunk = await redisClient.get(`ch:${canvasId}:${dx}:${dy}`);
if (!chunk || chunk.length !== TILE_SIZE * TILE_SIZE) {
na.push([dx, dy]);
continue;

View File

@ -52,7 +52,7 @@ export async function executeIPAction(action, ips, logger = null) {
await Blacklist.findOrCreate({
where: { ip: ipKey },
});
await redis.setAsync(key, 'y', 'EX', 24 * 3600);
await redis.set(key, 'y', 'EX', 24 * 3600);
break;
case 'unban':
await Blacklist.destroy({
@ -64,7 +64,7 @@ export async function executeIPAction(action, ips, logger = null) {
await Whitelist.findOrCreate({
where: { ip: ipKey },
});
await redis.setAsync(key, 'n', 'EX', 24 * 3600);
await redis.set(key, 'n', 'EX', 24 * 3600);
break;
case 'unwhitelist':
await Whitelist.destroy({

View File

@ -168,7 +168,7 @@ async function withCache(f, ip) {
// get from cache, if there
const ipKey = getIPv6Subnet(ip);
const key = `isprox:${ipKey}`;
const cache = await redis.getAsync(key);
const cache = await redis.get(key);
if (cache) {
const str = cache.toString('utf8');
logger.debug('PROXYCHECK fetch isproxy from cache %s %s %s %s %s',
@ -190,7 +190,7 @@ async function withCache(f, ip) {
withoutCache(f, ip)
.then((result) => {
const value = result ? 'y' : 'n';
redis.setAsync(key, value, 'EX', 3 * 24 * 3600); // cache for three days
redis.set(key, value, 'EX', 3 * 24 * 3600); // cache for three days
const pos = checking.indexOf(ipKey);
if (~pos) checking.splice(pos, 1);
lock += 1;

View File

@ -1,17 +1,16 @@
/**
* @flow
/*
*
*/
import expressSession from 'express-session';
import connectRedis from 'connect-redis';
import client from '../data/redis';
import { redisV3 } from '../data/redis';
import { HOUR, COOKIE_SESSION_NAME } from './constants';
import { SESSION_SECRET } from './config';
const RedisStore = connectRedis(expressSession);
export const store = new RedisStore({ client });
export const store = new RedisStore({ client: redisV3 });
const session = expressSession({
name: COOKIE_SESSION_NAME,

View File

@ -40,11 +40,11 @@ export async function updateBackupRedis(canvasRedis, backupRedis, canvases) {
* in exchange for higher execution time is wanted.
*/
// eslint-disable-next-line no-await-in-loop
const chunk = await canvasRedis.getAsync(key);
const chunk = await canvasRedis.get(key);
if (chunk) {
const setNXArgs = [key, chunk];
// eslint-disable-next-line no-await-in-loop
await backupRedis.sendCommandAsync('SET', setNXArgs);
await backupRedis.sendCommand('SET', setNXArgs);
amount += 1;
}
}
@ -108,12 +108,12 @@ export async function incrementialBackupRedis(
* in exchange for higher execution time is wanted.
*/
// eslint-disable-next-line no-await-in-loop
const curChunk = await canvasRedis.getAsync(key);
const curChunk = await canvasRedis.get(key);
let tileBuffer = null;
if (curChunk) {
if (curChunk.length === TILE_SIZE * TILE_SIZE) {
// eslint-disable-next-line no-await-in-loop
const oldChunk = await backupRedis.getAsync(key);
const oldChunk = await backupRedis.get(key);
if (oldChunk && oldChunk.length === TILE_SIZE * TILE_SIZE) {
let pxl = 0;
while (pxl < curChunk.length) {
@ -207,7 +207,7 @@ export async function createPngBackup(
* in exchange for higher execution time is wanted.
*/
// eslint-disable-next-line no-await-in-loop
const chunk = await redisClient.getAsync(key);
const chunk = await redisClient.get(key);
if (chunk) {
if (chunk.length === TILE_SIZE * TILE_SIZE) {
const textureBuffer = palette.buffer2RGB(chunk);

View File

@ -14,7 +14,7 @@ const STAT_KEY = 'clr:sta';
* (check core/CanvasCleaner for the meaning)
*/
export async function getData() {
const data = await redis.getAsync(DATA_KEY);
const data = await redis.get(DATA_KEY);
if (data) {
const parsedData = data.toString().split(':');
for (let i = 0; i < parsedData.length - 1; i += 1) {
@ -56,7 +56,7 @@ export async function setData(canvasId, x, y, u, v, methodName) {
);
return null;
}
return redis.setAsync(DATA_KEY, dataStr);
return redis.set(DATA_KEY, dataStr);
}
/*
@ -66,7 +66,7 @@ export async function setData(canvasId, x, y, u, v, methodName) {
* running: boolean if filter is running
*/
export async function getStatus() {
const stat = await redis.getAsync(STAT_KEY);
const stat = await redis.get(STAT_KEY);
if (stat) {
const parsedStat = stat.toString().split(':');
if (parsedStat.length !== 2) {
@ -103,5 +103,5 @@ export async function setStatus(cIter, running) {
);
return null;
}
return redis.setAsync(STAT_KEY, statString);
return redis.set(STAT_KEY, statString);
}

View File

@ -26,10 +26,10 @@ export const CANVAS_ID = '0';
* 2 = lost
*/
export function setSuccess(success) {
return redis.setAsync(EVENT_SUCCESS_KEY, success);
return redis.set(EVENT_SUCCESS_KEY, success);
}
export async function getSuccess() {
const success = await redis.getAsync(EVENT_SUCCESS_KEY);
const success = await redis.get(EVENT_SUCCESS_KEY);
return (success) ? parseInt(success, 10) : 0;
}
@ -37,7 +37,7 @@ export async function getSuccess() {
* @return time till next event in seconds
*/
export async function nextEvent() {
const timestamp = await redis.getAsync(EVENT_TIMESTAMP_KEY);
const timestamp = await redis.get(EVENT_TIMESTAMP_KEY);
if (timestamp) {
return Number(timestamp.toString());
}
@ -48,7 +48,7 @@ export async function nextEvent() {
* @return cell of chunk coordinates of event
*/
export async function getEventArea() {
const pos = await redis.getAsync(EVENT_POSITION_KEY);
const pos = await redis.get(EVENT_POSITION_KEY);
if (pos) {
return pos.toString().split(':').map((z) => Number(z));
}
@ -67,7 +67,7 @@ export async function clearOldEvent() {
for (let jc = j - 1; jc <= j + 1; jc += 1) {
for (let ic = i - 1; ic <= i + 1; ic += 1) {
const chunkKey = `${EVENT_BACKUP_PREFIX}:${ic}:${jc}`;
const chunk = await redis.getAsync(chunkKey);
const chunk = await redis.get(chunkKey);
if (!chunk) {
logger.warn(
// eslint-disable-next-line max-len
@ -88,10 +88,10 @@ export async function clearOldEvent() {
const chunkArray = new Uint8Array(chunk);
await RedisCanvas.setChunk(ic, jc, chunkArray, CANVAS_ID);
}
await redis.delAsync(chunkKey);
await redis.del(chunkKey);
}
}
await redis.delAsync(EVENT_POSITION_KEY);
await redis.del(EVENT_POSITION_KEY);
}
}
@ -113,10 +113,10 @@ export async function setNextEvent(minutes, i, j) {
await RedisCanvas.setPixelInChunk(ic, jc, 0, 0, CANVAS_ID);
}
const chunkKey = `${EVENT_BACKUP_PREFIX}:${ic}:${jc}`;
await redis.setAsync(chunkKey, chunk);
await redis.set(chunkKey, chunk);
}
}
await redis.setAsync(EVENT_POSITION_KEY, `${i}:${j}`);
await redis.set(EVENT_POSITION_KEY, `${i}:${j}`);
const timestamp = Date.now() + minutes * 60 * 1000;
await redis.setAsync(EVENT_TIMESTAMP_KEY, timestamp);
await redis.set(EVENT_TIMESTAMP_KEY, timestamp);
}

View File

@ -47,7 +47,7 @@ class RedisCanvas {
// core/tilesBackup.js
// and ./EventData.js
const key = `ch:${canvasId}:${i}:${j}`;
return redis.getAsync(key);
return redis.get(key);
}
static async setChunk(i: number, j: number, chunk: Uint8Array,
@ -58,14 +58,14 @@ class RedisCanvas {
return false;
}
const key = `ch:${canvasId}:${i}:${j}`;
await redis.setAsync(key, Buffer.from(chunk.buffer));
await redis.set(key, Buffer.from(chunk.buffer));
RedisCanvas.execChunkChangeCallback(canvasId, [i, j]);
return true;
}
static async delChunk(i: number, j: number, canvasId: number) {
const key = `ch:${canvasId}:${i}:${j}`;
await redis.delAsync(key);
await redis.del(key);
chunks.delete(key);
RedisCanvas.execChunkChangeCallback(canvasId, [i, j]);
return true;
@ -95,15 +95,15 @@ class RedisCanvas {
if (!chunks.has(key)) {
if (canvases[canvasId].v) {
await redis.setAsync(key, THREE_EMPTY_CHUNK_BUFFER, 'NX');
await redis.set(key, THREE_EMPTY_CHUNK_BUFFER, 'NX');
} else {
await redis.setAsync(key, EMPTY_CHUNK_BUFFER, 'NX');
await redis.set(key, EMPTY_CHUNK_BUFFER, 'NX');
}
chunks.add(key);
}
const args = [key, 'SET', UINT_SIZE, `#${offset}`, color];
await redis.sendCommandAsync('bitfield', args);
await redis.sendCommand('bitfield', args);
RedisCanvas.execChunkChangeCallback(canvasId, [i, j]);
}
@ -122,7 +122,7 @@ class RedisCanvas {
UINT_SIZE,
`#${offset}`,
];
const result: ?number = await redis.sendCommandAsync('bitfield', args);
const result: ?number = await redis.sendCommand('bitfield', args);
if (!result) return null;
const color = result[0];
return color;

View File

@ -139,17 +139,17 @@ class User {
async setWait(wait: number, canvasId: number): Promise<boolean> {
if (!wait) return false;
// PX is milliseconds expire
await redis.setAsync(`cd:${canvasId}:ip:${this.ipSub}`, '', 'PX', wait);
await redis.set(`cd:${canvasId}:ip:${this.ipSub}`, '', 'PX', wait);
if (this.id != null) {
await redis.setAsync(`cd:${canvasId}:id:${this.id}`, '', 'PX', wait);
await redis.set(`cd:${canvasId}:id:${this.id}`, '', 'PX', wait);
}
return true;
}
async getWait(canvasId: number): Promise<?number> {
let ttl: number = await redis.pttlAsync(`cd:${canvasId}:ip:${this.ipSub}`);
let ttl: number = await redis.pTTL(`cd:${canvasId}:ip:${this.ipSub}`);
if (this.id != null) {
const ttlid: number = await redis.pttlAsync(
const ttlid: number = await redis.pTTL(
`cd:${canvasId}:id:${this.id}`,
);
ttl = Math.max(ttl, ttlid);

View File

@ -15,7 +15,7 @@ export async function saveDailyTop(dailyRanking) {
const top10 = dailyRanking.slice(0, 10).map((user) => user.id);
const jsonTop = JSON.stringify(top10);
logger.info(`Saving current daily top 10 into redis: ${jsonTop}`);
await redis.setAsync(PREV_DAILY_TOP_KEY, jsonTop);
await redis.set(PREV_DAILY_TOP_KEY, jsonTop);
return top10;
}
@ -24,7 +24,7 @@ export async function saveDailyTop(dailyRanking) {
* @return Promis<Array> Array of user IDs of the top 10
*/
export async function loadDailyTop() {
const jsonTop = await redis.getAsync(PREV_DAILY_TOP_KEY);
const jsonTop = await redis.get(PREV_DAILY_TOP_KEY);
logger.info(`Loaded current daily top 10 into redis: ${jsonTop}`);
return (jsonTop) ? JSON.parse(jsonTop) : [];
}

View File

@ -1,12 +1,15 @@
/* @flow */
import bluebird from 'bluebird';
import redis from 'redis';
import { createClient } from 'redis';
import { REDIS_URL } from '../core/config';
bluebird.promisifyAll(redis.RedisClient.prototype);
bluebird.promisifyAll(redis.Multi.prototype);
const client = redis.createClient(REDIS_URL, { return_buffers: true });
const redis = createClient({
path: REDIS_URL,
// needed for connect-redis
legacyMode: true,
});
export default client;
export const redisV3 = redis;
export default redis.v4;

View File

@ -3,15 +3,13 @@
* the actual notification that a captcha is needed is sent
* with the pixel return answer when sending apixel on websocket
*
* @flow
*/
import type { Request, Response } from 'express';
import logger from '../../core/logger';
import { checkCaptchaSolution } from '../../utils/captcha';
import { getIPFromRequest } from '../../utils/ip';
export default async (req: Request, res: Response) => {
export default async (req, res) => {
const ip = getIPFromRequest(req);
const { t } = req.ttag;

View File

@ -1,11 +1,8 @@
/**
*
* @flow
* send initial data to player
*/
import type { Request, Response } from 'express';
import getMe from '../../core/me';
import {
USE_PROXYCHECK,
@ -13,23 +10,27 @@ import {
import { cheapDetector } from '../../core/isProxy';
export default async (req: Request, res: Response) => {
const { user, lang } = req;
const userdata = await getMe(user, lang);
user.updateLogInTimestamp();
export default async (req, res, next) => {
try {
const { user, lang } = req;
const userdata = await getMe(user, lang);
user.updateLogInTimestamp();
const { trueIp: ip } = req;
if (USE_PROXYCHECK && ip !== '0.0.0.1') {
// pre-fire cheap Detector to give it time to get a real result
// once api_pixel needs it
cheapDetector(ip);
const { trueIp: ip } = req;
if (USE_PROXYCHECK && ip !== '0.0.0.1') {
// pre-fire cheap Detector to give it time to get a real result
// once api_pixel needs it
cheapDetector(ip);
}
// https://stackoverflow.com/questions/49547/how-to-control-web-page-caching-across-all-browsers
res.set({
'Cache-Control': 'no-cache, no-store, must-revalidate',
Pragma: 'no-cache',
Expires: '0',
});
res.json(userdata);
} catch (error) {
next(error);
}
// https://stackoverflow.com/questions/49547/how-to-control-web-page-caching-across-all-browsers
res.set({
'Cache-Control': 'no-cache, no-store, must-revalidate',
Pragma: 'no-cache',
Expires: '0',
});
res.json(userdata);
};

View File

@ -2,10 +2,8 @@
*
* Outputs binary chunk directly from redis
*
* @flow
*/
import type { Request, Response } from 'express';
import etag from 'etag';
import RedisCanvas from '../data/models/RedisCanvas';
import {
@ -24,7 +22,7 @@ RedisCanvas.setChunkChangeCallback((canvasId, cell) => {
/*
* Send binary chunk to the client
*/
export default async (req: Request, res: Response, next) => {
export default async (req, res, next) => {
const {
c: paramC,
x: paramX,

View File

@ -12,6 +12,7 @@ import forceGC from './core/forceGC';
import logger from './core/logger';
import rankings from './core/ranking';
import models from './data/models';
import { redisV3 } from './data/redis';
import routes from './routes';
import chatProvider from './core/ChatProvider';
@ -24,8 +25,6 @@ import { SECOND } from './core/constants';
import { startAllCanvasLoops } from './core/tileserver';
startAllCanvasLoops();
const app = express();
app.disable('x-powered-by');
@ -78,18 +77,19 @@ app.use(routes);
//
// ip config
// -----------------------------------------------------------------------------
// use this if models changed:
const promise = models.sync({ alter: { drop: false } })
// const promise = models.sync()
.catch((err) => logger.error(err.stack));
promise.then(() => {
rankings.updateRanking();
chatProvider.initialize();
server.listen(PORT, HOST, () => {
const address = server.address();
logger.log(
'info',
`web is running at http://${address.host}:${address.port}/`,
);
models.sync({ alter: { drop: false } })
.then(() => redisV3.connect())
.then(() => {
rankings.updateRanking();
chatProvider.initialize();
startAllCanvasLoops();
usersocket.initialize();
apisocket.initialize();
server.listen(PORT, HOST, () => {
const address = server.address();
logger.log(
'info',
`web is running at http://${address.host}:${address.port}/`,
);
});
});
});

View File

@ -41,7 +41,7 @@ async function verifyClient(info, done) {
class APISocketServer {
wss: WebSocket.Server;
constructor() {
initialize() {
logger.info('Starting API websocket server');
const wss = new WebSocket.Server({

View File

@ -61,8 +61,7 @@ class SocketServer {
wss: WebSocket.Server;
CHUNK_CLIENTS: Map<number, Array>;
// constructor(server: http.Server) {
constructor() {
initialize() {
this.CHUNK_CLIENTS = new Map();
logger.info('Starting websocket server');

View File

@ -82,7 +82,7 @@ export function setCaptchaSolution(
if (captchaid) {
key += `:${captchaid}`;
}
return redis.setAsync(key, text, 'EX', CAPTCHA_TIMEOUT);
return redis.set(key, text, 'EX', CAPTCHA_TIMEOUT);
}
/*
@ -107,12 +107,12 @@ export async function checkCaptchaSolution(
if (captchaid) {
key += `:${captchaid}`;
}
const solution = await redis.getAsync(key);
const solution = await redis.get(key);
if (solution) {
if (evaluateResult(solution.toString('utf8'), text)) {
if (!onetime) {
const solvkey = `human:${ipn}`;
await redis.setAsync(solvkey, '', 'EX', TTL_CACHE);
await redis.set(solvkey, '', 'EX', TTL_CACHE);
}
logger.info(`CAPTCHA ${ip} successfully solved captcha`);
return 0;
@ -138,7 +138,7 @@ export async function needCaptcha(ip) {
}
const key = `human:${getIPv6Subnet(ip)}`;
const ttl = await redis.ttlAsync(key);
const ttl = await redis.ttl(key);
if (ttl > 0) {
return false;
}

View File

@ -6,9 +6,6 @@
import { TILE_SIZE, CANVAS_SIZE, CANVAS_MIN_XY, CANVAS_MAX_XY } from '../src/core/constants';
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 oldurl = "redis://localhost:6380";
const oldredis = redis.createClient(oldurl, { return_buffers: true });
@ -95,7 +92,7 @@ async function createBasechunkFromMultipleOldChunks(x: number, y: number): Uint8
let na = 0;
for (let dy = 0; dy < CHUNKS_IN_BASETILE; dy += 1) {
for (let dx = 0; dx < CHUNKS_IN_BASETILE; dx += 1) {
const smallchunk = await oldredis.getAsync(`chunk:${xabs + dx}:${yabs + dy}`);
const smallchunk = await oldredis.get(`chunk:${xabs + dx}:${yabs + dy}`);
if (!smallchunk) {
na++;
continue;
@ -118,7 +115,7 @@ async function createBasechunkFromMultipleOldChunks(x: number, y: number): Uint8
if (na != CHUNKS_IN_BASETILE * CHUNKS_IN_BASETILE) {
const key = `chunk:${x}:${y}`;
const setNXArgs = [key, Buffer.from(chunkBuffer.buffer).toString('binary')]
await newredis.sendCommandAsync('SETNX', setNXArgs);
await newredis.sendCommand('SETNX', setNXArgs);
console.log("Created Chunk ", key, "with", na, "empty chunks");
}
}
@ -132,7 +129,7 @@ async function createBasechunk(x: number, y: number): Uint8Array {
const key = `chunk:${x}:${y}`;
const newChunk = new Uint8Array(TILE_SIZE * TILE_SIZE);
const smallchunk = await oldredis.getAsync(key);
const smallchunk = await oldredis.get(key);
if (!smallchunk) {
return
}
@ -147,7 +144,7 @@ async function createBasechunk(x: number, y: number): Uint8Array {
}
const setNXArgs = [key, Buffer.from(newChunk.buffer).toString('binary')]
await newredis.sendCommandAsync('SETNX', setNXArgs);
await newredis.sendCommand('SETNX', setNXArgs);
console.log("Created Chunk ", key);
}

View File

@ -2,9 +2,6 @@
//this script just copies chunks from one redis to another
import redis from 'redis';
import bluebird from 'bluebird';
bluebird.promisifyAll(redis.RedisClient.prototype);
bluebird.promisifyAll(redis.Multi.prototype);
import {
TILE_SIZE,
@ -26,10 +23,10 @@ async function copyChunks() {
for (let y = 0; y < CHUNKS_XY; y++) {
const oldkey = `ch:2:${x}:${y}`;
const newkey = `ch:2:${x}:${y}`;
const chunk = await oldredis.getAsync(oldkey);
const chunk = await oldredis.get(oldkey);
if (chunk) {
const setNXArgs = [newkey, chunk];
await newredis.sendCommandAsync('SET', setNXArgs);
await newredis.sendCommand('SET', setNXArgs);
console.log("Created Chunk ", newkey);
}
}
@ -49,13 +46,13 @@ async function copyChunksByCoords(xMin, xMax, yMin, yMax) {
for (let y = chunkYMin; y <= chunkYMax; y++) {
const oldkey = `ch:2:${x}:${y}`;
const newkey = `ch:2:${x}:${y}`;
const chunk = await oldredis.getAsync(oldkey);
const chunk = await oldredis.get(oldkey);
if (chunk) {
const setNXArgs = [newkey, chunk];
await newredis.sendCommandAsync('SET', setNXArgs);
await newredis.sendCommand('SET', setNXArgs);
console.log("Created Chunk ", newkey);
} else {
await newredis.delAsync(newkey);
await newredis.del(newkey);
console.log("Deleted Chunk ", newkey);
}
}

View File

@ -2,11 +2,6 @@
// this script moves chunks of a canvas, i.e. to center it after changing size
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";
@ -22,12 +17,12 @@ async function move() {
for (let x = CHUNKS_XY - 1; x >= 0; x--) {
for (let y = CHUNKS_XY - 1; y >= 0; y--) {
const key = `ch:1:${x}:${y}`;
const chunk = await redisc.getAsync(key);
const chunk = await redisc.get(key);
if (chunk) {
const buffer = new Uint8Array(chunk);
const newKey = `ch:1:${x + offset}:${y + offset}`
await redisc.setAsync(newKey, Buffer.from(buffer.buffer));
await redisc.delAsync(key);
await redisc.set(newKey, Buffer.from(buffer.buffer));
await redisc.del(key);
console.log('Moved Chunk ', key, ' to ', newKey);
}
}

View File

@ -2,11 +2,6 @@
//this script removes protection from all pixels on main canas
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!!!
@ -23,7 +18,7 @@ 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 redisc.getAsync(key);
const chunk = await redisc.get(key);
if (chunk) {
const buffer = new Uint8Array(chunk);
let changed = false;
@ -35,7 +30,7 @@ async function moveProtection() {
}
}
if (changed) {
await rediso.setAsync(key, Buffer.from(buffer.buffer));
await rediso.set(key, Buffer.from(buffer.buffer));
console.log("Changed Chunk ", key);
}
}

View File

@ -6,7 +6,6 @@
import redis from 'redis';
import sharp from 'sharp';
import bluebird from 'bluebird';
import canvases from '../src/canvases.json';
import Palette from '../src/core/Palette';
@ -17,8 +16,6 @@ import {
TILE_SIZE,
} from '../src/core/constants';
bluebird.promisifyAll(redis.RedisClient.prototype);
bluebird.promisifyAll(redis.Multi.prototype);
//ATTENTION Make suer to set the rdis URLs right!!!
const redisurl = "redis://localhost:6379";
const redisCanvas = redis.createClient(redisurl, { return_buffers: true });
@ -74,7 +71,7 @@ async function imageABGR2Canvas(
}
if (pxlCnt) {
const key = `ch:${canvasId}:${cx}:${cy}`;
await redisCanvas.setAsync(key, Buffer.from(chunk.buffer));
await redisCanvas.set(key, Buffer.from(chunk.buffer));
console.log(`Loaded ${pxlCnt} pixels into chunk ${cx}, ${cy}.`);
totalPxlCnt += pxlCnt;
}