PHPackages                             kuick/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. [Caching](/categories/caching)
4. /
5. kuick/redis

ActiveLibrary[Caching](/categories/caching)

kuick/redis
===========

Kuick Redis provides an useful client factory and the Mock for Redis

v2.0.1(1mo ago)16.8k1MITPHPPHP &gt;=8.2.0CI passing

Since Dec 27Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/milejko/kuick-redis)[ Packagist](https://packagist.org/packages/kuick/redis)[ RSS](/packages/kuick-redis/feed)WikiDiscussions main Synced today

READMEChangelog (9)Dependencies (4)Versions (11)Used By (1)

Kuick Redis
===========

[](#kuick-redis)

[![Latest Version](https://camo.githubusercontent.com/7c4d82a898dd9319c58f680f2e58b071fdda73035c40552af4f559027b13730a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f6d696c656a6b6f2f6b7569636b2d72656469732e7376673f63616368655365636f6e64733d33363030)](https://github.com/milejko/kuick-redis/releases)[![PHP](https://camo.githubusercontent.com/ac99b489f44f6ce512b6a4d6919492f00b43862f88161b80e35da61f35064ca0/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e32253230253743253230382e33253230253743253230382e34253230253743253230382e352d626c75653f6c6f676f3d7068702663616368655365636f6e64733d33363030)](https://www.php.net)[![Total Downloads](https://camo.githubusercontent.com/ecee9979afa39bd2c8f078f7b92747bbd791b4806ea591cdf04170b0395e8d52/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6b7569636b2f72656469732e7376673f63616368655365636f6e64733d33363030)](https://packagist.org/packages/kuick/redis)[![GitHub Actions CI](https://github.com/milejko/kuick-redis/actions/workflows/ci.yml/badge.svg)](https://github.com/milejko/kuick-redis/actions/workflows/ci.yml)[![codecov](https://camo.githubusercontent.com/1ac976538cb61a2f44947b4e4c21e0e86e1c07517b3f7b8599b45f8aacc1066a/68747470733a2f2f636f6465636f762e696f2f67682f6d696c656a6b6f2f6b7569636b2d72656469732f67726170682f62616467652e7376673f746f6b656e3d38305145424448475048)](https://codecov.io/gh/milejko/kuick-redis)[![Software License](https://camo.githubusercontent.com/e2f0982d826e942af97a6e879597c2301c2a8a97567d69e47148db858bbc5de3/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f63616368655365636f6e64733d3134343030)](LICENSE)

A minimal, DSN-configured Redis client for PHP 8.2+ with a built-in in-memory mock — no extra dependencies beyond the `php-redis` extension and `nyholm/dsn`.

---

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

[](#table-of-contents)

- [Requirements](#requirements)
- [Installation](#installation)
- [Quick Start](#quick-start)
- [DSN Format](#dsn-format)
- [API Reference](#api-reference)
- [Testing Without Redis — RedisClientMock](#testing-without-redis--redisclientmock)
- [Architecture](#architecture)
- [Development](#development)
    - [Running the Full CI Suite (Docker)](#running-the-full-ci-suite-docker)
    - [Running Tests Locally](#running-tests-locally)
    - [Code Quality](#code-quality)
- [Contributing](#contributing)

---

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

[](#requirements)

RequirementVersionPHP≥ 8.2PHP extension`php-redis`Composer dependency`nyholm/dsn` ^2.0---

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

[](#installation)

```
composer require kuick/redis
```

---

Quick Start
-----------

[](#quick-start)

```
use Kuick\Redis\RedisClient;

// Connect to a local Redis instance
$redis = new RedisClient('redis://localhost');

// Store a value with a 60-second TTL
$redis->set('greeting', 'hello world', 60);

// Retrieve it
echo $redis->get('greeting'); // hello world

// Remove the TTL — key persists indefinitely
$redis->persist('greeting');

// Delete the key
$redis->del('greeting');
```

---

DSN Format
----------

[](#dsn-format)

```
redis://[user:pass@]host[:port][/db][?param=value&...]

```

ComponentDescriptionDefault`host`Redis server hostname or IP*(required)*`port`Redis server port`6379``/db`Database index (e.g. `/1` → `SELECT 1`)*(none)*`?user=`ACL username for authentication*(none)*`?pass=`Password for authentication*(none)*`?readTimeout=`Read timeout in seconds (float)`2.5``?connectTimeout=`Connection timeout in seconds (float)`2.5``?retryInterval=`Retry interval in milliseconds`100``?persistent=`Use a persistent connection (`1`/`0`)`1`**Examples:**

```
redis://localhost
redis://localhost:6380/2
redis://localhost?pass=secret&readTimeout=5
redis://localhost?user=myuser&pass=mypass
redis://redis.example.com:6379/0?persistent=0&connectTimeout=1

```

---

API Reference
-------------

[](#api-reference)

All three classes share the same `RedisClientInterface` contract:

```
interface RedisClientInterface
{
    // Store a value. $ttl = null means no expiry.
    public function set(string $key, mixed $value = null, ?int $ttl = null): bool;

    // Remove TTL from a key so it persists indefinitely.
    public function persist(string $key): bool;

    // Retrieve a value; returns false if the key does not exist or has expired.
    public function get(string $key): mixed;

    // Check whether a key exists (and has not expired).
    public function exists(string $key): bool;

    // Delete a single key.
    public function del(string $key): bool;

    // Delete all keys in the current database.
    public function flushDb(): bool;

    // Delete all keys in all databases.
    public function flushAll(): bool;

    // Return keys matching a glob pattern (default: all keys).
    public function keys(string $pattern = '*'): array;

    // Incrementally iterate keys (cursor-based). $iterator is updated each call;
    // returns false when iteration is complete.
    public function scan(?int &$iterator = null, string $pattern = '*', int $count = 1000, ?string $type = null): array|false;

    // Return server info as an associative array.
    public function info(): array;
}
```

### `scan` usage example

[](#scan-usage-example)

```
$iterator = null;
do {
    $keys = $redis->scan($iterator, 'session:*', 100);
    foreach ($keys ?: [] as $key) {
        // process $key
    }
} while ($iterator !== 0 && $iterator !== null);
```

---

Testing Without Redis — RedisClientMock
---------------------------------------

[](#testing-without-redis--redisclientmock)

`RedisClientMock` is a pure PHP, in-memory implementation of `RedisClientInterface`. It simulates TTL expiry using wall-clock comparisons — no timers, no Redis server required.

Use it anywhere you'd use the real client:

```
use Kuick\Redis\RedisClientMock;

$redis = new RedisClientMock();
$redis->set('token', 'abc123', 10); // expires in 10 seconds
var_dump($redis->exists('token')); // bool(true)

$redis->persist('token');          // remove expiry
$redis->del('token');
```

Type-hint against `RedisClientInterface` in your own services so you can swap implementations freely:

```
use Kuick\Redis\RedisClientInterface;

class SessionStore
{
    public function __construct(private RedisClientInterface $redis) {}

    public function save(string $id, array $data, int $ttl = 3600): void
    {
        $this->redis->set($id, serialize($data), $ttl);
    }
}

// Production
$store = new SessionStore(new RedisClient('redis://localhost'));

// Tests — no Redis needed
$store = new SessionStore(new RedisClientMock());
```

---

Architecture
------------

[](#architecture)

```
src/
├── RedisClientInterface.php   # Shared contract (get, set, del, exists, persist,
│                              #   keys, scan, flushDb, flushAll, info)
├── RedisClient.php            # Production: wraps php-redis, DSN-configured
└── RedisClientMock.php        # Test double: pure in-memory, simulates TTL

tests/
├── RedisClientTest.php        # Integration tests (requires test-redis:6379)
└── RedisClientMockTest.php    # Unit tests (no external deps)

```

`RedisClient` delegates directly to the native `Redis` extension object. The DSN is parsed via `nyholm/dsn` at construction time — options like `readTimeout`, `connectTimeout`, `retryInterval`, and `persistent` are passed through the `Redis` constructor options array (PHP `redis` &gt;= 6.0 style).

---

Development
-----------

[](#development)

### Running the Full CI Suite (Docker)

[](#running-the-full-ci-suite-docker)

The `Makefile` target builds a PHP image, starts a Redis 8 sidecar, runs all checks inside the container, then tears everything down:

```
make test
```

This is the canonical way to reproduce the CI environment locally. PHP version can be overridden:

```
PHP_VERSION=8.3 make test
```

### Running Tests Locally

[](#running-tests-locally)

Integration tests (`RedisClientTest`) require a reachable Redis at `test-redis:6379` (add an `/etc/hosts` alias or use Docker). Mock tests have no external dependencies:

```
# Unit tests only (no Redis needed)
XDEBUG_MODE=coverage vendor/bin/phpunit --filter RedisClientMockTest

# Single test method
XDEBUG_MODE=coverage vendor/bin/phpunit --filter testMethodName

# All tests (Redis required at test-redis:6379)
composer test:phpunit
```

### Code Quality

[](#code-quality)

CommandToolDescription`composer fix:phpcbf`PHP\_CodeSnifferAuto-fix PSR-12 style issues`composer test:phpcs`PHP\_CodeSnifferCheck PSR-12 compliance`composer test:phpstan`PHPStan (level 5)Static analysis`composer test:phpmd`PHPMDMess detection`composer test:phpunit`PHPUnitTests with coverage`composer test:all`—Run all of the aboveRun `composer fix:phpcbf` before committing — the CI pipeline enforces PSR-12.

> **Note:** Every test class must declare `#[CoversClass(ClassName::class)]` — coverage metadata is required by `phpunit.xml`.

---

Contributing
------------

[](#contributing)

1. Fork the repository and create a feature branch.
2. Run `composer fix:phpcbf` to normalise formatting.
3. Add or update tests; ensure `composer test:all` passes.
4. Open a pull request — CI will run automatically.

---

MIT © [Mariusz Miłejko](https://github.com/milejko)

###  Health Score

48

—

FairBetter than 93% of packages

Maintenance90

Actively maintained with recent releases

Popularity24

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 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.

###  Release Activity

Cadence

Every ~55 days

Recently: every ~123 days

Total

10

Last Release

53d ago

Major Versions

v1.0.7 → v2.0.02025-09-15

### Community

Maintainers

![](https://www.gravatar.com/avatar/f986340afe26a382bdec4d838f514714b6f5bc7222baf73972001a66b9b6dab0?d=identicon)[emisarius](/maintainers/emisarius)

---

Top Contributors

[![milejko](https://avatars.githubusercontent.com/u/14335568?v=4)](https://github.com/milejko "milejko (24 commits)")

---

Tags

redisKuickredis mock

### Embed Badge

![Health badge](/badges/kuick-redis/health.svg)

```
[![Health](https://phpackages.com/badges/kuick-redis/health.svg)](https://phpackages.com/packages/kuick-redis)
```

###  Alternatives

[predis/predis

A flexible and feature-complete Redis/Valkey client for PHP.

7.8k325.4M2.8k](/packages/predis-predis)[snc/redis-bundle

A Redis bundle for Symfony

1.0k40.9M75](/packages/snc-redis-bundle)[clue/redis-protocol

A streaming Redis protocol (RESP) parser and serializer written in pure PHP.

5216.6M14](/packages/clue-redis-protocol)[cache/redis-adapter

A PSR-6 cache implementation using Redis (PhpRedis). This implementation supports tags

584.1M26](/packages/cache-redis-adapter)[enqueue/redis

Message Queue Redis Transport

445.7M32](/packages/enqueue-redis)[kdyby/redis

Redis storage for Nette Framework

501.7M2](/packages/kdyby-redis)

PHPackages © 2026

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