MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / createRedisClient

Function createRedisClient

packages/redis/redis.ts:22–64  ·  view source on GitHub ↗
(
  name: string,
  url: string,
  overrides: RedisOptions = {},
)

Source from the content-addressed store, hash-verified

20}
21
22const createRedisClient = (
23 name: string,
24 url: string,
25 overrides: RedisOptions = {},
26): ExtendedRedis => {
27 const client = new Redis(url, {
28 ...options,
29 ...overrides,
30 }) as ExtendedRedis;
31
32 client.on('error', (error) => {
33 console.error(`[${name}] Redis Client Error:`, error);
34 });
35
36 client.getJson = async <T = any>(key: string): Promise<T | null> => {
37 const value = await client.get(key);
38 if (value) {
39 const res = getSuperJson(value) as T;
40 if (res && Array.isArray(res) && res.length === 0) {
41 return null;
42 }
43
44 if (res && typeof res === 'object' && Object.keys(res).length === 0) {
45 return null;
46 }
47
48 if (res) {
49 return res;
50 }
51 }
52 return null;
53 };
54
55 client.setJson = async <T = any>(
56 key: string,
57 expireInSec: number,
58 value: T,
59 ): Promise<void> => {
60 await client.setex(key, expireInSec, setSuperJson(value));
61 };
62
63 return client;
64};
65
66let redisCache: ExtendedRedis;
67export function getRedisCache() {

Callers 5

getRedisCacheFunction · 0.85
getRedisSubFunction · 0.85
getRedisPubFunction · 0.85
getRedisQueueFunction · 0.85
getRedisGroupQueueFunction · 0.85

Calls 4

getSuperJsonFunction · 0.90
setSuperJsonFunction · 0.90
errorMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected