@@ -158,4 +158,70 @@ public function test_ClusterFullMovedErrorResponse() {
158158 $ this ->assertSame (1 , GlobalFunctionMock::getCountCalls ('RedisClient\Connection::fgets ' ));
159159 $ this ->assertSame (1 , GlobalFunctionMock::getCountCalls ('RedisClient\Connection::fread ' ));
160160 }
161+
162+ public function test_ClusterFullAskErrorResponse () {
163+ GlobalFunctionMock::mockFunction ('RedisClient\Connection::fwrite ' , function ($ h , $ m , $ c ) {
164+ static $ data = [
165+ [
166+ 'tcp://127.0.0.1:7003 ' ,
167+ "*2 \r\n$3 \r\nGET \r\n$3 \r\nfoo \r\n" ,
168+ ],
169+ [
170+ 'tcp://127.0.0.1:7002 ' ,
171+ "*1 \r\n$6 \r\nASKING \r\n" ,
172+ ],
173+ [
174+ 'tcp://127.0.0.1:7002 ' ,
175+ "*2 \r\n$3 \r\nGET \r\n$3 \r\nfoo \r\n" ,
176+ ],
177+ [
178+ 'tcp://127.0.0.1:7003 ' ,
179+ "*2 \r\n$3 \r\nGET \r\n$3 \r\nfoo \r\n" ,
180+ ],
181+ ];
182+ $ datum = array_shift ($ data );
183+ $ this ->assertSame ($ datum [0 ], $ h );
184+ $ this ->assertSame ($ datum [1 ], $ m );
185+ return $ c ;
186+ });
187+
188+ GlobalFunctionMock::mockFunction ('RedisClient\Connection::fgets ' , function () {
189+ static $ data = [
190+ "-ASK 12182 127.0.0.1:7002 \r\n" ,
191+ "+OK \r\n" ,
192+ "\$3 \r\n" ,
193+ "\$7 \r\n" ,
194+ ];
195+ return array_shift ($ data );
196+ });
197+
198+ GlobalFunctionMock::mockFunction ('RedisClient\Connection::fread ' , function () {
199+ static $ data = [
200+ "bar \r\n" ,
201+ "bar-bar \r\n"
202+ ];
203+ return array_shift ($ data );
204+ });
205+
206+ $ Redis = new RedisClient ([
207+ 'server ' => '127.0.0.1:7001 ' ,
208+ 'cluster ' => [
209+ 'enabled ' => true ,
210+ 'clusters ' => [
211+ 5460 => '127.0.0.1:7001 ' ,
212+ 10922 => '127.0.0.1:7002 ' ,
213+ 16383 => '127.0.0.1:7003 ' ,
214+ ]
215+ ]
216+ ]);
217+
218+ $ this ->assertSame ('bar ' , $ Redis ->get ('foo ' ));
219+ $ this ->assertSame ('bar-bar ' , $ Redis ->get ('foo ' ));
220+
221+ $ this ->assertSame (2 , GlobalFunctionMock::getCountCalls ('RedisClient\Connection::stream_socket_client ' ));
222+ $ this ->assertSame (2 , GlobalFunctionMock::getCountCalls ('RedisClient\Connection::stream_set_timeout ' ));
223+ $ this ->assertSame (4 , GlobalFunctionMock::getCountCalls ('RedisClient\Connection::fwrite ' ));
224+ $ this ->assertSame (4 , GlobalFunctionMock::getCountCalls ('RedisClient\Connection::fgets ' ));
225+ $ this ->assertSame (2 , GlobalFunctionMock::getCountCalls ('RedisClient\Connection::fread ' ));
226+ }
161227}
0 commit comments