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.