init redis lazy
This commit is contained in:
@@ -2,7 +2,7 @@ import { groupBy } from 'ramda';
|
||||
import SuperJSON from 'superjson';
|
||||
|
||||
import { deepMergeObjects } from '@openpanel/common';
|
||||
import { redis, redisPub } from '@openpanel/redis';
|
||||
import { getRedisCache, getRedisPub } from '@openpanel/redis';
|
||||
|
||||
import { ch, TABLE_NAMES } from '../clickhouse-client';
|
||||
import { transformEvent } from '../services/event.service';
|
||||
@@ -31,12 +31,12 @@ export class EventBuffer extends RedisBuffer<IClickhouseEvent> {
|
||||
constructor() {
|
||||
super({
|
||||
table: TABLE_NAMES.events,
|
||||
redis,
|
||||
redis: getRedisCache(),
|
||||
});
|
||||
}
|
||||
|
||||
public onInsert?: OnInsert<IClickhouseEvent> | undefined = (event) => {
|
||||
redisPub.publish(
|
||||
getRedisPub().publish(
|
||||
'event:received',
|
||||
SuperJSON.stringify(transformEvent(event))
|
||||
);
|
||||
@@ -54,7 +54,7 @@ export class EventBuffer extends RedisBuffer<IClickhouseEvent> {
|
||||
savedEvents
|
||||
) => {
|
||||
for (const event of savedEvents) {
|
||||
redisPub.publish(
|
||||
getRedisPub().publish(
|
||||
'event:saved',
|
||||
SuperJSON.stringify(transformEvent(event))
|
||||
);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { mergeDeepRight } from 'ramda';
|
||||
|
||||
import { toDots } from '@openpanel/common';
|
||||
import { redis } from '@openpanel/redis';
|
||||
import { getRedisCache } from '@openpanel/redis';
|
||||
|
||||
import { ch, chQuery } from '../clickhouse-client';
|
||||
import type {
|
||||
@@ -22,7 +22,7 @@ import { RedisBuffer } from './buffer';
|
||||
export class ProfileBuffer extends RedisBuffer<IClickhouseProfile> {
|
||||
constructor() {
|
||||
super({
|
||||
redis,
|
||||
redis: getRedisCache(),
|
||||
table: 'profiles',
|
||||
batchSize: 100,
|
||||
});
|
||||
|
||||
@@ -3,7 +3,7 @@ import { escape } from 'sqlstring';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
|
||||
import { toDots } from '@openpanel/common';
|
||||
import { redis } from '@openpanel/redis';
|
||||
import { getRedisCache } from '@openpanel/redis';
|
||||
import type { IChartEventFilter } from '@openpanel/validation';
|
||||
|
||||
import { eventBuffer } from '../buffers';
|
||||
@@ -184,7 +184,7 @@ export function transformMinimalEvent(
|
||||
}
|
||||
|
||||
export async function getLiveVisitors(projectId: string) {
|
||||
const keys = await redis.keys(`live:event:${projectId}:*`);
|
||||
const keys = await getRedisCache().keys(`live:event:${projectId}:*`);
|
||||
return keys.length;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user