Skip to content

Commit

Permalink
dyk-counts: fix redis hmset
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharthvp committed Jun 24, 2024
1 parent c0f4582 commit 490312b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions dyk-counts/eventstream-trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ export default class DykCounts extends Route {

const keyValues = queryResult.flatMap(e => [e.username, e.noms]) as string[];
await redis.del('dyk-counts').catch(e => this.redisError(e));
await redis.hmset.apply(null, ['dyk-counts'].concat(keyValues)).catch(e => this.redisError(e));
const redisArgs = ['dyk-counts'].concat(keyValues) as [string, ...string[]]; // TS: array with at least one element
await redis.hmset(...redisArgs).catch(e => this.redisError(e));
} catch (e) {
this.log(`[E] Error while running db refresh`, e);
}
Expand Down Expand Up @@ -127,6 +128,6 @@ export default class DykCounts extends Route {
if (err.command === 'HMSET') {
err.args = [err.args[0], '<snipped>']; // too big to log!
}
this.log(`[E] Redis error: `, err)
this.log(`[E] dyk-counts redis error: `, err)
}
}
6 changes: 6 additions & 0 deletions redis-io.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {Redis} from "ioredis"
import {onToolforge, readFile} from "./utils";
import {log} from "./botbase";

export const redis = new Redis({
host: onToolforge() ? 'tools-redis' : 'localhost',
Expand All @@ -9,3 +10,8 @@ export const redis = new Redis({
// A secret prefix string is stored in redis-key-prefix.txt
keyPrefix: readFile(__dirname + '/redis-key-prefix.txt'),
});

redis.on('error', err => {
log(`[E] Redis error:`);
log(err);
});
2 changes: 2 additions & 0 deletions utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export function createLogStream(file: string) {
let stringified;
if (typeof msg === 'string') {
stream.write(`[${ts}] ${msg}\n`);
} else if (msg instanceof Error) {
stream.write(`[${ts}] ${msg.stack}`)
} else if (stringified = stringifyObject(msg)) {
stream.write(`[${ts}] ${stringified}\n`);
} else {
Expand Down

0 comments on commit 490312b

Please sign in to comment.