Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/phpredis/phpredis.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitri Iouchtchenko <johnnyspoon@gmail.com>2012-05-09 06:50:36 +0400
committerDmitri Iouchtchenko <johnnyspoon@gmail.com>2012-05-09 06:50:36 +0400
commitdb3c3c5d2a298c8aa329ae71f4194f021aee5428 (patch)
treee4058c712fcd3ede580d8f8d7abe8931d96a0879 /library.c
parentad7de59d8066e897b21d7c4c45e99f9cefc5c582 (diff)
Added SELECT after reconnect
This prevents the DB number from being reset to zero after a timeout and subsequent automatic reconnect.
Diffstat (limited to 'library.c')
-rw-r--r--library.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/library.c b/library.c
index 930244a9..dc420fed 100644
--- a/library.c
+++ b/library.c
@@ -38,8 +38,8 @@ PHPAPI int redis_check_eof(RedisSock *redis_sock TSRMLS_DC)
return -1;
eof = php_stream_eof(redis_sock->stream);
- while(eof) {
- if((MULTI == redis_sock->mode) || redis_sock->watching || count++ == 10) { /* too many failures */
+ for (; eof; count++) {
+ if((MULTI == redis_sock->mode) || redis_sock->watching || count == 10) { /* too many failures */
if(redis_sock->stream) { /* close stream if still here */
php_stream_close(redis_sock->stream);
redis_sock->stream = NULL;
@@ -61,6 +61,31 @@ PHPAPI int redis_check_eof(RedisSock *redis_sock TSRMLS_DC)
eof = php_stream_eof(redis_sock->stream);
}
}
+
+ // Reselect the DB.
+ if (count && redis_sock->dbNumber) {
+ char *cmd, *response;
+ int cmd_len, response_len;
+
+ cmd_len = redis_cmd_format_static(&cmd, "SELECT", "d", redis_sock->dbNumber);
+
+ if (redis_sock_write(redis_sock, cmd, cmd_len TSRMLS_CC) < 0) {
+ efree(cmd);
+ return -1;
+ }
+ efree(cmd);
+
+ if ((response = redis_sock_read(redis_sock, &response_len TSRMLS_CC)) == NULL) {
+ return -1;
+ }
+
+ if (strncmp(response, "+OK", 3)) {
+ efree(response);
+ return -1;
+ }
+ efree(response);
+ }
+
return 0;
}
@@ -731,6 +756,7 @@ PHPAPI RedisSock* redis_sock_create(char *host, int host_len, unsigned short por
redis_sock->stream = NULL;
redis_sock->status = REDIS_SOCK_STATUS_DISCONNECTED;
redis_sock->watching = 0;
+ redis_sock->dbNumber = 0;
redis_sock->persistent = persistent;