denoland / denoland/examples

I was wondering if I need to add the `with-ioredis` example

Open
#10 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
114
Forks
37
PR merge metrics
No merged PRs in 30d

Description

Because `ioredis` is also another popular Redis client library

Here is my example code like the code in `with-redis`

```ts
import { Server } from "https://deno.land/std@0.148.0/http/server.ts";
import IORedis from 'npm:ioredis@5.2.4'

// make a connection to the local instance of redis
const client = new IORedis("redis://localhost:6379")

client.on("error", (error) => {
console.error(error);
});

const server = new Server({
handler: async (req) => {
const { pathname } = new URL(req.url);
// strip the leading slash
const username = pathname.substring(1);
const cached_user = await client.get(username);
if (cached_user) {
return new Response(cached_user, {
headers: {
"content-type": "application/json",
"is-cached": "true",
},
});
} else {
const resp = await fetch(`https://api.github.com/users/${username}`);
const user = await resp.json();
await client.set(username, JSON.stringify(user));
return new Response(JSON.stringify(user), {
headers: {
"content-type": "application/json",
"is-cached": "false",
},
});
}
},

port: 3000,
});

server.listenAndServe();
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.