Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitff549ab

Browse files
authored
Merge pull requestphpredis#1108 from yatsukhnenko/develop
redis_check_eof refactoring
2 parentsaa6ff77 +be5c1f5 commitff549ab

File tree

2 files changed

+41
-36
lines changed

2 files changed

+41
-36
lines changed

‎library.c

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,10 @@ PHP_REDIS_API void redis_stream_close(RedisSock *redis_sock TSRMLS_DC) {
140140
}
141141
}
142142

143-
PHP_REDIS_APIintredis_check_eof(RedisSock*redis_sock,intno_throwTSRMLS_DC)
143+
PHP_REDIS_APIint
144+
redis_check_eof(RedisSock*redis_sock,intno_throwTSRMLS_DC)
144145
{
145-
inteof;
146-
intcount=0;
146+
intcount;
147147

148148
if (!redis_sock->stream) {
149149
return-1;
@@ -164,53 +164,57 @@ PHP_REDIS_API int redis_check_eof(RedisSock *redis_sock, int no_throw TSRMLS_DC)
164164
* Bug fix of php: https://github.com/php/php-src/pull/1456
165165
* */
166166
errno=0;
167-
eof=php_stream_eof(redis_sock->stream);
168-
for (;eof;count++) {
169-
if((MULTI==redis_sock->mode)||redis_sock->watching||count==10) {
170-
/* too many failures */
171-
if(redis_sock->stream) {/* close stream if still here */
172-
REDIS_STREAM_CLOSE_MARK_FAILED(redis_sock);
173-
}
174-
if(!no_throw) {
175-
zend_throw_exception(redis_exception_ce,"Connection lost",
176-
0TSRMLS_CC);
177-
}
178-
return-1;
167+
if (php_stream_eof(redis_sock->stream)==0) {
168+
/* Success */
169+
return0;
170+
}elseif (redis_sock->mode==MULTI||redis_sock->watching) {
171+
REDIS_STREAM_CLOSE_MARK_FAILED(redis_sock);
172+
if (!no_throw) {
173+
zend_throw_exception(redis_exception_ce,
174+
"Connection lost and socket is in MULTI/watching mode",
175+
0TSRMLS_CC);
179176
}
180-
if(redis_sock->stream) {/* close existing stream before reconnecting */
177+
return-1;
178+
}
179+
/* TODO: configurable max retry count */
180+
for (count=0;count<10;++count) {
181+
/* close existing stream before reconnecting */
182+
if (redis_sock->stream) {
181183
redis_stream_close(redis_sockTSRMLS_CC);
182184
redis_sock->stream=NULL;
183-
redis_sock->mode=ATOMIC;
184-
redis_sock->watching=0;
185185
}
186186
// Wait for a while before trying to reconnect
187187
if (redis_sock->retry_interval) {
188188
// Random factor to avoid having several (or many) concurrent connections trying to reconnect at the same time
189189
longretry_interval= (count ?redis_sock->retry_interval : (php_rand(TSRMLS_C) %redis_sock->retry_interval));
190190
usleep(retry_interval);
191191
}
192-
redis_sock_connect(redis_sockTSRMLS_CC);/* reconnect */
193-
if(redis_sock->stream) {/* check for EOF again. */
192+
/* reconnect */
193+
if (redis_sock_connect(redis_sockTSRMLS_CC)==0) {
194+
/* check for EOF again. */
194195
errno=0;
195-
eof=php_stream_eof(redis_sock->stream);
196+
if (php_stream_eof(redis_sock->stream)==0) {
197+
/* If we're using a password, attempt a reauthorization */
198+
if (redis_sock->auth&&resend_auth(redis_sockTSRMLS_CC)!=0) {
199+
break;
200+
}
201+
/* If we're using a non-zero db, reselect it */
202+
if (redis_sock->dbNumber&&reselect_db(redis_sockTSRMLS_CC)!=0) {
203+
break;
204+
}
205+
/* Success */
206+
return0;
207+
}
196208
}
197209
}
198-
199-
/* We've connected if we have a count */
200-
if (count) {
201-
/* If we're using a password, attempt a reauthorization */
202-
if (redis_sock->auth&&resend_auth(redis_sockTSRMLS_CC)!=0) {
203-
return-1;
204-
}
205-
206-
/* If we're using a non-zero db, reselect it */
207-
if (redis_sock->dbNumber&&reselect_db(redis_sockTSRMLS_CC)!=0) {
208-
return-1;
209-
}
210+
/* close stream if still here */
211+
if (redis_sock->stream) {
212+
REDIS_STREAM_CLOSE_MARK_FAILED(redis_sock);
210213
}
211-
212-
/* Success */
213-
return0;
214+
if (!no_throw) {
215+
zend_throw_exception(redis_exception_ce,"Connection lost",0TSRMLS_CC);
216+
}
217+
return-1;
214218
}
215219

216220

‎redis.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,7 @@ redis_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
844844

845845
if (redis_sock_server_open(redis->sock,1TSRMLS_CC)<0) {
846846
redis_free_socket(redis->sock);
847+
redis->sock=NULL;
847848
returnFAILURE;
848849
}
849850

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp