Skip to content

Commit

Permalink
Update redis connection docs to match latest Keyv API (#7944)
Browse files Browse the repository at this point in the history
The `@apollo/utils.keyvadapter` package was updated in
apollographql/apollo-utils#461 to be compatible
with Keyv v5. The primary change is that the `Keyv` constructor takes a
store instead of a string.

The constructor can be invoked in two ways:
```
// passed as first argument
new Keyv(new KeyvRedis("redis://..."))

// passed as store
new Keyv({ store: new KeyvRedis("redis://...") })
```

This updates the Redis examples in the documentation to match the new
API. For simplicity, I've stuck to the first format.
  • Loading branch information
tninesling authored Oct 23, 2024
1 parent bf28f54 commit 09f1b75
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions docs/source/performance/cache-backends.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,13 @@ npm install keyv @keyv/redis @apollo/utils.keyvadapter
### Single instance
```ts
import Keyv from "keyv";
import KeyvRedis from "@keyv/redis";
import { KeyvAdapter } from "@apollo/utils.keyvadapter";

const server = new ApolloServer({
typeDefs,
resolvers,
cache: new KeyvAdapter(new Keyv("redis://user:pass@localhost:6379")), // highlight-line
cache: new KeyvAdapter(new Keyv(new KeyvRedis("redis://user:pass@localhost:6379"))), // highlight-line
});
```

Expand All @@ -114,14 +115,14 @@ const server = new ApolloServer({
typeDefs,
resolvers,
// highlight-start
cache: new KeyvAdapter(
new Keyv("redis://user:pass@localhost:6379", {
cache: new KeyvAdapter(new Keyv(
new KeyvRedis("redis://user:pass@localhost:6379", {
sentinels: [
{ host: "localhost", port: 26379 },
{ host: "localhost", port: 26380 },
],
})
),
)),
// highlight-end
});
```
Expand Down Expand Up @@ -208,10 +209,11 @@ To provide error tolerance for cache backends that connect via a client (e.g., R

```typescript
import Keyv from "keyv";
import KeyvRedis from "@keyv/redis";
import { KeyvAdapter } from "@apollo/utils.keyvadapter";
import { ErrorsAreMissesCache } from "@apollo/utils.keyvaluecache";

const redisCache = new Keyv("redis://user:pass@localhost:6379");
const redisCache = new Keyv(new KeyvRedis("redis://user:pass@localhost:6379"));
const faultTolerantCache = new ErrorsAreMissesCache(
new KeyvAdapter(redisCache),
);
Expand Down

0 comments on commit 09f1b75

Please sign in to comment.