superbeaver's avatar

Getting all Sessions for given user from Redis

When using Redis as Session driver, how can I list all Sessions for a given User? With database it is easy, I know that. I'm trying to do that with Redis.

0 likes
4 replies
superbeaver's avatar

@Sinnbeck

Do you mean this?

$data = $request->session()->all();
array:3 [▼
  "_token" => "mmgqMBJYs1atx3KB4Mwm0mKksFpVbCQvSixMnRe6"
  "_previous" => array:1 [▶]
  "_flash" => array:2 [▶]
]

This will just return my current session. I'm looking for all Sessions for a given User.

Sinnbeck's avatar

why multiple users @andyandy?

You will need to figure out the id of the session. I can look into how laravel finds it for a user.

Or you can explain why you would need access to the data of a specific user's session

willvincent's avatar

Sorry to raise this post from the dead, but I just published a package that makes this doable. It updates the DB (you control how often with a configurable throttle) so that redis sessions can be tracked/listed/destroyed.

User Agent enrichment happens automatically, and you can optionally install the MaxMind GeoLite2 DB and get Location detail too.

100% type coverage, test coverage, and phpstan at level 9.

https://github.com/willvincent/laravel-session-manager

1 like

Please or to participate in this conversation.