Search by

neatous / redis

neatous

Minimalist Redis integration for Nette cache and sessions using phpredis

Package info

github.com/neatous/redis

pkg:composer/neatous/redis

Statistics

Installs: 1 462

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.10.1 2026-11-12 16:05 UTC

This package is auto-updated.

Last update: 2026-11-12 16:08:08 UTC


README

Logo
neatous/redis

Redis cache storage and sessions for Nette, using phpredis.

Requirements

  • PHP 8.4+, ext-redis 6.0+ (igbinary is used when phpredis is built with its support, the PHP serializer otherwise)
  • nette/caching 3.3.1+ or 4.x, nette/di 3.2.3+
  • Redis 4+, standalone (no Cluster), Lua scripting allowed

Upgrading from 0.9? See UPGRADE.md.

Installation

composer require neatous/redis
extensions:
    redis: Netous\Redis\DI\RedisExtension

redis:
    cache: true
    sessions: true

Options

Option Default Description
host 127.0.0.1 Redis host
port 6379 Redis port
password null Redis password
database 0 Database index
cacheDatabase null Database for the cache (default database)
sessionDatabase null Database for sessions (default database)
timeout 1.5 Connection timeout in seconds
persistent false Persistent connections
prefix app: Key prefix — unique per application, not nested in another application's prefix
cache false Use Redis as the Nette cache storage
journal true Enable Cache::Tags and Cache::Priority
defaultTtl 3600 Lifetime of items without Cache::Expire; null = until invalidated
sessions false Store PHP sessions in Redis
debug false Tracy panel (requires tracy/tracy)

Cache

All Nette\Caching\Cache instances use Redis. All dependencies are supported (Expire, Sliding, Tags, Priority, Files, Constants, Callbacks, Items; Sliding needs Expire).

Run the garbage collector regularly, e.g. hourly from cron:

$container->getByType(Nette\Caching\Storage::class)->clean([]);

Without the extension:

$redis = (new Netous\Redis\Client\RedisFactory())->create(new Netous\Redis\Client\RedisConfig(prefix: 'myapp:'));
$storage = new Netous\Redis\Cache\RedisStorage(
    $redis,
    new Netous\Redis\Cache\RedisKeyBuilder('myapp:'),
    new Netous\Redis\Cache\RedisJournal($redis, 'myapp:'), // same connection
);

Notes

  • Cache::All deletes only this library's keys ({prefix}cache…, {prefix}journal:); sessions and other data stay.
  • With the journal, set maxmemory-policy to volatile-* (recommended) or noeviction (a full Redis then makes cache writes throw); allkeys-* may evict journal keys and break tag invalidation.
  • Anyone who can write to your Redis can run code in your application (cached data is unserialized, Cache::Callbacks are executed). Protect Redis with a password/ACL and keep it off untrusted networks.
  • Sessions: the Redis password is part of session.save_path, which phpinfo() and Tracy's error page show. Restrict access to Tracy logs or set Tracy\Debugger::getBlueScreen()->showEnvironment = false.
  • A custom connection must use the PHP or igbinary serializer and no Redis::OPT_PREFIX; compression is supported.
  • The serializer depends on the phpredis build. Cache items written with the other serializer are read as misses, so all servers sharing one Redis and prefix should use the same build. Values stored directly through the Redis service are not converted.

Testing

composer install
vendor/bin/phpunit
REDIS_TEST_SERIALIZER=php vendor/bin/phpunit

Requires Redis on 127.0.0.1:6379. The tests flush databases 14 and 15.

License

MIT