@@ -847,9 +847,30 @@ ZEND_END_ARG_INFO()
847
847
#define IS_EX_PX_ARG (a ) (IS_EX_ARG(a) || IS_PX_ARG(a))
848
848
#define IS_NX_XX_ARG (a ) (IS_NX_ARG(a) || IS_XX_ARG(a))
849
849
850
+ struct RedisClient {
851
+ redisContext *context;
852
+ struct {
853
+ bool auth;
854
+ long db_num;
855
+ bool subscribe;
856
+ } session;
857
+ double connect_timeout;
858
+ double timeout;
859
+ bool serialize;
860
+ bool defer;
861
+ uint8_t reconnect_interval;
862
+ uint8_t reconnected_count;
863
+ bool auth;
864
+ bool compatibility_mode;
865
+ long database;
866
+ zval *zobject;
867
+ zval _zobject;
868
+ zend_object std;
869
+ };
870
+
850
871
#define SW_REDIS_COMMAND_CHECK \
851
872
Coroutine::get_current_safe (); \
852
- swRedisClient *redis = php_swoole_get_redis_client(ZEND_THIS);
873
+ RedisClient *redis = php_swoole_get_redis_client(ZEND_THIS);
853
874
854
875
#define SW_REDIS_COMMAND_ARGV_FILL (str, str_len ) \
855
876
argvlen[i] = str_len; \
@@ -893,43 +914,16 @@ ZEND_END_ARG_INFO()
893
914
efree (argv); \
894
915
}
895
916
896
- typedef struct {
897
- redisContext *context;
898
- struct {
899
- bool auth;
900
- long db_num;
901
- bool subscribe;
902
- } session;
903
- double connect_timeout;
904
- double timeout;
905
- bool serialize;
906
- bool defer;
907
- uint8_t reconnect_interval;
908
- uint8_t reconnected_count;
909
- bool auth;
910
- bool compatibility_mode;
911
- long database;
912
- zval *zobject;
913
- zval _zobject;
914
- zend_object std;
915
- } swRedisClient;
916
-
917
- typedef struct {
918
- zval _value;
919
- zval *value;
920
- swRedisClient *redis;
921
- } swRedis_result;
922
-
923
917
enum { SW_REDIS_MODE_MULTI, SW_REDIS_MODE_PIPELINE };
924
918
925
- static void swoole_redis_coro_parse_result (swRedisClient *redis, zval *return_value, redisReply *reply);
919
+ static void swoole_redis_coro_parse_result (RedisClient *redis, zval *return_value, redisReply *reply);
926
920
927
- static sw_inline swRedisClient *php_swoole_redis_coro_fetch_object (zend_object *obj) {
928
- return (swRedisClient *) ((char *) obj - swoole_redis_coro_handlers.offset );
921
+ static sw_inline RedisClient *php_swoole_redis_coro_fetch_object (zend_object *obj) {
922
+ return (RedisClient *) ((char *) obj - swoole_redis_coro_handlers.offset );
929
923
}
930
924
931
- static sw_inline swRedisClient *php_swoole_get_redis_client (zval *zobject) {
932
- swRedisClient *redis = (swRedisClient *) php_swoole_redis_coro_fetch_object (Z_OBJ_P (zobject));
925
+ static sw_inline RedisClient *php_swoole_get_redis_client (zval *zobject) {
926
+ RedisClient *redis = (RedisClient *) php_swoole_redis_coro_fetch_object (Z_OBJ_P (zobject));
933
927
if (UNEXPECTED (!redis)) {
934
928
php_swoole_fatal_error (E_ERROR, " you must call Redis constructor first" );
935
929
}
@@ -943,7 +937,7 @@ static sw_inline Socket *swoole_redis_coro_get_socket(redisContext *context) {
943
937
return nullptr ;
944
938
}
945
939
946
- static sw_inline bool swoole_redis_coro_close (swRedisClient *redis) {
940
+ static sw_inline bool swoole_redis_coro_close (RedisClient *redis) {
947
941
if (redis->context ) {
948
942
int sockfd = redis->context ->fd ;
949
943
Socket *socket = swoole_redis_coro_get_socket (redis->context );
@@ -963,7 +957,7 @@ static sw_inline bool swoole_redis_coro_close(swRedisClient *redis) {
963
957
}
964
958
965
959
static void php_swoole_redis_coro_free_object (zend_object *object) {
966
- swRedisClient *redis = php_swoole_redis_coro_fetch_object (object);
960
+ RedisClient *redis = php_swoole_redis_coro_fetch_object (object);
967
961
968
962
if (redis && redis->context ) {
969
963
swoole_redis_coro_close (redis);
@@ -973,7 +967,7 @@ static void php_swoole_redis_coro_free_object(zend_object *object) {
973
967
}
974
968
975
969
static zend_object *php_swoole_redis_coro_create_object (zend_class_entry *ce) {
976
- swRedisClient *redis = (swRedisClient *) zend_object_alloc (sizeof (swRedisClient ), ce);
970
+ RedisClient *redis = (RedisClient *) zend_object_alloc (sizeof (RedisClient ), ce);
977
971
zend_object_std_init (&redis->std , ce);
978
972
object_properties_init (&redis->std , ce);
979
973
redis->std .handlers = &swoole_redis_coro_handlers;
@@ -1027,12 +1021,12 @@ static sw_inline void swoole_redis_handle_assoc_array_result(zval *return_value,
1027
1021
RETVAL_ZVAL (&zret, 1 , 1 );
1028
1022
}
1029
1023
1030
- static bool redis_auth (swRedisClient *redis, char *pw, size_t pw_len);
1031
- static bool redis_select_db (swRedisClient *redis, long db_number);
1024
+ static bool redis_auth (RedisClient *redis, char *pw, size_t pw_len);
1025
+ static bool redis_select_db (RedisClient *redis, long db_number);
1032
1026
static void redis_request (
1033
- swRedisClient *redis, int argc, char **argv, size_t *argvlen, zval *return_value, bool retry = false );
1027
+ RedisClient *redis, int argc, char **argv, size_t *argvlen, zval *return_value, bool retry = false );
1034
1028
1035
- static bool swoole_redis_coro_connect (swRedisClient *redis) {
1029
+ static bool swoole_redis_coro_connect (RedisClient *redis) {
1036
1030
zval *zobject = redis->zobject ;
1037
1031
redisContext *context;
1038
1032
Socket *socket;
@@ -1134,7 +1128,7 @@ static bool swoole_redis_coro_connect(swRedisClient *redis) {
1134
1128
return true ;
1135
1129
}
1136
1130
1137
- static sw_inline bool swoole_redis_coro_keep_liveness (swRedisClient *redis) {
1131
+ static sw_inline bool swoole_redis_coro_keep_liveness (RedisClient *redis) {
1138
1132
Socket *socket = nullptr ;
1139
1133
if (!redis->context || !(socket = swoole_redis_coro_get_socket (redis->context )) || !socket->check_liveness ()) {
1140
1134
if (socket) {
@@ -1161,7 +1155,7 @@ static sw_inline bool swoole_redis_coro_keep_liveness(swRedisClient *redis) {
1161
1155
return true ;
1162
1156
}
1163
1157
1164
- static bool redis_auth (swRedisClient *redis, char *pw, size_t pw_len) {
1158
+ static bool redis_auth (RedisClient *redis, char *pw, size_t pw_len) {
1165
1159
int i = 0 ;
1166
1160
size_t argvlen[2 ];
1167
1161
char *argv[2 ];
@@ -1178,7 +1172,7 @@ static bool redis_auth(swRedisClient *redis, char *pw, size_t pw_len) {
1178
1172
return ret;
1179
1173
}
1180
1174
1181
- static bool redis_select_db (swRedisClient *redis, long db_number) {
1175
+ static bool redis_select_db (RedisClient *redis, long db_number) {
1182
1176
int i = 0 ;
1183
1177
size_t argvlen[2 ];
1184
1178
char *argv[2 ];
@@ -1198,7 +1192,7 @@ static bool redis_select_db(swRedisClient *redis, long db_number) {
1198
1192
}
1199
1193
1200
1194
static void redis_request (
1201
- swRedisClient *redis, int argc, char **argv, size_t *argvlen, zval *return_value, bool retry) {
1195
+ RedisClient *redis, int argc, char **argv, size_t *argvlen, zval *return_value, bool retry) {
1202
1196
redisReply *reply = nullptr ;
1203
1197
if (!swoole_redis_coro_keep_liveness (redis)) {
1204
1198
ZVAL_FALSE (return_value);
@@ -1261,8 +1255,7 @@ static void redis_request(
1261
1255
}
1262
1256
}
1263
1257
}
1264
- int i;
1265
- for (i = 0 ; i < argc; i++) {
1258
+ SW_LOOP_N (argc) {
1266
1259
efree (argv[i]);
1267
1260
}
1268
1261
}
@@ -1907,7 +1900,7 @@ void php_swoole_redis_coro_minit(int module_number) {
1907
1900
SW_SET_CLASS_UNSET_PROPERTY_HANDLER (swoole_redis_coro, sw_zend_class_unset_property_deny);
1908
1901
SW_SET_CLASS_CREATE_WITH_ITS_OWN_HANDLERS (swoole_redis_coro);
1909
1902
SW_SET_CLASS_CUSTOM_OBJECT (
1910
- swoole_redis_coro, php_swoole_redis_coro_create_object, php_swoole_redis_coro_free_object, swRedisClient , std);
1903
+ swoole_redis_coro, php_swoole_redis_coro_create_object, php_swoole_redis_coro_free_object, RedisClient , std);
1911
1904
1912
1905
zend_declare_property_string (swoole_redis_coro_ce, ZEND_STRL (" host" ), " " , ZEND_ACC_PUBLIC);
1913
1906
zend_declare_property_long (swoole_redis_coro_ce, ZEND_STRL (" port" ), 0 , ZEND_ACC_PUBLIC);
@@ -1938,7 +1931,7 @@ void php_swoole_redis_coro_minit(int module_number) {
1938
1931
SW_REGISTER_LONG_CONSTANT (" SWOOLE_REDIS_ERR_ALLOC" , SW_REDIS_ERR_ALLOC);
1939
1932
}
1940
1933
1941
- static void swoole_redis_coro_set_options (swRedisClient *redis, zval *zoptions, bool backward_compatibility = false ) {
1934
+ static void swoole_redis_coro_set_options (RedisClient *redis, zval *zoptions, bool backward_compatibility = false ) {
1942
1935
zval *zsettings =
1943
1936
sw_zend_read_and_convert_property_array (swoole_redis_coro_ce, redis->zobject , ZEND_STRL (" setting" ), 0 );
1944
1937
HashTable *vht = Z_ARRVAL_P (zoptions);
@@ -1979,7 +1972,7 @@ static void swoole_redis_coro_set_options(swRedisClient *redis, zval *zoptions,
1979
1972
}
1980
1973
1981
1974
static PHP_METHOD (swoole_redis_coro, __construct) {
1982
- swRedisClient *redis = php_swoole_get_redis_client (ZEND_THIS);
1975
+ RedisClient *redis = php_swoole_get_redis_client (ZEND_THIS);
1983
1976
zval *zsettings = sw_zend_read_and_convert_property_array (swoole_redis_coro_ce, ZEND_THIS, ZEND_STRL (" setting" ), 0 );
1984
1977
zval *zset = nullptr ;
1985
1978
@@ -2044,7 +2037,7 @@ static PHP_METHOD(swoole_redis_coro, connect) {
2044
2037
}
2045
2038
2046
2039
static PHP_METHOD (swoole_redis_coro, getAuth) {
2047
- swRedisClient *redis = php_swoole_get_redis_client (ZEND_THIS);
2040
+ RedisClient *redis = php_swoole_get_redis_client (ZEND_THIS);
2048
2041
if (redis->session .auth ) {
2049
2042
zval *ztmp = sw_zend_read_and_convert_property_array (swoole_redis_coro_ce, ZEND_THIS, ZEND_STRL (" setting" ), 0 );
2050
2043
if (php_swoole_array_get_value (Z_ARRVAL_P (ztmp), " password" , ztmp)) {
@@ -2056,7 +2049,7 @@ static PHP_METHOD(swoole_redis_coro, getAuth) {
2056
2049
}
2057
2050
2058
2051
static PHP_METHOD (swoole_redis_coro, getDBNum) {
2059
- swRedisClient *redis = php_swoole_get_redis_client (ZEND_THIS);
2052
+ RedisClient *redis = php_swoole_get_redis_client (ZEND_THIS);
2060
2053
if (!redis->context ) {
2061
2054
RETURN_FALSE;
2062
2055
}
@@ -2069,7 +2062,7 @@ static PHP_METHOD(swoole_redis_coro, getOptions) {
2069
2062
}
2070
2063
2071
2064
static PHP_METHOD (swoole_redis_coro, setOptions) {
2072
- swRedisClient *redis = php_swoole_get_redis_client (ZEND_THIS);
2065
+ RedisClient *redis = php_swoole_get_redis_client (ZEND_THIS);
2073
2066
zval *zoptions;
2074
2067
2075
2068
ZEND_PARSE_PARAMETERS_START (1 , 1 )
@@ -2082,13 +2075,13 @@ static PHP_METHOD(swoole_redis_coro, setOptions) {
2082
2075
}
2083
2076
2084
2077
static PHP_METHOD (swoole_redis_coro, getDefer) {
2085
- swRedisClient *redis = php_swoole_get_redis_client (ZEND_THIS);
2078
+ RedisClient *redis = php_swoole_get_redis_client (ZEND_THIS);
2086
2079
2087
2080
RETURN_BOOL (redis->defer );
2088
2081
}
2089
2082
2090
2083
static PHP_METHOD (swoole_redis_coro, setDefer) {
2091
- swRedisClient *redis = php_swoole_get_redis_client (ZEND_THIS);
2084
+ RedisClient *redis = php_swoole_get_redis_client (ZEND_THIS);
2092
2085
zend_bool defer = 1 ;
2093
2086
2094
2087
if (redis->session .subscribe ) {
@@ -2165,7 +2158,7 @@ static PHP_METHOD(swoole_redis_coro, recv) {
2165
2158
}
2166
2159
2167
2160
static PHP_METHOD (swoole_redis_coro, close) {
2168
- swRedisClient *redis = php_swoole_get_redis_client (ZEND_THIS);
2161
+ RedisClient *redis = php_swoole_get_redis_client (ZEND_THIS);
2169
2162
RETURN_BOOL (swoole_redis_coro_close (redis));
2170
2163
}
2171
2164
@@ -3890,6 +3883,11 @@ static PHP_METHOD(swoole_redis_coro, hMGet) {
3890
3883
3891
3884
static PHP_METHOD (swoole_redis_coro, hExists) {
3892
3885
sw_redis_command_key_str (INTERNAL_FUNCTION_PARAM_PASSTHRU, ZEND_STRL (" HEXISTS" ));
3886
+
3887
+ RedisClient *redis = php_swoole_get_redis_client (ZEND_THIS);
3888
+ if (redis->compatibility_mode && ZVAL_IS_LONG (return_value)) {
3889
+ RETURN_BOOL (zval_get_long (return_value) );
3890
+ }
3893
3891
}
3894
3892
3895
3893
static PHP_METHOD (swoole_redis_coro, publish) {
@@ -4406,7 +4404,7 @@ static PHP_METHOD(swoole_redis_coro, script) {
4406
4404
}
4407
4405
}
4408
4406
4409
- static void swoole_redis_coro_parse_result (swRedisClient *redis, zval *return_value, redisReply *reply) {
4407
+ static void swoole_redis_coro_parse_result (RedisClient *redis, zval *return_value, redisReply *reply) {
4410
4408
int j;
4411
4409
zval _val, *val = &_val;
4412
4410
0 commit comments