mirror of
https://github.com/php-win-ext/phpredis.git
synced 2026-04-24 17:18:27 +02:00
Allow to specify server address as schema://host
This commit is contained in:
@@ -1695,19 +1695,23 @@ redis_sock_create(char *host, int host_len, unsigned short port,
|
|||||||
PHP_REDIS_API int redis_sock_connect(RedisSock *redis_sock TSRMLS_DC)
|
PHP_REDIS_API int redis_sock_connect(RedisSock *redis_sock TSRMLS_DC)
|
||||||
{
|
{
|
||||||
struct timeval tv, read_tv, *tv_ptr = NULL;
|
struct timeval tv, read_tv, *tv_ptr = NULL;
|
||||||
zend_string *persistent_id = NULL;
|
zend_string *persistent_id = NULL, *estr = NULL;
|
||||||
char host[1024];
|
char host[1024], *pos, *address, *schema = NULL;
|
||||||
const char *fmtstr = "%s:%d";
|
const char *fmtstr = "%s://%s:%d";
|
||||||
int host_len, usocket = 0, err = 0, tcp_flag = 1;
|
int host_len, usocket = 0, err = 0, tcp_flag = 1;
|
||||||
ConnectionPool *p = NULL;
|
ConnectionPool *p = NULL;
|
||||||
zend_string *estr = NULL;
|
|
||||||
|
|
||||||
if (redis_sock->stream != NULL) {
|
if (redis_sock->stream != NULL) {
|
||||||
redis_sock_disconnect(redis_sock, 0 TSRMLS_CC);
|
redis_sock_disconnect(redis_sock, 0 TSRMLS_CC);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ZSTR_VAL(redis_sock->host)[0] == '/' && redis_sock->port < 1) {
|
address = ZSTR_VAL(redis_sock->host);
|
||||||
host_len = snprintf(host, sizeof(host), "unix://%s", ZSTR_VAL(redis_sock->host));
|
if ((pos = strstr(address, "://")) != NULL) {
|
||||||
|
schema = estrndup(address, pos - address);
|
||||||
|
address = pos + sizeof("://") - 1;
|
||||||
|
}
|
||||||
|
if (redis_sock->port < 1) {
|
||||||
|
host_len = snprintf(host, sizeof(host), "unix://%s", address);
|
||||||
usocket = 1;
|
usocket = 1;
|
||||||
} else {
|
} else {
|
||||||
if(redis_sock->port == 0)
|
if(redis_sock->port == 0)
|
||||||
@@ -1716,11 +1720,12 @@ PHP_REDIS_API int redis_sock_connect(RedisSock *redis_sock TSRMLS_DC)
|
|||||||
#ifdef HAVE_IPV6
|
#ifdef HAVE_IPV6
|
||||||
/* If we've got IPv6 and find a colon in our address, convert to proper
|
/* If we've got IPv6 and find a colon in our address, convert to proper
|
||||||
* IPv6 [host]:port format */
|
* IPv6 [host]:port format */
|
||||||
if (strchr(ZSTR_VAL(redis_sock->host), ':') != NULL) {
|
if (strchr(address, ':') != NULL) {
|
||||||
fmtstr = "[%s]:%d";
|
fmtstr = "%s://[%s]:%d";
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
host_len = snprintf(host, sizeof(host), fmtstr, ZSTR_VAL(redis_sock->host), redis_sock->port);
|
host_len = snprintf(host, sizeof(host), fmtstr, schema ? schema : "tcp", address, redis_sock->port);
|
||||||
|
if (schema) efree(schema);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (redis_sock->persistent) {
|
if (redis_sock->persistent) {
|
||||||
|
|||||||
Reference in New Issue
Block a user