|
24 | 24 | #include "SAPI.h"
|
25 | 25 | #include "ext/standard/url.h"
|
26 | 26 | #include "ext/standard/crc32.h"
|
| 27 | +#include "zend_interfaces.h" |
27 | 28 |
|
28 | 29 | #define PHPREDIS_INDEX_NAME "__phpredis_array_index__"
|
29 | 30 |
|
@@ -970,6 +971,40 @@ ra_move_string(const char *key, int key_len, zval *z_from, zval *z_to, long ttl
|
970 | 971 | return 1;
|
971 | 972 | }
|
972 | 973 |
|
| 974 | +#if (PHP_MAJOR_VERSION < 7) |
| 975 | + |
| 976 | +static zend_bool |
| 977 | +ra_move_hash(const char *key, int key_len, zval *z_from, zval *z_to, long ttl TSRMLS_DC) { |
| 978 | + zval *z_ret, *z_arg1; |
| 979 | + |
| 980 | + /* Call HMGET on the source host */ |
| 981 | + MAKE_STD_ZVAL(z_arg1); |
| 982 | + ZVAL_STRINGL(z_arg1, key, key_len); |
| 983 | + zend_call_method_with_1_params(&z_from, redis_ce, NULL, "hgetall", &z_ret, z_arg1); |
| 984 | + |
| 985 | + /* Abort if we don't get a proper response */ |
| 986 | + if (!z_ret || Z_TYPE_P(z_ret) != IS_ARRAY) { |
| 987 | + if (z_ret) zval_ptr_dtor(&z_ret); |
| 988 | + zval_ptr_dtor(&z_arg1); |
| 989 | + return 0; |
| 990 | + } |
| 991 | + |
| 992 | + /* Now run HMSET on destination host with the results of our HGETALL call */ |
| 993 | + zend_call_method_with_2_params(&z_to, redis_ce, NULL, "hmset", NULL, z_arg1, z_ret); |
| 994 | + |
| 995 | + /* Expire key if needed */ |
| 996 | + ra_expire_key(key, key_len, z_to, ttl TSRMLS_CC); |
| 997 | + |
| 998 | + /* cleanup */ |
| 999 | + zval_ptr_dtor(&z_ret); |
| 1000 | + zval_ptr_dtor(&z_arg1); |
| 1001 | + zval_ptr_dtor(&z_ret); |
| 1002 | + |
| 1003 | + return 1; |
| 1004 | +} |
| 1005 | + |
| 1006 | +#else |
| 1007 | + |
973 | 1008 | static zend_bool
|
974 | 1009 | ra_move_hash(const char *key, int key_len, zval *z_from, zval *z_to, long ttl TSRMLS_DC) {
|
975 | 1010 | zval z_fun_hgetall, z_fun_hmset, z_ret_dest, z_args[2];
|
@@ -1003,6 +1038,8 @@ ra_move_hash(const char *key, int key_len, zval *z_from, zval *z_to, long ttl TS
|
1003 | 1038 | return 1;
|
1004 | 1039 | }
|
1005 | 1040 |
|
| 1041 | +#endif |
| 1042 | + |
1006 | 1043 | static zend_bool
|
1007 | 1044 | ra_move_collection(const char *key, int key_len, zval *z_from, zval *z_to,
|
1008 | 1045 | int list_count, const char **cmd_list, int add_count,
|
@@ -1139,30 +1176,41 @@ ra_move_key(const char *key, int key_len, zval *z_from, zval *z_to TSRMLS_DC)
|
1139 | 1176 | static void zval_rehash_callback(zend_fcall_info *z_cb, zend_fcall_info_cache *z_cb_cache,
|
1140 | 1177 | const char *hostname, long count, zval *z_ret TSRMLS_DC)
|
1141 | 1178 | {
|
| 1179 | +#if (PHP_MAJOR_VERSION < 7) |
| 1180 | + zval *z_args[2]; |
1142 | 1181 |
|
1143 |
| - zval z_args[2]; |
| 1182 | + MAKE_STD_ZVAL(z_args[0]); |
| 1183 | + MAKE_STD_ZVAL(z_args[1]); |
| 1184 | + ZVAL_STRINGL(z_args[0], hostname, 0); |
| 1185 | + ZVAL_LONG(z_args[1], count); |
1144 | 1186 |
|
1145 |
| - ZVAL_STRING(&z_args[0], hostname); |
1146 |
| - ZVAL_LONG(&z_args[1], count); |
| 1187 | + zval **z_args_pp[2] = { &z_args[0], &z_args[1] }; |
1147 | 1188 |
|
1148 |
| -#if (PHP_MAJOR_VERSION < 7) |
1149 |
| - zval *z_host = &z_args[0], *z_count = &z_args[1], **z_args_pp[2] = { &z_host, &z_count }; |
1150 | 1189 | z_cb->params = z_args_pp;
|
1151 | 1190 | z_cb->retval_ptr_ptr = &z_ret;
|
1152 | 1191 | #else
|
| 1192 | + zval z_args[2]; |
| 1193 | + |
| 1194 | + ZVAL_STRING(&z_args[0], hostname); |
| 1195 | + ZVAL_LONG(&z_args[1], count); |
| 1196 | + |
1153 | 1197 | z_cb->params = z_args;
|
1154 | 1198 | z_cb->retval = z_ret;
|
1155 | 1199 | #endif
|
| 1200 | + |
1156 | 1201 | z_cb->param_count = 2;
|
1157 | 1202 | z_cb->no_separation = 0;
|
1158 | 1203 |
|
1159 | 1204 | /* run cb(hostname, count) */
|
1160 | 1205 | zend_call_function(z_cb, z_cb_cache TSRMLS_CC);
|
1161 | 1206 |
|
1162 | 1207 | /* cleanup */
|
1163 |
| - zval_dtor(&z_args[0]); |
1164 | 1208 | #if (PHP_MAJOR_VERSION < 7)
|
| 1209 | + zval_ptr_dtor(&z_args[0]); |
| 1210 | + zval_ptr_dtor(&z_args[1]); |
1165 | 1211 | zval_ptr_dtor(&z_ret);
|
| 1212 | +#else |
| 1213 | + zval_dtor(&z_args[0]); |
1166 | 1214 | #endif
|
1167 | 1215 | }
|
1168 | 1216 |
|
|
0 commit comments