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 singleSET key value EX seconds NX.putMany()that returns the real result, using one atomicMSETEXwhen the server has it.many()andputMany()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 onSET ... IFEQ. It throwsBadMethodCallExceptionwhen the server lacksSET IFEQ. A missing key never matches.- Lock release with
DELEX key IFEQ ownerwhen available, else the Lua script.Resp3Lock::refresh($seconds = null): bool(takes an int or null; the parameter is untyped for compatibility with Laravel'sRedisLock::refresh()) extends a held lock and returns false when the lock expired or belongs to another owner. - Cache tags through
Resp3TaggedCacheandResp3TagSet, 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.