File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -432,6 +432,10 @@ public function setPrefix($prefix)
432
432
protected function pack ($ value , $ connection )
433
433
{
434
434
if ($ connection instanceof PhpRedisConnection) {
435
+ if ($ this ->shouldBeStoredWithoutSerialization ($ value )) {
436
+ return $ value ;
437
+ }
438
+
435
439
if ($ connection ->serialized ()) {
436
440
return $ connection ->pack ([$ value ])[0 ];
437
441
}
@@ -452,7 +456,18 @@ protected function pack($value, $connection)
452
456
*/
453
457
protected function serialize ($ value )
454
458
{
455
- return is_numeric ($ value ) && ! in_array ($ value , [INF , -INF ]) && ! is_nan ($ value ) ? $ value : serialize ($ value );
459
+ return $ this ->shouldBeStoredWithoutSerialization ($ value ) ? $ value : serialize ($ value );
460
+ }
461
+
462
+ /**
463
+ * Determine if the given value should be stored as plain value.
464
+ *
465
+ * @param mixed $value
466
+ * @return bool
467
+ */
468
+ protected function shouldBeStoredWithoutSerialization ($ value ): bool
469
+ {
470
+ return is_numeric ($ value ) && ! in_array ($ value , [INF , -INF ]) && ! is_nan ($ value );
456
471
}
457
472
458
473
/**
Original file line number Diff line number Diff line change @@ -249,4 +249,20 @@ public function testPutManyCallsPutWhenClustered()
249
249
'fizz ' => 'buz ' ,
250
250
], 10 );
251
251
}
252
+
253
+ public function testIncrementWithSerializationEnabled ()
254
+ {
255
+ /** @var \Illuminate\Cache\RedisStore $store */
256
+ $ store = Cache::store ('redis ' );
257
+ /** @var \Redis $client */
258
+ $ client = $ store ->connection ()->client ();
259
+ $ client ->setOption (\Redis::OPT_SERIALIZER , \Redis::SERIALIZER_PHP );
260
+
261
+ $ store ->flush ();
262
+ $ store ->add ('foo ' , 1 , 10 );
263
+ $ this ->assertEquals (1 , $ store ->get ('foo ' ));
264
+
265
+ $ store ->increment ('foo ' );
266
+ $ this ->assertEquals (2 , $ store ->get ('foo ' ));
267
+ }
252
268
}
You can’t perform that action at this time.
0 commit comments