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:
authorNicolas Favre-Felix <n.favrefelix@gmail.com>2012-05-28 01:25:16 +0400
committerNicolas Favre-Felix <n.favrefelix@gmail.com>2012-05-28 01:26:08 +0400
commit38e2cca3cf0fa4caa269cfc9e10f6bae2b0ce461 (patch)
treec4c28f5af3052b616f99e34187e940988b3f1a3e /library.c
parentbcabe601b239db3204e72b292a4d874ef8ad4017 (diff)
parent2e70c5a5a93bbf3cb2d6a1f31a01e6758b21ae11 (diff)
Merge branch '0-reconnect-select'
Diffstat (limited to 'library.c')
-rw-r--r--library.c31
1 files changed, 29 insertions, 2 deletions
diff --git a/library.c b/library.c
index a5224caf..6a1a6725 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;
}
@@ -794,6 +819,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;
@@ -933,6 +959,7 @@ PHPAPI int redis_sock_disconnect(RedisSock *redis_sock TSRMLS_DC)
return 1;
}
+ redis_sock->dbNumber = 0;
if (redis_sock->stream != NULL) {
if (!redis_sock->persistent) {
redis_sock_write(redis_sock, "QUIT", sizeof("QUIT") - 1 TSRMLS_CC);