With Express, I can use Redis as session storage like this:
var express = require('express');
var app = express();
var RedisStore = require('connect-redis')(express);
app.use(express.cookieParser());
app.use(express.session({
store: new RedisStore({
host: 'localhost',
port: 6379,
db: 'test',
pass: '123456'
}),
secret: '123456789'
}));
But with Kraken, the session configuration is in the file config/middleware.json
. I changed the file to use connect-redis
as following:
{
"middleware": {
"session": {
"module": "connect-redis",
"secret": "99b91c387e6e049308fc31d3cfff5fd3149e419c"
}
}
}
This way, Kraken does use Redis as session storage but how do I suppose to pass Redis' options (password, host, db name...) like with Express?
The documentation for kraken-js is not very extensive. Hope it improves.
We had to dig into the code and understand the logic and we were able to solve.
Hope this help others who want to use Redis Session store with Kraken.js
Add "connect-redis" to package.json
"dependencies": {
...
"connect-redis": ">=1.0.0"
},
Install "connect-redis" module
npm install
In the config/middleware.json add the config as below
{
"middleware": {
"session": {
"module": "connect-redis",
"config": {
"host": "localhost",
"port": 6379,
"db": 1
},
"secret": "a1df0e81ef54d199567befb02761b1834c8b7406"
}
}
}
Change the config as required
Start/Restart server and it should work!
Provided you already have Redis running
A complete working example can be found here: https://github.com/AlexSantos/Kraken_Example_Session_Redis
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With