@@ -70,6 +70,44 @@ public function testDeleteFilterArguments(): void
7070 $ this ->assertSameValues ($ expected , $ command ->getArguments ());
7171 }
7272
73+ /**
74+ * @group disconnected
75+ */
76+ public function testDumpFilterArguments (): void
77+ {
78+ $ arguments = ['DUMP ' ];
79+ $ expected = ['DUMP ' ];
80+
81+ $ command = $ this ->getCommand ();
82+ $ command ->setArguments ($ arguments );
83+
84+ $ this ->assertSameValues ($ expected , $ command ->getArguments ());
85+ }
86+
87+ /**
88+ * @dataProvider flushArgumentsProvider
89+ * @group disconnected
90+ */
91+ public function testFlushFilterArguments (array $ actualArguments , array $ expectedResponse ): void
92+ {
93+ $ command = $ this ->getCommand ();
94+ $ command ->setArguments ($ actualArguments );
95+
96+ $ this ->assertSameValues ($ expectedResponse , $ command ->getArguments ());
97+ }
98+
99+ /**
100+ * @dataProvider restoreArgumentsProvider
101+ * @group disconnected
102+ */
103+ public function testRestoreFilterArguments (array $ actualArguments , array $ expectedResponse ): void
104+ {
105+ $ command = $ this ->getCommand ();
106+ $ command ->setArguments ($ actualArguments );
107+
108+ $ this ->assertSameValues ($ expectedResponse , $ command ->getArguments ());
109+ }
110+
73111 /**
74112 * @group disconnected
75113 */
@@ -86,7 +124,7 @@ public function testParseResponse(): void
86124 public function testLoadFunctionAddFunctionIntoGivenLibrary (): void
87125 {
88126 $ redis = $ this ->getClient ();
89- $ redis ->executeRaw ([ ' FUNCTION ' , ' FLUSH ' ] );
127+ $ redis ->function -> flush ( );
90128
91129 $ actualResponse = $ redis ->function ->load (
92130 "#!lua name= {$ this ->libName } \n redis.register_function('myfunc', function(keys, args) return args[1] end) "
@@ -105,7 +143,7 @@ public function testLoadFunctionAddFunctionIntoGivenLibrary(): void
105143 public function testLoadFunctionOverridesExistingFunctionWithReplaceArgumentGiven (): void
106144 {
107145 $ redis = $ this ->getClient ();
108- $ redis ->executeRaw ([ ' FUNCTION ' , ' FLUSH ' ] );
146+ $ redis ->function -> flush ( );
109147
110148 $ actualResponse = $ redis ->function ->load (
111149 "#!lua name= {$ this ->libName } \n redis.register_function('myfunc', function(keys, args) return args[1] end) "
@@ -132,7 +170,7 @@ public function testLoadFunctionOverridesExistingFunctionWithReplaceArgumentGive
132170 public function testLoadFunctionThrowsErrorOnAlreadyExistingLibraryGiven (): void
133171 {
134172 $ redis = $ this ->getClient ();
135- $ redis ->executeRaw ([ ' FUNCTION ' , ' FLUSH ' ] );
173+ $ redis ->function -> flush ( );
136174
137175 $ actualResponse = $ redis ->function ->load (
138176 "#!lua name= {$ this ->libName } \n redis.register_function('myfunc', function(keys, args) return args[1] end) "
@@ -160,7 +198,7 @@ public function testLoadFunctionThrowsErrorOnAlreadyExistingLibraryGiven(): void
160198 public function testDeleteFunctionRemovesAlreadyExistingLibrary (): void
161199 {
162200 $ redis = $ this ->getClient ();
163- $ redis ->executeRaw ([ ' FUNCTION ' , ' FLUSH ' ] );
201+ $ redis ->function -> flush ( );
164202
165203 $ actualResponse = $ redis ->function ->load (
166204 "#!lua name= {$ this ->libName } \n redis.register_function('myfunc', function(keys, args) return args[1] end) "
@@ -170,6 +208,65 @@ public function testDeleteFunctionRemovesAlreadyExistingLibrary(): void
170208 $ this ->assertEquals ('OK ' , $ redis ->function ->delete ($ this ->libName ));
171209 }
172210
211+ /**
212+ * @group connected
213+ * @return void
214+ * @requiresRedisVersion >= 7.0.0
215+ */
216+ public function testDumpReturnsSerializedPayloadOfLibrary (): void
217+ {
218+ $ redis = $ this ->getClient ();
219+ $ redis ->function ->flush ();
220+
221+ $ libName = $ redis ->function ->load (
222+ "#!lua name= {$ this ->libName } \n redis.register_function('myfunc', function(keys, args) return args[1] end) "
223+ );
224+
225+ $ this ->assertSame ($ this ->libName , $ libName );
226+ $ this ->assertStringContainsString ($ libName , $ redis ->function ->dump ());
227+ }
228+
229+ /**
230+ * @group connected
231+ * @return void
232+ * @requiresRedisVersion >= 7.0.0
233+ */
234+ public function testFlushRemovesAllLibraries (): void
235+ {
236+ $ redis = $ this ->getClient ();
237+ $ redis ->function ->flush ();
238+
239+ $ libName = $ redis ->function ->load (
240+ "#!lua name= {$ this ->libName } \n redis.register_function('myfunc', function(keys, args) return args[1] end) "
241+ );
242+
243+ $ this ->assertEquals ($ this ->libName , $ libName );
244+ $ this ->assertEquals ('OK ' , $ redis ->function ->flush ());
245+ }
246+
247+ /**
248+ * @group connected
249+ * @return void
250+ * @requiresRedisVersion >= 7.0.0
251+ */
252+ public function testRestoresLibraryFromSerializedPayload (): void
253+ {
254+ $ redis = $ this ->getClient ();
255+ $ redis ->function ->flush ();
256+
257+ $ libName = $ redis ->function ->load (
258+ "#!lua name= {$ this ->libName } \n redis.register_function('myfunc', function(keys, args) return args[1] end) "
259+ );
260+ $ this ->assertEquals ($ this ->libName , $ libName );
261+
262+ $ serializedPayload = $ redis ->function ->dump ();
263+ $ this ->assertStringContainsString ($ libName , $ serializedPayload );
264+
265+ $ redis ->function ->flush ();
266+
267+ $ this ->assertEquals ('OK ' , $ redis ->function ->restore ($ serializedPayload ));
268+ }
269+
173270 /**
174271 * @group connected
175272 * @return void
@@ -178,11 +275,39 @@ public function testDeleteFunctionRemovesAlreadyExistingLibrary(): void
178275 public function testDeleteFunctionThrowsErrorOnNonExistingLibrary (): void
179276 {
180277 $ redis = $ this ->getClient ();
181- $ redis ->executeRaw ([ ' FUNCTION ' , ' FLUSH ' ] );
278+ $ redis ->function -> flush ( );
182279
183280 $ this ->expectException (ServerException::class);
184281 $ this ->expectExceptionMessage ('ERR Library not found ' );
185282
186283 $ redis ->function ->delete ($ this ->libName );
187284 }
285+
286+ public function flushArgumentsProvider (): array
287+ {
288+ return [
289+ 'with default arguments ' => [
290+ ['FLUSH ' , null ],
291+ ['FLUSH ' ],
292+ ],
293+ 'with mode argument ' => [
294+ ['FLUSH ' , 'sync ' ],
295+ ['FLUSH ' , 'SYNC ' ],
296+ ],
297+ ];
298+ }
299+
300+ public function restoreArgumentsProvider (): array
301+ {
302+ return [
303+ 'with default arguments ' => [
304+ ['RESTORE ' , 'value ' , null ],
305+ ['RESTORE ' , 'value ' ],
306+ ],
307+ 'with mode argument ' => [
308+ ['RESTORE ' , 'value ' , 'append ' ],
309+ ['RESTORE ' , 'value ' , 'APPEND ' ],
310+ ],
311+ ];
312+ }
188313}
0 commit comments