Skip to content

Commit 5bb430d

Browse files
committed
fix problem when doing a connect many times in one request
1 parent 6b03469 commit 5bb430d

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

redis.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ PHP_METHOD(Redis, __construct)
349349
PHP_METHOD(Redis, connect)
350350
{
351351
zval *object;
352+
zval **socket;
352353
int host_len, id;
353354
char *host = NULL;
354355
long port = -1;
@@ -371,6 +372,16 @@ PHP_METHOD(Redis, connect)
371372
port = 6379;
372373
}
373374

375+
/* if there is a redis sock already we have to remove it from the list */
376+
if (redis_sock_get(object, &redis_sock TSRMLS_CC) > 0) {
377+
if (zend_hash_find(Z_OBJPROP_P(object), "socket",
378+
sizeof("socket"), (void **) &socket) == FAILURE) {
379+
/* maybe there is a socket but the id isn't known.. what to do? */
380+
} else {
381+
zend_list_delete(Z_LVAL_PP(socket)); /* the refcount should be decreased and the detructor called */
382+
}
383+
}
384+
374385
redis_sock = redis_sock_create(host, host_len, port, timeout);
375386

376387
if (redis_sock_server_open(redis_sock, 1 TSRMLS_CC) < 0) {
@@ -4479,5 +4490,5 @@ PHP_METHOD(Redis, slaveof)
44794490
}
44804491
/* }}} */
44814492

4482-
/* vim: set tabstop=4 expandtab: */
4493+
/* vim: set tabstop=4 noexpandtab: */
44834494

0 commit comments

Comments
 (0)