-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathapp.ts
More file actions
54 lines (46 loc) · 1.8 KB
/
app.ts
File metadata and controls
54 lines (46 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import * as Sentry from '@sentry/deno';
import { createClient } from 'redis';
Sentry.init({
environment: 'qa',
dsn: Deno.env.get('E2E_TEST_DSN'),
debug: !!Deno.env.get('DEBUG'),
tunnel: 'http://localhost:3031/',
tracesSampleRate: 1,
});
// One shared client per process. node-redis publishes to the
// `node-redis:command` / `:batch` / `:connect` diagnostics channels for every
// operation on this client; denoRedisIntegration is already subscribed to
// those (it's part of the default integrations on Deno 2.7.13+).
const redis = createClient({
url: Deno.env.get('REDIS_URL') ?? 'redis://127.0.0.1:6379',
});
redis.on('error', err => {
// eslint-disable-next-line no-console
console.error('redis client error', err);
});
await redis.connect();
const port = 3030;
Deno.serve({ port, hostname: '0.0.0.0' }, async (req: Request) => {
const url = new URL(req.url);
// GET — exercises the command channel, success path.
if (url.pathname === '/redis-get') {
const key = url.searchParams.get('key') ?? 'cache:key';
const value = await redis.get(key);
return Response.json({ key, value });
}
// SET then GET — exercises two commands inside a single transaction so we
// can assert the parent has two db.redis children.
if (url.pathname === '/redis-set-get') {
const key = url.searchParams.get('key') ?? 'cache:key';
const value = url.searchParams.get('value') ?? 'hello';
await redis.set(key, value);
const echoed = await redis.get(key);
return Response.json({ key, value: echoed });
}
// MULTI — exercises the batch channel.
if (url.pathname === '/redis-multi') {
const result = await redis.multi().set('multi:a', '1').set('multi:b', '2').get('multi:a').exec();
return Response.json({ result });
}
return new Response('Not found', { status: 404 });
});