8000 Allow calling methods only in atomic mode · phpredis/phpredis@cbaf095 · GitHub
[go: up one dir, main page]

Skip to content

Commit cbaf095

Browse files
yatsukhnenkomichael-grunder
authored andcommitted
Allow calling methods only in atomic mode
1 parent 056c2db commit cbaf095

File tree

5 files changed

+26
-18
lines changed

5 files changed

+26
-18
lines changed

library.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2077,16 +2077,15 @@ redis_hello_response(INTERNAL_FUNCTION_PARAMETERS,
20772077
zv = zend_hash_str_find(Z_ARRVAL(z_ret), ZEND_STRL("version"));
20782078
redis_sock->hello.version = zv ? zval_get_string(zv) : ZSTR_EMPTY_ALLOC();
20792079

2080-
if (ctx != NULL) {
2081-
zval_dtor(&z_ret);
2082-
if (ctx == PHPREDIS_CTX_PTR) {
2083-
ZVAL_STR_COPY(&z_ret, redis_sock->hello.server);
2084-
} else if (ctx == PHPREDIS_CTX_PTR + 1) {
2085-
ZVAL_STR_COPY(&z_ret, redis_sock->hello.version);
2086-
} else {
2087-
ZEND_ASSERT(!"memory corruption?");
2088-
return FAILURE;
2089-
}
2080+
zval_dtor(&z_ret);
2081+
2082+
if (ctx == PHPREDIS_CTX_PTR) {
2083+
ZVAL_STR_COPY(&z_ret, redis_sock->hello.server);
2084+
} else if (ctx == PHPREDIS_CTX_PTR + 1) {
2085+
ZVAL_STR_COPY(&z_ret, redis_sock->hello.version);
2086+
} else {
2087+
ZEND_ASSERT(!"memory corruption?");
2088+
return FAILURE;
20902089
}
20912090

20922091
if (IS_ATOMIC(redis_sock)) {

redis.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2580,7 +2580,11 @@ PHP_METHOD(Redis, getPort) {
25802580
PHP_METHOD(Redis, serverName) {
25812581
RedisSock *rs;
25822582

2583-
if ((rs = redis_sock_get_connected(INTERNAL_FUNCTION_PARAM_PASSTHRU)) == NULL) {
2583+
if ((rs = redis_sock_get_instance(getThis(), 1)) == NULL) {
2584+
RETURN_FALSE;
2585+
} else if (!IS_ATOMIC(rs)) {
2586+
php_error_docref(NULL, E_ERROR,
2587+
"Can't call serverName in multi or pipeline mode!");
25842588
RETURN_FALSE;
25852589
} else if (rs->hello.server != NULL) {
25862590
RETURN_STR_COPY(rs->hello.server);
@@ -2592,7 +2596,11 @@ PHP_METHOD(Redis, serverName) {
25922596
PHP_METHOD(Redis, serverVersion) {
25932597
RedisSock *rs;
25942598

2595-
if ((rs = redis_sock_get_connected(INTERNAL_FUNCTION_PARAM_PASSTHRU)) == NULL) {
2599+
if ((rs = redis_sock_get_instance(getThis(), 1)) == NULL) {
2600+
RETURN_FALSE;
2601+
} else if (!IS_ATOMIC(rs)) {
2602+
php_error_docref(NULL, E_ERROR,
2603+
"Can't call serverVersion in multi or pipeline mode!");
25962604
RETURN_FALSE;
25972605
} else if (rs->hello.version != NULL) {
25982606
RETURN_STR_COPY(rs->hello.version);

redis.stub.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1595,14 +1595,14 @@ public function getPort(): int;
15951595
*
15961596
* @return string|false
15971597
*/
1598-
public function serverName(): Redis|string|false;
1598+
public function serverName(): string|false;
15991599

16001600
/**
16011601
* Get the server version as reported by the `HELLO` response.
16021602
*
16031603
* @return string|false
16041604
*/
1605-
public function serverVersion(): Redis|string|false;
1605+
public function serverVersion(): string|false;
16061606

16071607
/**
16081608
* Retrieve a substring of a string by index.

redis_arginfo.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 79376d7ada29d6f9bb873e7c59e64e22af3ca559 */
2+
* Stub hash: 805a66c17b7c9972c73a979bdd67f98f7c1f6c74 */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis___construct, 0, 0, 0)
55
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, options, IS_ARRAY, 1, "null")
@@ -363,7 +363,7 @@ ZEND_END_ARG_INFO()
363363

364364
#define arginfo_class_Redis_getPort arginfo_class_Redis_getDBNum
365365

366-
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_Redis_serverName, 0, 0, Redis, MAY_BE_STRING|MAY_BE_FALSE)
366+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_class_Redis_serverName, 0, 0, MAY_BE_STRING|MAY_BE_FALSE)
367367
ZEND_END_ARG_INFO()
368368

369369
#define arginfo_class_Redis_serverVersion arginfo_class_Redis_serverName
@@ -686,7 +686,8 @@ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_Redis_rPop, 0, 1, Redi
686686
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, count, IS_LONG, 0, "0")
687687
ZEND_END_ARG_INFO()
688688

689-
#define arginfo_class_Redis_randomKey arginfo_class_Redis_serverName
689+
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_class_Redis_randomKey, 0, 0, Redis, MAY_BE_STRING|MAY_BE_FALSE)
690+
ZEND_END_ARG_INFO()
690691

691692
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Redis_rawcommand, 0, 1, IS_MIXED, 0)
692693
ZEND_ARG_TYPE_INFO(0, command, IS_STRING, 0)

redis_legacy_arginfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 79376d7ada29d6f9bb873e7c59e64e22af3ca559 */
2+
* Stub hash: 805a66c17b7c9972c73a979bdd67f98f7c1f6c74 */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Redis___construct, 0, 0, 0)
55
ZEND_ARG_INFO(0, options)

0 commit comments

Comments
 (0)
0