88
99class PhpRedisLock extends RedisLock
1010{
11+ /**
12+ * Create a new phpredis lock instance.
13+ *
14+ * @param \Illuminate\Redis\Connections\PhpRedisConnection $redis
15+ * @param string $name
16+ * @param int $seconds
17+ * @param string|null $owner
18+ * @return void
19+ */
1120 public function __construct (PhpRedisConnection $ redis , string $ name , int $ seconds , ?string $ owner = null )
1221 {
1322 parent ::__construct ($ redis , $ name , $ seconds , $ owner );
@@ -26,26 +35,18 @@ public function release()
2635 );
2736 }
2837
38+ /**
39+ * Get the owner key, serialized and compressed.
40+ *
41+ * @return string
42+ */
2943 protected function serializedAndCompressedOwner (): string
3044 {
3145 $ client = $ this ->redis ->client ();
3246
33- /* If a serialization mode such as "php" or "igbinary" and/or a
34- * compression mode such as "lzf" or "zstd" is enabled, the owner
35- * must be serialized and/or compressed by us, because phpredis does
36- * not do this for the eval command.
37- *
38- * Name must not be modified!
39- */
4047 $ owner = $ client ->_serialize ($ this ->owner );
4148
42- /* Once the phpredis extension exposes a compress function like the
43- * above `_serialize()` function, we should switch to it to guarantee
44- * consistency in the way the extension serializes and compresses to
45- * avoid the need to check each compression option ourselves.
46- *
47- * @see https://github.com/phpredis/phpredis/issues/1938
48- */
49+ // https://github.com/phpredis/phpredis/issues/1938
4950 if ($ this ->compressed ()) {
5051 if ($ this ->lzfCompressed ()) {
5152 $ owner = \lzf_compress ($ owner );
@@ -55,7 +56,7 @@ protected function serializedAndCompressedOwner(): string
5556 $ owner = \lz4_compress ($ owner , $ client ->getOption (Redis::OPT_COMPRESSION_LEVEL ));
5657 } else {
5758 throw new UnexpectedValueException (sprintf (
58- 'Unknown phpredis compression in use (%d) . Unable to release lock. ' ,
59+ 'Unknown phpredis compression in use [%d] . Unable to release lock. ' ,
5960 $ client ->getOption (Redis::OPT_COMPRESSION )
6061 ));
6162 }
@@ -64,26 +65,46 @@ protected function serializedAndCompressedOwner(): string
6465 return $ owner ;
6566 }
6667
68+ /**
69+ * Determine if compression is enabled.
70+ *
71+ * @return bool
72+ */
6773 protected function compressed (): bool
6874 {
6975 return $ this ->redis ->client ()->getOption (Redis::OPT_COMPRESSION ) !== Redis::COMPRESSION_NONE ;
7076 }
7177
78+ /**
79+ * Determine if LZF compression is enabled.
80+ *
81+ * @return bool
82+ */
7283 protected function lzfCompressed (): bool
7384 {
7485 return defined ('Redis::COMPRESSION_LZF ' ) &&
75- $ this ->redis ->client ()->getOption (Redis::OPT_COMPRESSION ) === Redis::COMPRESSION_LZF ;
86+ $ this ->redis ->client ()->getOption (Redis::OPT_COMPRESSION ) === Redis::COMPRESSION_LZF ;
7687 }
7788
89+ /**
90+ * Determine if ZSTD compression is enabled.
91+ *
92+ * @return bool
93+ */
7894 protected function zstdCompressed (): bool
7995 {
8096 return defined ('Redis::COMPRESSION_ZSTD ' ) &&
81- $ this ->redis ->client ()->getOption (Redis::OPT_COMPRESSION ) === Redis::COMPRESSION_ZSTD ;
97+ $ this ->redis ->client ()->getOption (Redis::OPT_COMPRESSION ) === Redis::COMPRESSION_ZSTD ;
8298 }
8399
100+ /**
101+ * Determine if LZ4 compression is enabled.
102+ *
103+ * @return bool
104+ */
84105 protected function lz4Compressed (): bool
85106 {
86107 return defined ('Redis::COMPRESSION_LZ4 ' ) &&
87- $ this ->redis ->client ()->getOption (Redis::OPT_COMPRESSION ) === Redis::COMPRESSION_LZ4 ;
108+ $ this ->redis ->client ()->getOption (Redis::OPT_COMPRESSION ) === Redis::COMPRESSION_LZ4 ;
88109 }
89110}
0 commit comments