@@ -41,8 +41,7 @@ protected function setUp()
41
41
$ uri = parse_url ($ redisUri );
42
42
43
43
// original Redis::set and Redis::eval calls will reopen the connection
44
- $ connection = new class extends Redis
45
- {
44
+ $ connection = new class extends Redis {
46
45
private $ is_closed = false ;
47
46
48
47
public function close ()
@@ -100,6 +99,9 @@ private function closeMinorityConnections()
100
99
}
101
100
102
101
$ numberToClose = ceil (count ($ this ->connections ) / 2 ) - 1 ;
102
+ if (0 >= $ numberToClose ) {
103
+ return ;
104
+ }
103
105
104
106
foreach ((array ) array_rand ($ this ->connections , $ numberToClose ) as $ keyToClose ) {
105
107
$ this ->connections [$ keyToClose ]->close ();
@@ -132,27 +134,36 @@ public function testEvalScriptFails()
132
134
}
133
135
134
136
/**
135
- * @param $serialization
136
- * @dataProvider dpSerializationModes
137
+ * @dataProvider serializationAndCompressionModes
138
+ *
139
+ * @param array $serializer Serializer to test.
140
+ * @param array $compressor Compressor to test.
137
141
*/
138
- public function testSynchronizedWorks ( $ serialization )
142
+ public function testSerializersAndCompressors ( $ serializer , $ compressor )
139
143
{
140
144
foreach ($ this ->connections as $ connection ) {
141
- $ connection ->setOption (Redis::OPT_SERIALIZER , $ serialization );
145
+ $ connection ->setOption (Redis::OPT_SERIALIZER , $ serializer );
146
+ $ connection ->setOption (Redis::OPT_COMPRESSION , $ compressor );
142
147
}
143
148
144
- $ this ->assertSame ("test " , $ this ->mutex ->synchronized (function (): string {
145
- return "test " ;
146
- }));
149
+ $ this ->assertSame (
150
+ "test " ,
151
+ $ this ->mutex ->synchronized (function (): string {
152
+ return "test " ;
153
+ })
154
+ );
147
155
}
148
156
149
157
public function testResistantToPartialClusterFailuresForAcquiringLock ()
150
158
{
151
159
$ this ->closeMinorityConnections ();
152
160
153
- $ this ->assertSame ("test " , $ this ->mutex ->synchronized (function (): string {
154
- return "test " ;
155
- }));
161
+ $ this ->assertSame (
162
+ "test " ,
163
+ $ this ->mutex ->synchronized (function (): string {
164
+ return "test " ;
165
+ })
166
+ );
156
167
}
157
168
158
169
public function testResistantToPartialClusterFailuresForReleasingLock ()
@@ -163,21 +174,42 @@ public function testResistantToPartialClusterFailuresForReleasingLock()
163
174
}));
164
175
}
165
176
166
- public function dpSerializationModes ()
177
+ public function serializationAndCompressionModes ()
167
178
{
168
179
if (!class_exists (Redis::class)) {
169
180
return [];
170
181
}
171
182
172
- $ serializers = [
173
- [Redis::SERIALIZER_NONE ],
174
- [Redis::SERIALIZER_PHP ],
183
+ $ options = [
184
+ [Redis::SERIALIZER_NONE , Redis:: COMPRESSION_NONE ],
185
+ [Redis::SERIALIZER_PHP , Redis:: COMPRESSION_NONE ],
175
186
];
176
187
177
188
if (defined ("Redis::SERIALIZER_IGBINARY " )) {
178
- $ serializers [] = [constant ("Redis::SERIALIZER_IGBINARY " )];
189
+ $ options [] = [
190
+ constant ("Redis::SERIALIZER_IGBINARY " ),
191
+ Redis::COMPRESSION_NONE
192
+ ];
193
+ }
194
+
195
+ if (defined ("Redis::COMPRESSION_LZF " )) {
196
+ $ options [] = [
197
+ Redis::SERIALIZER_NONE ,
198
+ constant ("Redis::COMPRESSION_LZF " )
199
+ ];
200
+ $ options [] = [
201
+ Redis::SERIALIZER_PHP ,
202
+ constant ("Redis::COMPRESSION_LZF " )
203
+ ];
204
+
205
+ if (defined ("Redis::SERIALIZER_IGBINARY " )) {
206
+ $ options [] = [
207
+ constant ("Redis::SERIALIZER_IGBINARY " ),
208
+ constant ("Redis::COMPRESSION_LZF " )
209
+ ];
210
+ }
179
211
}
180
212
181
- return $ serializers ;
213
+ return $ options ;
182
214
}
183
215
}
0 commit comments