mirror of
https://github.com/php-win-ext/phpredis.git
synced 2026-03-24 00:52:16 +01:00
Backoff settings in constructor
This commit is contained in:
@@ -161,6 +161,11 @@ $redis = new Redis([
|
||||
'connectTimeout' => 2.5,
|
||||
'auth' => ['phpredis', 'phpredis'],
|
||||
'ssl' => ['verify_peer' => false],
|
||||
'backoff' => [
|
||||
'algorithm' => Redis::BACKOFF_ALGORITHM_DECORRELATED_JITTER,
|
||||
'base' => 500,
|
||||
'cap' => 750,
|
||||
],
|
||||
]);
|
||||
~~~
|
||||
|
||||
|
||||
38
library.c
38
library.c
@@ -2589,6 +2589,44 @@ redis_sock_set_stream_context(RedisSock *redis_sock, zval *options)
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
PHP_REDIS_API int
|
||||
redis_sock_set_backoff(RedisSock *redis_sock, zval *options)
|
||||
{
|
||||
zend_string *zkey;
|
||||
zend_long val;
|
||||
zval *z_ele;
|
||||
|
||||
if (!redis_sock || Z_TYPE_P(options) != IS_ARRAY) {
|
||||
return FAILURE;
|
||||
}
|
||||
|
||||
ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(options), zkey, z_ele) {
|
||||
if (zkey != NULL) {
|
||||
ZVAL_DEREF(z_ele);
|
||||
if (zend_string_equals_literal_ci(zkey, "algorithm")) {
|
||||
if ((val = zval_get_long(z_ele)) < 0 || val >= REDIS_BACKOFF_ALGORITHMS) {
|
||||
return FAILURE;
|
||||
}
|
||||
redis_sock->backoff.algorithm = val;
|
||||
} else if (zend_string_equals_literal_ci(zkey, "base")) {
|
||||
if ((val = zval_get_long(z_ele)) < 0) {
|
||||
return FAILURE;
|
||||
}
|
||||
redis_sock->backoff.base = val * 1000;
|
||||
} else if (zend_string_equals_literal_ci(zkey, "cap")) {
|
||||
if ((val = zval_get_long(z_ele)) < 0) {
|
||||
return FAILURE;
|
||||
}
|
||||
redis_sock->backoff.cap = val * 1000;
|
||||
} else {
|
||||
php_error_docref(NULL, E_WARNING, "Skip unknown backoff option '%s'", ZSTR_VAL(zkey));
|
||||
}
|
||||
}
|
||||
} ZEND_HASH_FOREACH_END();
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* redis_sock_read_multibulk_reply
|
||||
*/
|
||||
|
||||
@@ -117,6 +117,7 @@ PHP_REDIS_API RedisSock *redis_sock_get(zval *id, int nothrow);
|
||||
PHP_REDIS_API void redis_free_socket(RedisSock *redis_sock);
|
||||
PHP_REDIS_API void redis_sock_set_err(RedisSock *redis_sock, const char *msg, int msg_len);
|
||||
PHP_REDIS_API int redis_sock_set_stream_context(RedisSock *redis_sock, zval *options);
|
||||
PHP_REDIS_API int redis_sock_set_backoff(RedisSock *redis_sock, zval *options);
|
||||
|
||||
PHP_REDIS_API int
|
||||
redis_serialize(RedisSock *redis_sock, zval *z, char **val, size_t *val_len);
|
||||
|
||||
8
redis.c
8
redis.c
@@ -650,17 +650,21 @@ PHP_METHOD(Redis, __construct)
|
||||
}
|
||||
redis->sock->retry_interval = zval_get_long(val);
|
||||
} else if (zend_string_equals_literal_ci(zkey, "ssl")) {
|
||||
if (Z_TYPE_P(val) != IS_ARRAY) {
|
||||
if (redis_sock_set_stream_context(redis->sock, val) != SUCCESS) {
|
||||
REDIS_VALUE_EXCEPTION("Invalid SSL context options");
|
||||
RETURN_THROWS();
|
||||
}
|
||||
redis_sock_set_stream_context(redis->sock, val);
|
||||
} else if (zend_string_equals_literal_ci(zkey, "auth")) {
|
||||
if (Z_TYPE_P(val) != IS_STRING && Z_TYPE_P(val) != IS_ARRAY) {
|
||||
REDIS_VALUE_EXCEPTION("Invalid auth credentials");
|
||||
RETURN_THROWS();
|
||||
}
|
||||
redis_sock_set_auth_zval(redis->sock, val);
|
||||
} else if (zend_string_equals_literal_ci(zkey, "backoff")) {
|
||||
if (redis_sock_set_backoff(redis->sock, val) != SUCCESS) {
|
||||
REDIS_VALUE_EXCEPTION("Invalid backoff options");
|
||||
RETURN_THROWS();
|
||||
}
|
||||
} else {
|
||||
php_error_docref(NULL, E_WARNING, "Skip unknown option '%s'", ZSTR_VAL(zkey));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user