liamdon / connect-memjs Goto Github PK
View Code? Open in Web Editor NEWMemcached session store for Connect backed by memjs
Memcached session store for Connect backed by memjs
hi,
i have been using this libray for a while now. but now i want to set my own ttl in set method i:e not using session maxage but there is no support for it in your libray. i have tried some code and seems to be working. i also have tried to update the same on the repo but not authorised. please have a look on the code
MemcachedStore.prototype.set = function(sid, sess, fn,maxAgettl) {
sid = this.getKey(sid);
try {
var defaultCokie = { httpOnly: true, secure : false, maxAge : (4 * 60 * 60)};
var cookie = sess.cookie && sess.cookie||defaultCokie;
var maxAge = maxAgettl && maxAgettl||cookie.maxAge;
var ttl = 'number' == typeof maxAge ? maxAge | 0 : oneDay
var sess = JSON.stringify(sess);
this.client.set(sid, sess, function() {
fn && fn.apply(this, arguments);
}, ttl);
} catch (err) {
fn && fn(err);
}
};
Hello,
I get the following error on the second request:
Error: connect ECONNREFUSED 127.0.0.1:11211
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1161:16)
It is worth mentioning that the requests are different but they access the same user session.
Request 1:
router.get('/login',(req,res) => {
var sess = req.session;
sess.email = req.query.email;
res.send('done');
});
Request 2:
router.get('/admin',(req,res) => {
var sess = req.session;
if(sess.email) {
res.send(`Hello ${sess.email}`);
} else {
res.send('Please login first.');
}
});
My config:
const session = require("express-session");
var MemcachedStore = require('connect-memjs')(session);
...
app.use(session({
store: new MemcachedStore({
hosts: ["127.0.0.1:11211"]
}),
secret: '....',
resave: false,
saveUninitialized: false,
proxy: true,
cookie: {
maxAge: 1000 * 60 * 15
}
}));
Thanks greetings.
The current code sets servers if none are given. This breaks memjs' ability to retrieve the servers from environment variables.
Suggestion: don't provide a default, just leave servers unset when not specified.
with memjs 0.10.0 I get a deprecated notification:
MemJS SET: using deprecated call - arguments have changed
just change this:
this.client.set(sid, sess, function() {
fn && fn.apply(this, arguments);
}, ttl);
to:
this.client.set(sid, sess, {expires:ttl}, function() {
fn && fn.apply(this, arguments);
});
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.