views:

397

answers:

2

Hi there,

I am trying to figure out the most straightforward and safe way to count the number of active sessions using a memcached storage option. With DB based session storage, I can just count the number of rows in the table but can't do the same thing with memcached.

Thanks, Vikram

A: 

I don't think you can do that with memcache.

Must admit I am yet to use MemCacheStore but you could probably implement something using before filters in the application controller with a cron job and a table in your database.

Omar Qureshi
A: 

Memcache explicitly does not provide a way to iterate over the keys in use. You can read or write based on a specific key, but you can not get a list of all keys or iterate over them. This is a limitation of memcache.

Unfortunately, a before_filter won't work because sessions can be expired in memcached without your app being notified about it.

Why do you want to get this information?

Yehuda Katz
Hi there, Thanks for the answer. I want this information to display the number of users on the site, whether logged in or otherwise. Vikram
Vikram Goyal