I'm trying to setup db sessions in Lucee without e...
# lucee
t
I'm trying to setup db sessions in Lucee without enabling
sessionCluster
(because I read it causes a db read on every request vs temp memory store). If I turn off
sessionCluster
, sessions only seem to last a few minutes before expiring, even though the session is still active in the DB, it's like it gets clear from the local memory and Lucee doesn't check the DB, it just assumes the session is empty or something. Can anyone clarify the bnhavuour here? There isn't much information out there on the internals of how all this works. I'm on Lucee 5.3.12.1 and here's my session config. Thanks!
Copy code
this.sessionManagement = true;
	this.sessionCluster = false;
	this.sessionTimeout = createTimespan(7,0,0,0);
	this.sessionStorage = 'rsessions';
    this.datasources={
		'rsessions' = {
			type: 'mysql',
			host: 'mariadb',
			database: 'rsessions',
			port: '3306',
			username: 'root',
			password: 'pass',
			connectionLimit: -1,
			blob: false,
			clob: true,
			storage: true,
			timezone: 'GMT',
			custom: { useUnicode:true, characterEncoding:'UTF-8' }
		}
	}
b
Cluster is required if you have more than one server.
If you only have a single server and just want to have external storage to back up the memory, then you can turn cluster off.
Either way, Lucee caches the session data in memory for a few minutes
What you're describing does seem like a bug that Lucee isn't ever getting the session scope back out of the DB.
t
Yeah, it's a single server which is why this behavior is so weird. I can't imagine I would be the first to have this issue if that were the case though.
b
Does it works if you enable session cluster
I've never found the reads to have a significant overhead, at least when used with Redis and Couchbase caches
t
Yeah, it works with SessionCluster enabled but the site gets high traffic, so within 8 or so hours we have 30,000 sessions and things slow down. I could move the session storage from Mysql to Redis. I'm using the following Docker image:
ortussolutions/commandbox:lucee5-alpine-3.7.12
- I'm guessing it doesn't have the Lucee Redis plugin built in. Is there a good guide for adding it? I also don't have access to the admin and prefer to configure everything programmatically and avoid the GUI.
b
I can't say I've ever used DB based sessions in production
I have no idea how well it works, but I would start by checking if indexes are added to the table
30k rows isn't that many unless you don't have indexes
You would install whatever Lucee extensions you wanted via the env vars Lucee supports.
t
Okay, I didn't have to install anything, turns out the Redis extension was already installed in the box image. Took 2 hours to figure out how to configure it in the application.cfc:
Copy code
this.cache.connections["redis"] = {
		class: 'lucee.extension.io.cache.redis.simple.RedisCache',
		storage: true,
		custom: {
			host: 'redis',
			port: 6379,
			timeout: 2000,
			password: 'pass'
		}
	};
	this.cache.defaultConnection = "redis";
	this.sessionStorage = 'redis';
Now I am seeing sessions flowing into the redis db which is great but now if I also want to use it as a cache store I guess I have to mix both session data and cache data in one db as I haven't seen an option to specific the db index in the settings yet.
Looks like I misspoke, Redis wasn't already in the image, it came from the mounted volume to the deploy directory with the lex I had added. However on startup, it removes the lex file so on the next start it crashes due to the missing value. Now I'm looking at doing it through env vars like you originally suggested, however I'm not sure where to find the guid identifier for the extension to add to the LUCEE_EXTENSIONS value
Got it: LUCEE_EXTENSIONS: 60772C12-F179-D555-8E2CD2B4F7428718;version=3.0.0.48
Alright I think I’m good to go. Thanks for helping me think through this @bdw429s!
b
Redis wasn't already in the image
Correct
it came from the mounted volume to the deploy directory with the lex I had added
Lol, how would you have gone through all that trouble and forgot you did it?
it removes the lex file so on the next start it crashes due to the missing value.
I have no idea what that means. Missing value??
I'm not sure where to find the guid identifier for the extension
Depends on which Redis extension you want. Lucee has their GUIDs on this page https://download.lucee.org/#60772C12-F179-D555-8E2CD2B4F7428718 Ortus has our own supported extension, here https://forgebox.io/view/5C558CC6-1E67-4776-96A60F9726D580F1
t
Lol, multitasking, then thought I forgot to drop the lex file in but turned out Lucee deleted it. Anyway, all good now. Now thinking about how I can implement pub/sub simple messaging into my app with Redis, more wondering how fleshed out this extension is.
b
The Lucee one isn't very fleshed out. One of the reasons we created ours
I'm actually pretty sure @lmajano added some pub/sub stuff into ours
I really like RabbitMQ though for pure messaging 🙂
Oh, and regarding this:
I guess I have to mix both session data and cache data in one db
That's not entirely true. You can create as many cache connection as you like in Lucee and use one of them for session storage and use another one for just data
as I haven't seen an option to specific the db index in the settings yet
I don't understand what this has to do at all with Redis 🤔
t
Redis allows for multiple DB’s in the config. Mine is set to 10 or something
b
Ahh, ok. A little confusing since you were talking about actual DB storage at the start of this thread. Like JDBC DB
At least, I assume that's what you meant. I'm not sure now, lol
My original comment about adding indexes, was in reference to an actual Database, not redis (which wasn't in the convo at that point)
t
Yeah, I followed :)
Bit of a mess but glad I finally upgraded from the default memory sessions
l
You can see all of our features there
with native redis db support as well
t
👍