Redis instance is being mapped only once per app visit and only to the page that is being hit
See original GitHub issuePrerequisites
- I have written a descriptive issue title
- I have searched existing issues to ensure the issue has not already been raised
Issue
Reproducible demo/repo here
I am mapping my redis instance to req.raw
, but for some reason, it doesn’t persist through page navigations, even if you return to the same page.
In my afterHandler, I’m doing the following:
fastify.next('/', (app, req, reply) => {
req.raw.redisInstance = fastify.redis;
app.render(req.raw, reply.raw, '/', req.query);
});
fastify.next('/another', (app, req, reply) => {
req.raw.redisInstance = fastify.redis;
app.render(req.raw, reply.raw, '/another', req.query);
});
If you visit the index
file or the another
route, then the redis instance will be available the first time. The redis instance is also available if you refresh the page.
However if you first first index
, then go to another
, and then go back to index
, the reference to the redis instance is lost.
I’ve tried doing as was suggested here, but to no avail.
What am I doing wrong here?
Issue Analytics
- State:
- Created 2 years ago
- Comments:11 (8 by maintainers)
Top Results From Across the Web
Diagnosing latency issues - Redis
Enable and use the Latency monitor feature of Redis in order to get a human readable description of the latency events and causes...
Read more >How to Monitor Redis Performance Metrics - Datadog
Metric to watch: hit rate. When using Redis as a cache, monitoring the cache hit rate can tell you if your cache is...
Read more >Redis-specific parameters - Amazon ElastiCache for Redis
cluster.on – Use this parameter group, or one derived from it, for Redis (cluster mode enabled) clusters and replication groups.
Read more >Connect to a Redis instance - Memorystore - Google Cloud
If you don't already have a Compute Engine VM that uses that same authorized network as your Redis instance, create one and connect...
Read more >Moodle in English: Moodle performance during ... - Moodle.org
Visiting notification page is purging all opcache and overwriting muc/config. ... I could only suggest to create two different Redis instances, one for...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
After looking into the suggestion that @climba03003 proposed, I’ve realised that there could be a very easy solution to this issue which doesn’t require a change in the plugin.
@mkhoussid: In order to achieve to have the redis instance on all of the requests you could simply just add a
onRequest
hook and move the logic from yourafterHandler
to the hook and that will solve the problem.Here is the full code (from your example):
server.js:
afterHandler.js
Works.
Sorry @radomird , docs are great, but writing them sucks.