Redis Server integration with ApolloServer3

Hi Team,
Am trying to do a POC where we wanted to integrate Redis cache with apolloserver. The document provided does not help in connecting all the wires.
in the Index.js I have the local redis server configured.

const server = new ApolloServer({
typeDefs,
resolvers,
cache: new BaseRedisCache({
client: new Redis({
host: ‘127.0.0.1’,
port: ‘6379’
})
}),
});
In the Resolver, trying to access the client so that I can set/get the KEY/Value to the redis instance.
Below code does not work as expected. Getting error since client cannot be accessed.

Query: {
get: (parent, { key }, { client }) => {
try {
return client.getAsync(key);
} catch (e) {
return null;
}
}
},

Mutation: {
set: async (parent, { key, value }, context) => {
try {
console.log(key + value);
await client.set(key, value);
return true;
} catch (e) {
console.log(e);
return false;
}

}
}
Here is the typeDefs for this.
type Query {
get(key: String!): String
}

type Mutation {
set(key: String!, value: String!): Boolean!
}

Any help is really appreciate on this.

did you follow docs from this link Data sources - Apollo GraphQL Docs ?

if yes there some issue with package apollo-server-cache-redis with Apollo Server 3.
when i use Apollo Server version 2, caching with Redis its working fine. after migrate to version 3 i got same issue like yours.

Solved it.
initialize redis like below.
const Redis = require(‘ioredis’);

const redisClient = new Redis();

Pass it in context like this. not like the way mentioned in document.
const server = new ApolloServer({
typeDefs,
resolvers,
context: () => ({ redisClient })
});

in resolvers access it via parameters and access it like below
context.redisClient.set/get()

then, where to close the Redis client?