balor / connect-memcached Goto Github PK
View Code? Open in Web Editor NEWMemcached session store for Connect
License: MIT License
Memcached session store for Connect
License: MIT License
Good morning,
While trying to run the new test suite I am receiving 500
responses on the any iteration after the initial request.
$ npm install
$ npm test
> connect-memcached@1.0.0 tests /connect-memcached
> NODE_ENV=test jest --testTimeout=10000
FAIL test/test.js
Plain memcached session store
GET / should increment views value at each request (92 ms)
Plain memcached session store > GET / should increment views at each request
expect(received).toEqual(expected) // deep equality
Expected: 200
Received: 500
10 | for (var i = 1; i < 50; i++) {
11 | const res = await serverAgent.get("/");
> 12 | expected(res.status).toEqual(200);
^
With npm 1.x / node 0.4.8+ modules are no longer global by default, so package.json should contain all dependencies:
, "dependencies": { "memcached": ">= 0.0.1", "connect": "*" }
to avoid a missing module:
$ npm install connect-memcached
$ node
> require("connect-memcached")
Error: Cannot find module 'connect'
Under what license is the code?
Hi,
I am using connect-memcached("0.2.0;') and express("3.1.0"). In my web application, there are two interface admin panel and site interface. I am using different session in both cases.
In admin panel, i always send backend = 1 in header.
var app = module.exports = express();
var session = express.session;
var MemcachedStore = require('connect-memcached')(session);
var host = process.env.MEMCACHE_PORT_11211_TCP_ADDR || sessionServer.host || 'localhost';
var port = process.env.MEMCACHE_PORT_11211_TCP_PORT || sessionServer.port || '11211';
var admin_session = session({
key: 'admin_token',
secret: 'aersda@#$32sfas2342',
cookie: {
maxAge: 30 * 24 * 60 * 60 * 1000,
},
store: new MemcachedStore({
hosts: host + ":" + port
})
});
var user_session = session({
key: 'jsessionid',
secret: 'aersda@#$32sfas2342',
cookie: {
maxAge: 30 * 24 * 60 * 60 * 1000,
},
store: new MemcachedStore({
hosts: host + ":" + port
})
});
app.use(function (req, res, next) {
console.log("Setting session ");
if (req.headers.backend == '1') {
admin_session(req, res, next);
} else {
user_session(req, res, next);
}
});
I am using google cloud instance for memcache.
When user login on my computer, it is working fine but on my client networks, user logout automatically after 10-15 min.
I console the cookies on server, cookies value is changed automatically and user logout. I don't know why it is happening.
How to debug and resolve it.
If I used redis server for session storage, then everything is working fine.
I have a project that already has a memcached instance created, yet when adding connect-memcached
, it will create a new instance of the client but i wanted to use the existing instance
Took a look at the code and i see i can pass in a client
at MemcachedStore()
, but for some reason in case a client is passed the secret option is ignored:
connect-memcached/lib/connect-memcached.js
Lines 32 to 53 in 5116ea3
Shouldn't the if (options.secret)
block be outside the if (!options.client)
?
Has this been abandoned? Latest non-readme changes are from May 2014
Care to add some maintainers if help is needed?
memcached recently updated to 0.0.8. The session store fails to record any entries in memcache on 0.0.8. Reverting to 0.0.7 fixes the issue.
Good morning, I see you have merged the latest crypto functionality updates. An apology is warranted, it seems the algorithm for the latest updates in the Readme.md
file also needs to change. The default is now aes-256-gcm
. The remaining verbiage can be removed as well. Have a good afternoon.
If using connect-memcached as session store in nodejs how can one confirm connectivity to memcached has occured?
I am wanting to ensure memcached is up and running and throw error/exception if nodejs application can't connect to memcached.
Thanks
I want to add a prefix to ensure that keys you set in memcache during the session are unique to my application.
I have tried setting it up as follows but not sure if I am doing it correctly, or how to check.
store: new MemcachedStore({
hosts: ['127.0.0.1:11211'],
prefix: prefix
})
here is my full code below:
app.use(session({
secret: 'CatOnKeyboard',
key: 'test',
proxy: 'true',
store : new MemcachedStore({
hosts: ['127.0.0.1:11211'],
prefix: prefix,
secret: '123, easy as ABC. ABC, easy as 123' // Optionally use transparent encryption for memcache session data
})
}));
Trying to get my app working with redis/memcachedcloud but I cannot find any place in config I could put my login and password details in. Does it mean connect-memcached won't work because it does not support authentication?
memjs has it
and there seems to be a library connect-memjs specially for this purpose.
Shouldn't that security be enabled somehow?
I am looking for an express session store using memcached, but supporting SASL. Does your library do this?
Hi,
i am using your solution to store my web app sessions with express.
Problem is that apparently the sessions expire after 60 seconds.
How do change this?
Thanks in advanced.
I tried to use some of the Example code in my app by making a few changes and it didn't worked. After hours of changing my code and 'adapting' it so that the memcached could work I tried to run just the example to know if I was the one wrong here.
So I copy paste the code, and run it and the same problem I was having with my app happened. When you access the designated URL for your app(example: 127.0.0.1:9341) it will keep loading and loading.
Please if I'm doing something wrong please tell me, otherwise it would be nice if you could fix this problem.
Thank You.
When trying to upgrade from v1 to v2 I get the following stacktrace when using the express-session:
TypeError: Cannot read properties of undefined (reading 'expires') (Most recent call first)
at MemcachedStore.Store.createSession (/var/www/app/node_modules/express-session/session/store.js line 87 col 28)
at inflate (/var/www/app/node_modules/express-session/index.js line 372 col 12)
at <unknown> (/var/www/app/node_modules/express-session/index.js line 499 col 10)
at Object.<anonymous> (/var/www/app/node_modules/connect-memcached/lib/connect-memcached.js line 99 col 1)
at exports.AsyncResource.runInAsyncScope (node:async_hooks line 202 col 8)
...
I'm still trying to dig into the details, but the missing session.cookies
doesn't look great.
This is for code not using encryption.
Hi, I'm getting this error:
APP | 2017-06-28 18:47: Server error: SyntaxError: Unexpected end of JSON input
APP | at JSON.parse (<anonymous>)
APP | at MemcachedStore.decryptData (/var/myapp/node_modules/connect-memcached/lib/connect-memcached.j s:180:27)
APP | at Object.callback (/var/myapp/node_modules/connect-memcached/lib/connect-memcached.js:85:52)
APP | at Client.memcached.delegateCallback (/var/myapp/node_modules/memcached/lib/memcached.js:687:12)
APP | at Client.rawDataReceived (/var/myapp/node_modules/memcached/lib/memcached.js:758:22)
APP | at Client.BufferBuffer (/var/myapp/node_modules/memcached/lib/memcached.js:678:12)
APP | at Socket.bowlofcurry (/var/myapp/node_modules/memcached/lib/utils.js:126:15)
APP | at emitOne (events.js:115:13)
APP | at Socket.emit (events.js:210:7)
APP | at addChunk (_stream_readable.js:252:12)
APP | at readableAddChunk (_stream_readable.js:235:13)
APP | at Socket.Readable.push (_stream_readable.js:197:10)
APP | at TCP.onread (net.js:588:20)
I added a console.log
to the line 180 of lib/memcached.js and I got this:
APP | 2017-06-28 18:50: 2323 '{"ct":"c8d2339bb4f7bb0ea299afbebb19ff312cb35b0ff04d5f3beec6d2ddc9108d43ee99cd4fec0c800f769d73fd189ebc4acbacc99b32538bd414acd672638a1de5cc910e97049427e549fcdfdfd7bb33fb14886cc6e2770001ce541fc918392b0665e0dc26427dc22cb7908b14bde65ee873181cf70971adb31bd9efc99ad2e602c464d62ea31a507b2b3c7a5193a0ac09bcfb6cad232d5eff9da5c5b41fee485b77474b8c304c9cbd503825fbab3ab554921b1d69d5313d162996979a7bfae9534bf99efffbbb690f7f549347b89a15339fccaf9b67f337b172c9c23c565df3102b6f4f5df906e648242b3b7c4141ded0ee8e684d225667af141347ac0d884b6ee85ed0554572874a8ac43b66bda63ae6603b5299e73eadc891d9ac722160e1be587e6db602add87f2faeef6c6c4ebb8a132c5bbcfe67758dd8c96fcd4e2dc2ff3d0c9952e0b58e30be75abefca3e7ed14a8650c1b5b70a7b9a4bdaf1452cc68c5e39a204f6e79507b90baeaead2667b2d399c5d1711375688e3a58dc1899c39684f2034ec65e3407aec9d62bbdd8bcc61faa9793c7fe73a09a4592ee0eec740d4b5aaa592ab2519bbb4b18c2580bb0ffafcf9ead8cd711e04c6d3c72132bbd4a11ae5caa0befeac3efe2ef32d48787f969bb05a163d706f1751dd18c714bf26411d7b717e584bf13e5573fd16b5f47345542655f2c7286f5089c4f692'
APP | 2017-06-28 18:50: Server error: SyntaxError: Unexpected end of JSON input
APP | at JSON.parse (<anonymous>)
APP | at MemcachedStore.decryptData (/var/myapp/n
(...)
I suppose that this is somehow connected with AWS (Memcache in RDS), when I run my app locally, nothing's wrong.
@balor do you have any idea how to work it around?
Thanks
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.