I am currently attempting to access the express-session data manually without relying on req.session.reload()
and req.session.save()
. My aim is to utilize Redisjson instead of the default redis. The problem I am encountering is that the express-session sets data using .get()
rather than .json.get()
(.get saves it as a string, preventing me from accessing the session through client.json.get()
.
In the express-session session.js file, the store is saved using:
defineMethod(Session.prototype, 'save', function save(fn) {
this.req.sessionStore.set(this.id, this, fn || function(){});
return this;
});
I have set up the store with the following code:
const RedisStore = require("connect-redis").default;
const { createClient } = require("redis");
require("dotenv").config();
const RedisClient = createClient({
url: `redis://localhost:${process.env.REDISPORT}`
});
RedisClient.connect();
const store = new RedisStore({ client: RedisClient });
const RedisJsonGet = RedisClient.json.get.bind(RedisClient.json);
const RedisJsonSet = RedisClient.json.set.bind(RedisClient.json);
const sessionmiddleware = session(
{
store: store,
secret: crypto.randomBytes(32).toString("hex"),
resave: false,
saveUninitialized: true
}
)
I am able to access RedisClient.json
methods as demonstrated in RedisJsonGet and Set, but when trying to access them within express-session, they are undefined.
Is there a way for me to access them within express-session?