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)
432432 protected function pack ($ value , $ connection )
433433 {
434434 if ($ connection instanceof PhpRedisConnection) {
435+ if ($ this ->storePlainValue ($ value )) {
436+ return $ value ;
437+ }
438+
435439 if ($ connection ->serialized ()) {
436440 return $ connection ->pack ([$ value ])[0 ];
437441 }
@@ -444,6 +448,17 @@ protected function pack($value, $connection)
444448 return $ this ->serialize ($ value );
445449 }
446450
451+ /**
452+ * Determine if the given value should be stored as plain value or be serialized/compressed instead.
453+ *
454+ * @param mixed $value
455+ * @return bool
456+ */
457+ protected function storePlainValue ($ value ): bool
458+ {
459+ return is_numeric ($ value ) && ! in_array ($ value , [INF , -INF ]) && ! is_nan ($ value );
460+ }
461+
447462 /**
448463 * Serialize the value.
449464 *
@@ -452,7 +467,7 @@ protected function pack($value, $connection)
452467 */
453468 protected function serialize ($ value )
454469 {
455- return is_numeric ( $ value ) && ! in_array ( $ value , [ INF , - INF ]) && ! is_nan ($ value ) ? $ value : serialize ($ value );
470+ return $ this -> storePlainValue ($ value ) ? $ value : serialize ($ value );
456471 }
457472
458473 /**
Original file line number Diff line number Diff line change @@ -249,4 +249,20 @@ public function testPutManyCallsPutWhenClustered()
249249 'fizz ' => 'buz ' ,
250250 ], 10 );
251251 }
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+ }
252268}
You can’t perform that action at this time.
0 commit comments