odedia
odedia

Reputation: 1001

Get active session count from Spring Session Redis

I need to know the number of active sessions in a Spring Cloud based application. It has multiple microservices, and Session information is shared using Redis (@EnableRedisHttpSession).

What would be valuable data to represent the number of active sessions? You'd think it is just the number of keys (Redis isn't used for anything else), but the keys count is a lot more - around 200, while there is maybe 20 active sessions in my test.

Thanks.

Upvotes: 1

Views: 2052

Answers (1)

Vedran Pavic
Vedran Pavic

Reputation: 2389

You need the keys that match the spring:session:sessions:[session_id_uuid] pattern, where [session_id_uuid] is the Spring Session generated id of a session.

This is assuming you're not using a custom key namespace (EnableRedisHttpSession#redisNamespace). If you do, you need to also take that into consideration so the pattern becomes spring:session:[namespace]:sessions:[session_id_uuid]

Upvotes: 1

Related Questions