~/docs
Resonate
Resonate
0.x 0.9.0, current
Laravel RESP3 Cache
Toggle sidebar
Laravel RESP3 Cache
webpatser/laravel-resp3-cache 0.9.0

Laravel RESP3 Cache 0.x

Quick Start

Use the resp3 client with the stock redis driver, or register the resp3 cache store.

Option 1: the redis driver

After installing and setting redis.client to resp3, your existing Cache::* calls work unchanged through the standard redis cache driver.

Option 2: the resp3 cache driver

Register a store with 'driver' => 'resp3' in config/cache.php. It accepts the same options as the redis driver.

'stores' => [
'resp3' => [
'driver' => 'resp3',
'connection' => 'cache', // key in config/database.php redis
'lock_connection' => 'default',
'prefix' => env('CACHE_PREFIX', 'app:'),
],
],

The resp3 driver adds, over the stock redis driver:

  • add() as a single SET key value EX seconds NX.
  • putMany() that returns the real result, using one atomic MSETEX when the server has it.
  • many() and putMany() on a cluster without hash tags: keys are grouped per slot.
  • putIfEquals(string $key, mixed $expected, mixed $value, ?int $seconds = null): bool, a compare-and-set built on SET ... IFEQ. It throws BadMethodCallException when the server lacks SET IFEQ. A missing key never matches.
  • Lock release with DELEX key IFEQ owner when available, else the Lua script. Resp3Lock::refresh($seconds = null): bool (takes an int or null; the parameter is untyped for compatibility with Laravel's RedisLock::refresh()) extends a held lock and returns false when the lock expired or belongs to another owner.
  • Cache tags through Resp3TaggedCache and Resp3TagSet, with the same key format as Laravel's Redis tags.

Errors

Redis error replies reaching a Laravel connection are thrown as Resp3\Laravel\Client\ServerException. It extends RuntimeException, has a readonly prefix (ERR, WRONGTYPE, NOAUTH and so on) and getRedisException() for the original Resp3\RedisException.

Pub/Sub

Redis::subscribe() and Redis::psubscribe() work on single-node and sentinel connections. See Examples.