33namespace Illuminate \Cache ;
44
55use Illuminate \Redis \Connections \PhpRedisConnection ;
6- use Redis ;
7- use UnexpectedValueException ;
86
97class PhpRedisLock extends RedisLock
108{
9+ /**
10+ * The phpredis factory implementation.
11+ *
12+ * @var \Illuminate\Redis\Connections\PhpredisConnection
13+ */
14+ protected $ redis ;
15+
1116 /**
1217 * Create a new phpredis lock instance.
1318 *
@@ -31,7 +36,7 @@ public function release()
3136 LuaScripts::releaseLock (),
3237 1 ,
3338 $ this ->name ,
34- $ this ->serializedAndCompressedOwner ( )
39+ ... $ this ->redis -> pack ([ $ this -> owner ] )
3540 );
3641 }
3742
@@ -41,72 +46,64 @@ public function release()
4146 * @return string
4247 *
4348 * @throws \UnexpectedValueException
49+ *
50+ * @deprecated Will be removed in a later laravel version. Use PhpRedisConnection::pack.
51+ * @see \Illuminate\Redis\Connections\PhpRedisConnection::pack
4452 */
4553 protected function serializedAndCompressedOwner (): string
4654 {
47- $ client = $ this ->redis ->client ();
48-
49- $ owner = $ client ->_serialize ($ this ->owner );
50-
51- // https://github.com/phpredis/phpredis/issues/1938
52- if ($ this ->compressed ()) {
53- if ($ this ->lzfCompressed ()) {
54- $ owner = \lzf_compress ($ owner );
55- } elseif ($ this ->zstdCompressed ()) {
56- $ owner = \zstd_compress ($ owner , $ client ->getOption (Redis::OPT_COMPRESSION_LEVEL ));
57- } elseif ($ this ->lz4Compressed ()) {
58- $ owner = \lz4_compress ($ owner , $ client ->getOption (Redis::OPT_COMPRESSION_LEVEL ));
59- } else {
60- throw new UnexpectedValueException (sprintf (
61- 'Unknown phpredis compression in use [%d]. Unable to release lock. ' ,
62- $ client ->getOption (Redis::OPT_COMPRESSION )
63- ));
64- }
65- }
66-
67- return $ owner ;
55+ return $ this ->redis ->pack ([$ this ->owner ])[0 ];
6856 }
6957
7058 /**
7159 * Determine if compression is enabled.
7260 *
7361 * @return bool
62+ *
63+ * @deprecated Will be removed in a later laravel version. Use PhpRedisConnection::compressed.
64+ * @see \Illuminate\Redis\Connections\PhpRedisConnection::compressed
7465 */
7566 protected function compressed (): bool
7667 {
77- return $ this ->redis ->client ()-> getOption (Redis:: OPT_COMPRESSION ) !== Redis:: COMPRESSION_NONE ;
68+ return $ this ->redis ->compressed () ;
7869 }
7970
8071 /**
8172 * Determine if LZF compression is enabled.
8273 *
8374 * @return bool
75+ *
76+ * @deprecated Will be removed in a later laravel version. Use PhpRedisConnection::lzfCompressed.
77+ * @see \Illuminate\Redis\Connections\PhpRedisConnection::lzfCompressed
8478 */
8579 protected function lzfCompressed (): bool
8680 {
87- return defined ('Redis::COMPRESSION_LZF ' ) &&
88- $ this ->redis ->client ()->getOption (Redis::OPT_COMPRESSION ) === Redis::COMPRESSION_LZF ;
81+ return $ this ->redis ->lzfCompressed ();
8982 }
9083
9184 /**
9285 * Determine if ZSTD compression is enabled.
9386 *
9487 * @return bool
88+ *
89+ * @deprecated Will be removed in a later laravel version. Use PhpRedisConnection::zstdCompressed.
90+ * @see \Illuminate\Redis\Connections\PhpRedisConnection::zstdCompressed
9591 */
9692 protected function zstdCompressed (): bool
9793 {
98- return defined ('Redis::COMPRESSION_ZSTD ' ) &&
99- $ this ->redis ->client ()->getOption (Redis::OPT_COMPRESSION ) === Redis::COMPRESSION_ZSTD ;
94+ return $ this ->redis ->zstdCompressed ();
10095 }
10196
10297 /**
10398 * Determine if LZ4 compression is enabled.
10499 *
105100 * @return bool
101+ *
102+ * @deprecated Will be removed in a later laravel version. Use PhpRedisConnection::lz4Compressed.
103+ * @see \Illuminate\Redis\Connections\PhpRedisConnection::lz4Compressed
106104 */
107105 protected function lz4Compressed (): bool
108106 {
109- return defined ('Redis::COMPRESSION_LZ4 ' ) &&
110- $ this ->redis ->client ()->getOption (Redis::OPT_COMPRESSION ) === Redis::COMPRESSION_LZ4 ;
107+ return $ this ->redis ->lz4Compressed ();
111108 }
112109}
0 commit comments