PHPackages                             playbase-oss/laravel-redis-session-enhanced - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. playbase-oss/laravel-redis-session-enhanced

ActiveLibrary[Caching](/categories/caching)

playbase-oss/laravel-redis-session-enhanced
===========================================

Enhanced redis driver for sessions in Laravel

v2.1.0(2mo ago)184MITPHPPHP ^8.2CI passing

Since Mar 22Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/PlayBase-OSS/laravel-redis-session-enhanced)[ Packagist](https://packagist.org/packages/playbase-oss/laravel-redis-session-enhanced)[ Docs](https://github.com/PlayBase-OSS/laravel-redis-session-enhanced)[ RSS](/packages/playbase-oss-laravel-redis-session-enhanced/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (2)Dependencies (5)Versions (3)Used By (0)

Laravel Redis Session Enhanced
==============================

[](#laravel-redis-session-enhanced)

[![Total Downloads](https://camo.githubusercontent.com/65ee7779328ae58d070d335dac8c26aa885bd78d8ae5fc946146d6473f7783f8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f706c6179626173652d6f73732f6c61726176656c2d72656469732d73657373696f6e2d656e68616e636564)](https://packagist.org/packages/playbase-oss/laravel-redis-session-enhanced)[![Latest Stable Version](https://camo.githubusercontent.com/87075cdef54ed0a3c6e739c4f59bab6c1cda501d1eaf4626b4b7165763b594a3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f706c6179626173652d6f73732f6c61726176656c2d72656469732d73657373696f6e2d656e68616e6365643f6c6162656c3d76657273696f6e)](https://packagist.org/packages/playbase-oss/laravel-redis-session-enhanced)[![License](https://camo.githubusercontent.com/69e4a50f802e8bf7ca2296bbb129b92d5812c6d8cd450244559e397db6da51db/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f706c6179626173652d6f73732f6c61726176656c2d72656469732d73657373696f6e2d656e68616e636564)](https://packagist.org/packages/playbase-oss/laravel-redis-session-enhanced)[![Status](https://github.com/PlayBase-OSS/laravel-redis-session-enhanced/actions/workflows/test.yml/badge.svg)](https://github.com/PlayBase-OSS/laravel-redis-session-enhanced/actions/workflows/test.yml)

A Redis session driver for Laravel that stores rich session metadata — `user_id`, `ip_address`, `user_agent`, and `last_activity` — alongside the session payload. This gives you the same session management capabilities as Laravel's database driver, but backed by Redis.

**Use this if you want to:**

- Track active sessions per user
- Implement "logout from other devices"
- Force-logout users (individually or all at once)
- Prevent concurrent sessions

Requirements
------------

[](#requirements)

- PHP `^8.2`
- Laravel `^11.0 | ^12.0`
- Redis configured in your Laravel application

Installation
------------

[](#installation)

```
composer require playbase-oss/laravel-redis-session-enhanced
```

The service provider is auto-discovered via Laravel's package discovery.

Configuration
-------------

[](#configuration)

**1. Add a dedicated Redis connection for sessions in `config/database.php`:**

```
'redis' => [
    // ... existing connections

    'session' => [
        'host'     => env('REDIS_HOST', '127.0.0.1'),
        'password' => env('REDIS_PASSWORD', null),
        'port'     => env('REDIS_PORT', 6379),
        'database' => env('REDIS_SESSION_DB', 2),
    ],
],
```

Using a separate database index keeps session keys isolated from cache and queue data, making it trivial to flush all sessions without affecting other Redis data.

**2. Update your `.env`:**

```
SESSION_DRIVER=redis-session
SESSION_CONNECTION=session
```

If you have a cached config, clear it:

```
php artisan config:clear
```

Session Data Structure
----------------------

[](#session-data-structure)

Each session is stored as a JSON object with the following shape:

```
{
    "user_id": 1,
    "ip_address": "127.0.0.1",
    "user_agent": "Mozilla/5.0 ...",
    "last_activity": 1711234567,
    "payload": ""
}
```

Usage
-----

[](#usage)

### SessionHelper

[](#sessionhelper)

`SessionHelper` abstracts over both the `redis-session` and `database` drivers, so you can switch between them without changing application code.

```
use PlayBaseOss\LaravelRedisSessionEnhanced\Support\SessionHelper;

// Get all sessions for a user
SessionHelper::getForUser($userId);

// Get only active sessions (within SESSION_LIFETIME)
SessionHelper::getForUser($userId, only_active: true);

// Delete all sessions of a user except the current one
SessionHelper::deleteForUserExceptSession($userId, request()->session()->id());

// Delete all sessions of a user
SessionHelper::deleteForUserExceptSession($userId);

// Delete all sessions (every user)
SessionHelper::deleteAll();

// Check if the application is using a supported driver
SessionHelper::isUsingValidDriver(); // true for database or redis-session
```

### Direct Handler Access

[](#direct-handler-access)

You can resolve the underlying `RedisSessionEnhancerHandler` directly from the session facade:

```
use PlayBaseOss\LaravelRedisSessionEnhanced\Session\RedisSessionEnhancerHandler;

/** @var RedisSessionEnhancerHandler $handler */
$handler = Session::getHandler();

// Get all sessions as a Collection of SessionData objects
$sessions = $handler->readAll();

// Flush all session data from Redis
$handler->destroyAll();
```

### SessionData

[](#sessiondata)

`readAll()` returns a `Collection` of `SessionData` objects:

```
use PlayBaseOss\LaravelRedisSessionEnhanced\Session\SessionData;

$session->id;            // string  — session ID
$session->user_id;       // mixed   — authenticated user ID, or null
$session->ip_address;    // string  — client IP address
$session->user_agent;    // string  — client User-Agent (truncated to 500 chars)
$session->last_activity; // int     — Unix timestamp of last activity
$session->payload;       // string  — base64-encoded session payload
```

Migrating from v1
-----------------

[](#migrating-from-v1)

The package has been transferred to PlayBase-OSS. Update your `composer.json`:

```
composer remove craftsys/laravel-redis-session-enhanced
composer require playbase-oss/laravel-redis-session-enhanced
```

Update any direct class references in your application:

v1v2`Craftsys\LaravelRedisSessionEnhanced\SessionHelper``PlayBaseOss\LaravelRedisSessionEnhanced\Support\SessionHelper``Craftsys\LaravelRedisSessionEnhanced\RedisSessionEnhancerHandler``PlayBaseOss\LaravelRedisSessionEnhanced\Session\RedisSessionEnhancerHandler`Credits
=======

[](#credits)

- [Craftsys](https://github.com/craftsys/laravel-redis-session-enhanced)

License
-------

[](#license)

MIT

###  Health Score

41

—

FairBetter than 87% of packages

Maintenance84

Actively maintained with recent releases

Popularity15

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity47

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~12 days

Total

2

Last Release

84d ago

PHP version history (2 changes)v2.0.0PHP ^8.2|^8.3|^8.4

v2.1.0PHP ^8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/18230443?v=4)[Jacek Maciejak](/maintainers/RikoDEV)[@RikoDEV](https://github.com/RikoDEV)

---

Top Contributors

[![RikoDEV](https://avatars.githubusercontent.com/u/18230443?v=4)](https://github.com/RikoDEV "RikoDEV (11 commits)")[![sudkumar](https://avatars.githubusercontent.com/u/6812992?v=4)](https://github.com/sudkumar "sudkumar (9 commits)")[![semantic-release-bot](https://avatars.githubusercontent.com/u/32174276?v=4)](https://github.com/semantic-release-bot "semantic-release-bot (6 commits)")

---

Tags

phplaravelredissession

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/playbase-oss-laravel-redis-session-enhanced/health.svg)

```
[![Health](https://phpackages.com/badges/playbase-oss-laravel-redis-session-enhanced/health.svg)](https://phpackages.com/packages/playbase-oss-laravel-redis-session-enhanced)
```

###  Alternatives

[spatie/laravel-responsecache

Speed up a Laravel application by caching the entire response

2.8k8.7M64](/packages/spatie-laravel-responsecache)[awssat/laravel-visits

Laravel Redis visits counter for Eloquent models

974169.8k2](/packages/awssat-laravel-visits)[spiritix/lada-cache

A Redis based, automated and scalable database caching layer for Laravel

591452.8k2](/packages/spiritix-lada-cache)[yangusik/laravel-balanced-queue

Laravel queue management with load balancing between partitions (user groups)

8512.6k](/packages/yangusik-laravel-balanced-queue)[craftsys/laravel-redis-session-enhanced

Enhanced redis driver for sessions in Laravel

107.0k](/packages/craftsys-laravel-redis-session-enhanced)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
