Skip to content

Commit 5b9c0c6

Browse files
committed
1 parent 837dee4 commit 5b9c0c6

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

library.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1420,6 +1420,11 @@ PHP_REDIS_API int redis_sock_connect(RedisSock *redis_sock TSRMLS_DC)
14201420
int host_len, usocket = 0, err = 0;
14211421
php_netstream_data_t *sock;
14221422
int tcp_flag = 1;
1423+
#if (PHP_MAJOR_VERSION < 7)
1424+
char *estr = NULL;
1425+
#else
1426+
zend_string *estr = NULL;
1427+
#endif
14231428

14241429
if (redis_sock->stream != NULL) {
14251430
redis_sock_disconnect(redis_sock TSRMLS_CC);
@@ -1463,13 +1468,22 @@ PHP_REDIS_API int redis_sock_connect(RedisSock *redis_sock TSRMLS_DC)
14631468

14641469
redis_sock->stream = php_stream_xport_create(host, host_len,
14651470
0, STREAM_XPORT_CLIENT | STREAM_XPORT_CONNECT,
1466-
persistent_id, tv_ptr, NULL, NULL, &err);
1471+
persistent_id, tv_ptr, NULL, &estr, &err);
14671472

14681473
if (persistent_id) {
14691474
efree(persistent_id);
14701475
}
14711476

14721477
if (!redis_sock->stream) {
1478+
if (estr) {
1479+
#if (PHP_MAJOR_VERSION < 7)
1480+
redis_sock_set_err(redis_sock, estr, strlen(estr));
1481+
efree(estr);
1482+
#else
1483+
redis_sock_set_err(redis_sock, ZSTR_VAL(estr), ZSTR_LEN(estr));
1484+
zend_string_release(estr);
1485+
#endif
1486+
}
14731487
return -1;
14741488
}
14751489

redis.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,9 @@ redis_connect(INTERNAL_FUNCTION_PARAMETERS, int persistent)
943943
persistent_id, retry_interval, 0);
944944

945945
if (redis_sock_server_open(redis->sock TSRMLS_CC) < 0) {
946+
if (redis->sock->err) {
947+
zend_throw_exception(redis_exception_ce, ZSTR_VAL(redis->sock->err), 0 TSRMLS_CC);
948+
}
946949
redis_free_socket(redis->sock);
947950
redis->sock = NULL;
948951
return FAILURE;

0 commit comments

Comments
 (0)