Repository navigation
Conversation
|
This is a good fix that looks correct but I don't think we can merge it as default behavior before a major version bump. Currently when The change would cause PhpRedis to write partial transactions. Clanker created example below: // develop
$rc->multi();
try {
$rc->mSet([
'{a}:critical' => 'updated',
'{b}:critical' => 'updated',
'{c}:cache' => $bad,
]);
} catch (Exception $e) { /* Recoverable cache serialization failure. */ }
$rc->exec();
// Both critical keys are updated; the cache value is invalid.
// This PR
$rc->multi();
try {
$rc->mSet([
'{a}:critical' => 'updated',
'{b}:critical' => 'updated',
'{c}:cache' => $bad,
]);
} catch (Exception $e) { /* Recoverable cache serialization failure. */ }
$rc->exec();
// Only {a}:critical is updated; {b}:critical silently remains unchanged.We could gate the behavior with a |
|
@michael-grunder Added |
Add
Redis::OPT_STRICT_SERIALIZATION, a boolean option supported by Redis and RedisCluster. It defaults tofalseso 6.x callers retain existing behavior, including completion of cross-slot batches after a serialization exception.getOption()reports the current setting, and disabling the option restores legacy behavior.Opt in with:
With strict serialization enabled, a serialization exception prevents the failed command from being sent or queued. Existing values and TTLs survive, the original exception propagates, and failed commands add no reply callbacks.
RedisCluster
mSet()andmSetNX()prepare an owned snapshot of all packed values before sending any batch. Each serializer runs once per value. If the first, middle, or last value throws, none of that call's batches is sent or queued. This avoids the partial batching described in the review. Commands queued by earlier calls remain in the transaction and can still be executed, as can subsequent valid commands.The extra buffering applies only when callers enable strict serialization. Existing handling of server and connection errors is preserved; this does not introduce atomic transactions across cluster slots.
The option gates serializer short-circuiting, partial-buffer rejection, compression suppression, and command dispatch together. Stubs, generated arginfo, and documentation describe the new setting and its default.
Validation on PHP 8.5.11 and Redis 8.10.2:
mSet()/mSetNX()failures at each argument position, earlier and later queued commands, and successful preparation without duplicate serialization.git diff --checkpass.