PHPackages                             kozlovsv/yii2-jwt-storage-redis - 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. [Database &amp; ORM](/categories/database)
4. /
5. kozlovsv/yii2-jwt-storage-redis

ActiveYii2-extension[Database &amp; ORM](/categories/database)

kozlovsv/yii2-jwt-storage-redis
===============================

Redis storage for yii2-jwt-auth component

017PHP

Since Apr 14Pushed 3y ago1 watchersCompare

[ Source](https://github.com/kozlovsv/yii2-jwt-storage-redis)[ Packagist](https://packagist.org/packages/kozlovsv/yii2-jwt-storage-redis)[ RSS](/packages/kozlovsv-yii2-jwt-storage-redis/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

yii2-jwt-storage-redis
======================

[](#yii2-jwt-storage-redis)

Redis storage component for kozlovsv/yii2-jwt-auth.

Component provides token storage in redis cache

This component should be used if your application uses Redis cache, and you need functionality that allows you to delete all saved access and refresh tokens for a specific user.

The standard application cache component, which is used in the TokenStorageCache class, converts all keys to an MD5 hash before writing or reading, so there is no way to get all the keys for a specific user. All keys in the cache look like: 402849137963e1945d01315c4f61662f

The TokenStorageRedis component executes the Redis commands directly, and does not use the commands of the standard cache class. Due to this, the keys are not formatted in MD5, but are stored in the cache in their original form.

Fotrat of the key api:token:user\_id:token\_id.

Example: api:token:1425:9f3898ca702c9c9f4991c63dc7eb0e13.

This formatting allows you to get all the keys for a specific user that are stored in the cache by the search mask. For example, api:token:1425:\* will retrieve all stored tokens for user ID 1425.

This makes it possible to remove all of that user's keys from the store.

For example, when you need to log out of all authorized devices for a specific user.

The default key storage component does not allow you to perform this functionality.

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

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist kozlovsv/yii2-jwt-storage-redis "@dev"
```

or add

```
"kozlovsv/yii2-jwt-storage-redis": "@dev"

```

to the `require` section of your `composer.json` file.

Dependencies
------------

[](#dependencies)

- PHP 7.2+
- [kozlovsv/yii2-jwt-auth](https://github.com/kozlovsv/yii2-jwt-auth)
- [yiisoft/yii2-redis 2.0.6+](https://github.com/yiisoft/yii2-redis)

Basic usage
-----------

[](#basic-usage)

Edit `jwt` component to your configuration file,

```
'components' => [
    'jwt' => [
        'class' => \kozlovsv\jwtauth\Jwt::class,
        ...
        'tokenStorage' => \kozlovsv\jwtredis\TokenStorageRedis::class, //Set Redis storage class
    ],
],
```

For examle add method `afterSave()` to model `app\models\User`

```
public function afterSave($insert, $changedAttributes)
    // Purge the user tokens when the password is changed
    if (array_key_exists('password_hash', $changedAttributes)) {
        /** @var Jwt $jwtServ */
        $jwtServ = Yii::$app->get('jwt', false);
        $jwtServ?->tokenStorage->deleteAllForUser($this->id);
    }

    parent::afterSave($insert, $changedAttributes);
}
```

###  Health Score

14

—

LowBetter than 2% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity22

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/714ea1f58d3a355f2bc3062f38198e2e09cc72bde793f03d6c4f8ca3decbfb32?d=identicon)[kozlovsv](/maintainers/kozlovsv)

---

Top Contributors

[![kozlovsv](https://avatars.githubusercontent.com/u/10562997?v=4)](https://github.com/kozlovsv "kozlovsv (8 commits)")

### Embed Badge

![Health badge](/badges/kozlovsv-yii2-jwt-storage-redis/health.svg)

```
[![Health](https://phpackages.com/badges/kozlovsv-yii2-jwt-storage-redis/health.svg)](https://phpackages.com/packages/kozlovsv-yii2-jwt-storage-redis)
```

###  Alternatives

[doctrine/orm

Object-Relational-Mapper for PHP

10.2k285.3M6.2k](/packages/doctrine-orm)[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k115.1M102](/packages/jdorn-sql-formatter)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[mongodb/mongodb

MongoDB driver library

1.6k64.0M546](/packages/mongodb-mongodb)[ramsey/uuid-doctrine

Use ramsey/uuid as a Doctrine field type.

90340.3M211](/packages/ramsey-uuid-doctrine)[reliese/laravel

Reliese Components for Laravel Framework code generation.

1.7k3.4M16](/packages/reliese-laravel)

PHPackages © 2026

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