Skip to content

Commit

Permalink
redis: switch to ioredis client lib
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharthvp committed Jun 24, 2024
1 parent 1cd1800 commit c0f4582
Show file tree
Hide file tree
Showing 6 changed files with 252 additions and 50 deletions.
3 changes: 1 addition & 2 deletions db-tabulator/web-endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@ import {
} from "./app";
import {createLogStream, mapPath} from "../utils";
import {bot} from "../botbase";
import {getRedisInstance} from "../redis";
import {EventEmitter} from "events";
import {EnwikiWebDb} from "../db";
import {redis} from "../redis-io";

const router = express.Router();

const log = createLogStream(mapPath('~/web-dbtb.out'));
const redis = getRedisInstance();

/** Store the list of pages currently undergoing update as a redis set */
const redisKey = 'web-db-tabulator-pages';
Expand Down
10 changes: 4 additions & 6 deletions dyk-counts/eventstream-trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ import {bot} from "../botbase";
import {Route} from "../eventstream-router/app";
import {createLocalSSHTunnel} from "../utils";
import {ENWIKI_DB_HOST, enwikidb} from "../db";
import {Redis, getRedisInstance} from "../redis";
import {RecentChangeStreamEvent} from "../eventstream-router/RecentChangeStreamEvent";
import {Cache, CacheClass} from "memory-cache";
import {ReplyError} from 'redis';
import {DAY, SECOND} from "../millis";
import {redis} from "../redis-io";

export default class DykCounts extends Route {
name = 'dyk-counts';

db: enwikidb;
redis: Redis;

counts: Record<string, number> = {};
unflushedChanges: Record<string, string[]> = {};
Expand All @@ -31,7 +30,6 @@ export default class DykCounts extends Route {

await createLocalSSHTunnel(ENWIKI_DB_HOST);
this.db = new enwikidb();
this.redis = getRedisInstance();

bot.setOptions({ maxRetries: 0, defaultParams: { maxlag: undefined } });
await bot.getTokensAndSiteInfo();
Expand Down Expand Up @@ -60,8 +58,8 @@ export default class DykCounts extends Route {
await this.saveCounts('Refreshing counts from database');

const keyValues = queryResult.flatMap(e => [e.username, e.noms]) as string[];
await this.redis.del('dyk-counts').catch(e => this.redisError(e));
await this.redis.hmset.apply(null, ['dyk-counts'].concat(keyValues)).catch(e => this.redisError(e));
await redis.del('dyk-counts').catch(e => this.redisError(e));
await redis.hmset.apply(null, ['dyk-counts'].concat(keyValues)).catch(e => this.redisError(e));
} catch (e) {
this.log(`[E] Error while running db refresh`, e);
}
Expand Down Expand Up @@ -110,7 +108,7 @@ export default class DykCounts extends Route {
this.dupeCache.put(title, true, 300); // 5 min timeout

this.counts[user] = (this.counts[user] || 0) + 1;
this.redis.hincrby('dyk-counts', user, 1).catch(e => this.redisError(e));
redis.hincrby('dyk-counts', user, 1).catch(e => this.redisError(e));
this.unflushedChanges[user] = (this.unflushedChanges[user] || []).concat(title);
this.log(`[i] Crediting "${user}" for [[${title}]]`);

Expand Down
4 changes: 1 addition & 3 deletions dyk-counts/web-endpoint.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import * as express from "express";
import 'express-async-errors';
import {enwikidb} from "../db";
import {getRedisInstance} from "../redis";
import {redis} from "../redis-io";

const router = express.Router();
const db = new enwikidb();

const redis = getRedisInstance()

router.get('/credits/:user', async (req, res, next) => {
const user = req.params.user.replace(/ /g, '_');
const result = await db.query(`
Expand Down
Loading

0 comments on commit c0f4582

Please sign in to comment.