Skip to content

Commit 09f1b75

Browse files
authored
Update redis connection docs to match latest Keyv API (#7944)
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.
1 parent bf28f54 commit 09f1b75

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

docs/source/performance/cache-backends.mdx

+7-5
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,13 @@ npm install keyv @keyv/redis @apollo/utils.keyvadapter
9696
### Single instance
9797
```ts
9898
import Keyv from "keyv";
99+
import KeyvRedis from "@keyv/redis";
99100
import { KeyvAdapter } from "@apollo/utils.keyvadapter";
100101

101102
const server = new ApolloServer({
102103
typeDefs,
103104
resolvers,
104-
cache: new KeyvAdapter(new Keyv("redis://user:pass@localhost:6379")), // highlight-line
105+
cache: new KeyvAdapter(new Keyv(new KeyvRedis("redis://user:pass@localhost:6379"))), // highlight-line
105106
});
106107
```
107108

@@ -114,14 +115,14 @@ const server = new ApolloServer({
114115
typeDefs,
115116
resolvers,
116117
// highlight-start
117-
cache: new KeyvAdapter(
118-
new Keyv("redis://user:pass@localhost:6379", {
118+
cache: new KeyvAdapter(new Keyv(
119+
new KeyvRedis("redis://user:pass@localhost:6379", {
119120
sentinels: [
120121
{ host: "localhost", port: 26379 },
121122
{ host: "localhost", port: 26380 },
122123
],
123124
})
124-
),
125+
)),
125126
// highlight-end
126127
});
127128
```
@@ -208,10 +209,11 @@ To provide error tolerance for cache backends that connect via a client (e.g., R
208209

209210
```typescript
210211
import Keyv from "keyv";
212+
import KeyvRedis from "@keyv/redis";
211213
import { KeyvAdapter } from "@apollo/utils.keyvadapter";
212214
import { ErrorsAreMissesCache } from "@apollo/utils.keyvaluecache";
213215

214-
const redisCache = new Keyv("redis://user:pass@localhost:6379");
216+
const redisCache = new Keyv(new KeyvRedis("redis://user:pass@localhost:6379"));
215217
const faultTolerantCache = new ErrorsAreMissesCache(
216218
new KeyvAdapter(redisCache),
217219
);

0 commit comments

Comments
 (0)