PHPackages                             craftsys/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. craftsys/laravel-redis-session-enhanced

ActiveLibrary[Caching](/categories/caching)

craftsys/laravel-redis-session-enhanced
=======================================

Enhanced redis driver for sessions in Laravel

v1.0.5(2y ago)106.6k↓39.3%6[1 PRs](https://github.com/craftsys/laravel-redis-session-enhanced/pulls)MITPHPPHP ^7.1.3|^8.0|^8.1

Since Apr 25Pushed 2y ago1 watchersCompare

[ Source](https://github.com/craftsys/laravel-redis-session-enhanced)[ Packagist](https://packagist.org/packages/craftsys/laravel-redis-session-enhanced)[ Docs](https://github.com/craftsys/laravel-redis-session-enhanced)[ RSS](/packages/craftsys-laravel-redis-session-enhanced/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (6)Dependencies (3)Versions (7)Used By (0)

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

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

[![Total Downloads](https://camo.githubusercontent.com/63af4c838d70f455573548e43fe1b604e97ec4e39c428a5242c7c52663c7963d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f63726166747379732f6c61726176656c2d72656469732d73657373696f6e2d656e68616e636564)](https://packagist.org/packages/craftsys/laravel-redis-session-enhanced)[![Latest Stable Version](https://camo.githubusercontent.com/a3ce676b16f439cce311c9a8d37cbc99ba93c5ac2982d7e964cd3b4a07805176/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f63726166747379732f6c61726176656c2d72656469732d73657373696f6e2d656e68616e6365643f6c6162656c3d76657273696f6e)](https://packagist.org/packages/craftsys/laravel-redis-session-enhanced)[![License](https://camo.githubusercontent.com/52d6b6854e531f58e4f249093f112bf6b97c398f4be6d113a96f70ba2724e28f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f63726166747379732f6c61726176656c2d72656469732d73657373696f6e2d656e68616e636564)](https://packagist.org/packages/craftsys/laravel-redis-session-enhanced)[![Status](https://github.com/craftsys/laravel-redis-session-enhanced/actions/workflows/test.yml/badge.svg)](https://github.com/craftsys/laravel-redis-session-enhanced/actions/workflows/test.yml)

The [Laravel's Database Session Driver](https://laravel.com/docs/session#database) manages sessions in the Database which associates following attributes (along with the payload) with every session update: `user_id`, `ip_address`, `user_agent`, and `last_activty`. These attributes can be accessed and modified to provide following capabilities to your customers

- Track Active Sessions
- Remove Other Sessions (Logout from other devices)
- Allow Admins to force logout some/everyone
- Block Multiple Sessions

But with the Database driver, **every request to your application will do a Database update** to sessions table to track the latest session information, specifically, the `last_activty` attribute. This database update is required to validate unauthenticated requests if the session becomes inactive for the configured `SESSION_LIFETIME`. These session updates on every requests are fast and should not have much performance impact on your request time. But, if you ARE facing performance issues and want to store the session in the redis cache, you can go the [Laravel's Redis Session Driver](https://laravel.com/docs/session#redis). The redis driver will store and validate the session automatically but you will loose the above mentioned capabilities for your customers (tracking, logouts etc.).

If you want to have similar capabilities as the Database Session driver but want to use Redis for session storage, this project is for you.

Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Configuration](#configuration)
- [Usage](#usage)

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

[](#installation)

The packages is available on [Packagist](https://packagist.org/packages/craftsys/laravel-redis-session-enhanced) and can be installed via [Composer](https://getcomposer.org/) by executing following command in shell.

```
composer require craftsys/laravel-redis-session-enhanced
```

**prerequisite**

- php^7.1
- laravel^5|^6|^7|^8|^9|^10|^11
- redis installed and configured for laravel

The package is tested for 5.8+,^6.0,^7.0,^8.0,^9.0,^10.0,^11.0 only.

### Laravel 5.5+

[](#laravel-55)

If you're using Laravel 5.5 or above, the package will automatically register the `Craftsys\LaravelRedisSessionEnhanced\RedisSessionEnhancedServiceProvider` provider.

### Laravel 5.4 and below

[](#laravel-54-and-below)

Add `Craftsys\LaravelRedisSessionEnhanced\RedisSessionEnhancedServiceProvider` to the `providers` array in your `config/app.php`:

```
'providers' => [
     // Other service providers...
     Craftsys\LaravelRedisSessionEnhanced\RedisSessionEnhancedServiceProvider::class,
],
```

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

[](#configuration)

The package usage your existing configuration files and requires following modification in configs and env file.

1. Add a new connection named `session` in your `config/database.php` redis configuration

```
[
  'redis' => [
     // ... existing configuration
     // Add new connection for session
     'session' => [
        'host' => env('REDIS_HOST', '127.0.0.1'),
        'password' => env('REDIS_PASSWORD', null),
        'port' => env('REDIS_PORT', 6379),
        // new DB, only for sessions for quick access and cleanup, change the value if 2 is already taken
        'database' => env('REDIS_CACHE_DB', 2),
    ],
  ]
];
```

2. Update the .env file with the session driver and connection

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

If you have cached your config file, you might want to run `php artisan config:clear` and `php artisan config:cache` to revalidate the cache.

Usage
-----

[](#usage)

Once you configure, the session data will be automatically stored in Redis cache with automatic validation. The stored session data has following properties in the cache.

```
{
    "id": string, // session id
    "user_id": number|string, // user id
    "ip_address": null|string, // request ip address
    "user_agent": string, // request user agent
    "last_activty": number, // user's last request timestamp
    "payload": string, // serialized/encrypted session data,
}
```

If you want to get the underlying handler of the session (`RedisSessionEnhancerHandler` instance) in your application code, you can use the `Illuminate\Support\Facades\Session::getHandler()`. Along with the required [Session Interface for Custom Drivers by Laravel](https://laravel.com/docs/session#implementing-the-driver), this helper provides `readAll` and `destroyAll` methods to work with stored sessions. This package also includes a helper to work with sessions.

### SessionHelper

[](#sessionhelper)

To retrieve the stored session data from the cache, you should use the `Craftsys\LaravelRedisSessionEnhanced\SessionHelper` class. This helper class also handles the `SESSION_DRIVER=database` driver so that you can easily switch between database and redis drivers as per your application needs, without changing the application code for sessions.

The following helper functions are provided:

```
use Craftsys\LaravelRedisSessionEnhanced\SessionHelper;

// 1. Show the active/all sessions of a User
SessionHelper::getForUser($user_id) // get collection of all sessions of a user
SessionHelper::getForUser($user_id, true) // get collection of all active sessions of a user

// 2. Remove all/other sessions of a user
SessionHelper::deleteForUserExceptSession($user_id, [request()->session()->id]) // delete user's sessions except the current request
SessionHelper::deleteForUserExceptSession($user_id) // delete all sessions of a user

// 3. Remove All sessions (can be used in a command to flush out all sessions by DevOps)
SessionHelper::deleteAll() // delete all the sessions stored in database of every

// 4. Check if the application is configured with valid driver (database/redis).
SessionHelper::isUsingValidDriver() // return true if using SESSION_DRIVER=database or SESSION_DRIVER=redis-session
```

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity33

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 60% of commits — single point of failure

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 ~0 days

Total

6

Last Release

753d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6812992?v=4)[Sudhir Mitharwal](/maintainers/sudkumar)[@sudkumar](https://github.com/sudkumar)

---

Top Contributors

[![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/craftsys-laravel-redis-session-enhanced/health.svg)

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

###  Alternatives

[awssat/laravel-visits

Laravel Redis visits counter for Eloquent models

975163.6k2](/packages/awssat-laravel-visits)[namoshek/laravel-redis-sentinel

An extension of Laravels Redis driver which supports connecting to a Redis master through Redis Sentinel.

38679.0k](/packages/namoshek-laravel-redis-sentinel)[yangusik/laravel-balanced-queue

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

786.4k](/packages/yangusik-laravel-balanced-queue)[vetruvet/laravel-phpredis

Use phpredis as the redis connection in Laravel

43123.7k](/packages/vetruvet-laravel-phpredis)[alexmg86/laravel-sub-query

Laravel subquery

7538.4k](/packages/alexmg86-laravel-sub-query)

PHPackages © 2026

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