PHPackages                             officialaudite/nullredis - 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. officialaudite/nullredis

ActiveLibrary[Caching](/categories/caching)

officialaudite/nullredis
========================

A tiny file-backed Redis-like shim for PHP (KV, sets, sorted sets)

v0.1.2(8mo ago)03MITPHPPHP &gt;=8.0CI passing

Since Oct 15Pushed 8mo agoCompare

[ Source](https://github.com/OfficialAudite/nullredis)[ Packagist](https://packagist.org/packages/officialaudite/nullredis)[ RSS](/packages/officialaudite-nullredis/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (1)Versions (4)Used By (0)

NullRedis (file-backed Redis-like shim)
=======================================

[](#nullredis-file-backed-redis-like-shim)

NullRedis is a tiny, dependency-free, file-backed shim that mimics a small subset of Redis commands:

- KV: get, set, setex, exists, expire
- Sets: sAdd, sMembers
- Sorted sets: zadd, zcard, zremrangebyscore
- Admin: flushAll

It’s useful as a drop-in fallback when Redis is unavailable, or as a lightweight cache/rate-limiter without running a server.

Install
-------

[](#install)

### Via Composer (recommended)

[](#via-composer-recommended)

```
composer require officialaudite/nullredis
```

```
require __DIR__ . '/vendor/autoload.php';
use NullRedis\NullRedis;
$cache = new NullRedis(__DIR__.'/cache'); // optional custom cache dir
```

### Manual (copy file)

[](#manual-copy-file)

Copy `src/NullRedis.php` into your project and include it.

```
require_once __DIR__.'/src/NullRedis.php';
$cache = new \NullRedis\NullRedis(__DIR__.'/cache');
```

Usage
-----

[](#usage)

### Basic KV

[](#basic-kv)

```
use NullRedis\NullRedis;
$cache = new NullRedis(__DIR__.'/cache');
$cache->set('greeting', 'hello');
echo $cache->get('greeting'); // hello
$cache->setex('temp', 2, 'short');
sleep(3);
var_dump($cache->get('temp')); // NULL after expiry
```

### Sets

[](#sets)

```
$cache->sAdd('bad_agents', 'curl/7.88');
$cache->sAdd('bad_agents', 'bot');
print_r($cache->sMembers('bad_agents'));
```

### Sorted sets (rate limiting)

[](#sorted-sets-rate-limiting)

```
$user = '127.0.0.1';
$key = 'rate:'.$user;
$now = time(); $window = 2; $max = 5;
$cache->zremrangebyscore($key, 0, $now - $window);
$cache->zadd($key, $now, (string)$now);
if ($cache->zcard($key) > $max) { http_response_code(429); exit('Too Many Requests'); }
$cache->expire($key, $window+1);
```

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

[](#development)

### Run tests

[](#run-tests)

```
composer install
composer test
```

Roadmap
-------

[](#roadmap)

- KV basics: `get`, `set`, `setex`, `exists`, `expire`
- Admin: `flushAll`
- Sorted sets (MVP): `zadd`, `zcard`, `zremrangebyscore`
- Sets (MVP): `sAdd`/`sMembers`
- KV more: `del`, `mset`, `mget`, `incr`, `decr`, `incrBy`, `decrBy`, `pexpire`, `ttl`, `pttl`, `persist`, `type`, `keys`
- Sets more: `sismember`, `srem`, `scard`
- Sorted sets more: `zrange`, `zrevrange`, `zrangebyscore`, `zrem`, `zscore`, `zcount`
- Lists: `lpush`, `rpush`, `lpop`, `rpop`, `llen`, `lrange`
- Hashes: `hset`, `hget`, `hmset`, `hmget`, `hgetall`, `hdel`, `hexists`, `hincrby`
- DB/admin: `select` (db directories), `dbsize`, `flushdb`
- Docs: compatibility matrix vs phpredis
- Optional: PHPCS and coding-style CI

Non-goals (for now): Pub/Sub, Streams, Lua (`eval`), blocking ops (`blpop`, `brpop`), Cluster.

Notes
-----

[](#notes)

- Per-key JSON files under `cache/`, sharded by the first 2 chars of SHA1(key)
- Lazy TTL expiration on read
- Single-host, low-contention environments recommended

License
-------

[](#license)

MIT — see [LICENSE](./LICENSE)

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance59

Moderate activity, may be stable

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity33

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.

###  Release Activity

Cadence

Every ~0 days

Total

3

Last Release

260d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/10171579?v=4)[Audite](/maintainers/OfficialAudite)[@OfficialAudite](https://github.com/OfficialAudite)

---

Top Contributors

[![OfficialAudite](https://avatars.githubusercontent.com/u/10171579?v=4)](https://github.com/OfficialAudite "OfficialAudite (13 commits)")

---

Tags

redisredis-cacheshimshimrediscacherate limitfile cache

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/officialaudite-nullredis/health.svg)

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

###  Alternatives

[tedivm/stash

The place to keep your cache.

9614.9M128](/packages/tedivm-stash)[nikolaposa/rate-limit

General purpose rate limiter implementation.

2741.7M3](/packages/nikolaposa-rate-limit)[cache/redis-adapter

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

584.1M27](/packages/cache-redis-adapter)[kdyby/redis

Redis storage for Nette Framework

501.7M2](/packages/kdyby-redis)[matomo/cache

PHP caching library based on Doctrine cache

381.3M21](/packages/matomo-cache)[cache/predis-adapter

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

242.6M13](/packages/cache-predis-adapter)

PHPackages © 2026

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