1 #ifndef REDIS_COMMANDS_H 2 #define REDIS_COMMANDS_H 3 4 #include "common.h" 5 #include "library.h" 6 #include "cluster_library.h" 7 8 /* Pick a random slot, any slot (for stuff like publish/subscribe) */ 9 #define CMD_RAND_SLOT(slot) \ 10 if(slot) *slot = rand() % REDIS_CLUSTER_MOD 11 12 /* Macro for setting the slot if we've been asked to */ 13 #define CMD_SET_SLOT(slot,key,key_len) \ 14 if (slot) *slot = cluster_hash_key(key,key_len); 15 16 /* Simple container so we can push subscribe context out */ 17 typedef struct subscribeContext { 18 char *kw; 19 int argc; 20 zend_fcall_info cb; 21 zend_fcall_info_cache cb_cache; 22 } subscribeContext; 23 24 /* Construct a raw command */ 25 int redis_build_raw_cmd(zval *z_args, int argc, char **cmd, int *cmd_len); 26 27 /* Construct a script command */ 28 smart_string *redis_build_script_cmd(smart_string *cmd, int argc, zval *z_args); 29 30 char *redis_variadic_str_cmd(char *kw, zval *argv, int argc, int *cmd_len); 31 32 /* Redis command generics. Many commands share common prototypes meaning that 33 * we can write one function to handle all of them. For example, there are 34 * many COMMAND key value commands, or COMMAND key commands. */ 35 36 int redis_empty_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 37 char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); 38 39 int redis_opt_str_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, char *kw, 40 char **cmd, int *cmd_len, short *slot, void **ctx); 41 42 int redis_str_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 43 char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); 44 45 int redis_key_long_val_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 46 char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); 47 48 int redis_key_long_str_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 49 char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); 50 51 int redis_kv_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 52 char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); 53 54 int redis_key_str_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 55 char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); 56 57 int redis_key_key_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 58 char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); 59 60 int redis_key_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 61 char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); 62 63 int redis_key_long_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 64 char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); 65 66 int redis_long_long_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 67 char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); 68 69 int redis_key_long_long_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 70 char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); 71 72 int redis_key_str_str_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 73 char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); 74 75 int redis_key_dbl_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 76 char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); 77 78 int redis_key_varval_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 79 char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); 80 81 int redis_key_val_arr_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 82 char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); 83 84 int redis_key_str_arr_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 85 char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); 86 87 int redis_blocking_pop_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 88 char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); 89 90 /* Construct SCAN and similar commands, as well as check iterator */ 91 int redis_scan_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 92 REDIS_SCAN_TYPE type, char **cmd, int *cmd_len); 93 94 /* ZRANGE, ZREVRANGE, ZRANGEBYSCORE, and ZREVRANGEBYSCORE callback type */ 95 typedef int (*zrange_cb)(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 96 char *,char**,int*,int*,short*,void**); 97 98 int redis_zrange_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 99 char *kw, char **cmd, int *cmd_len, int *withscores, short *slot, 100 void **ctx); 101 102 int redis_zrangebyscore_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 103 char *kw, char **cmd, int *cmd_len, int *withscores, short *slot, 104 void **ctx); 105 106 int redis_zinter_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 107 char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); 108 109 int redis_subscribe_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 110 char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); 111 112 int redis_unsubscribe_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 113 char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); 114 115 int redis_zrangebylex_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 116 char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); 117 118 int redis_gen_zlex_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 119 char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); 120 121 int redis_eval_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 122 char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); 123 124 int redis_flush_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 125 char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); 126 127 int redis_xrange_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 128 char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); 129 130 int redis_georadius_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 131 char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); 132 133 int redis_georadiusbymember_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 134 char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); 135 136 /* Commands which need a unique construction mechanism. This is either because 137 * they don't share a signature with any other command, or because there is 138 * specific processing we do (e.g. verifying subarguments) that make them 139 * unique */ 140 141 int redis_set_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 142 char **cmd, int *cmd_len, short *slot, void **ctx); 143 144 int redis_brpoplpush_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 145 char **cmd, int *cmd_len, short *slot, void **ctx); 146 147 int redis_incr_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 148 char **cmd, int *cmd_len, short *slot, void **ctx); 149 150 int redis_decr_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 151 char **cmd, int *cmd_len, short *slot, void **ctx); 152 153 int redis_hincrby_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 154 char **cmd, int *cmd_len, short *slot, void **ctx); 155 156 int redis_hincrbyfloat_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 157 char **cmd, int *cmd_len, short *slot, void **ctx); 158 159 int redis_hmget_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 160 char **cmd, int *cmd_len, short *slot, void **ctx); 161 162 int redis_hmset_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 163 char **cmd, int *cmd_len, short *slot, void **ctx); 164 165 int redis_hstrlen_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 166 char **cmd, int *cmd_len, short *slot, void **ctx); 167 168 int redis_bitop_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 169 char **cmd, int *cmd_len, short *slot, void **ctx); 170 171 int redis_bitcount_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 172 char **cmd, int *cmd_len, short *slot, void **ctx); 173 174 int redis_bitpos_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 175 char **cmd, int *cmd_len, short *slot, void **ctx); 176 177 int redis_pfcount_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 178 char **cmd, int *cmd_len, short *slot, void **ctx); 179 180 int redis_pfadd_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 181 char **cmd, int *cmd_len, short *slot, void **ctx); 182 183 int redis_pfmerge_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 184 char **cmd, int *cmd_len, short *slot, void **ctx); 185 186 int redis_auth_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 187 char **cmd, int *cmd_len, short *slot, void **ctx); 188 189 int redis_setbit_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 190 char **cmd, int *cmd_len, short *slot, void **ctx); 191 192 int redis_linsert_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 193 char **cmd, int *cmd_len, short *slot, void **ctx); 194 195 int redis_lrem_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 196 char **cmd, int *cmd_len, short *slot, void **ctx); 197 198 int redis_smove_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 199 char **cmd, int *cmd_len, short *slot, void **ctx); 200 201 int redis_hset_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 202 char **cmd, int *cmd_len, short *slot, void **ctx); 203 204 int redis_hsetnx_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 205 char **cmd, int *cmd_len, short *slot, void **ctx); 206 207 int redis_srandmember_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 208 char **cmd, int *cmd_len, short *slot, void **ctx, short *have_count); 209 210 int redis_zincrby_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 211 char **cmd, int *cmd_len, short *slot, void **ctx); 212 213 int redis_sort_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 214 int *using_store, char **cmd, int *cmd_len, short *slot, void **ctx); 215 216 int redis_hdel_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 217 char **cmd, int *cmd_len, short *slot, void **ctx); 218 219 int redis_zadd_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 220 char **cmd, int *cmd_len, short *slot, void **ctx); 221 222 int redis_object_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 223 REDIS_REPLY_TYPE *rtype, char **cmd, int *cmd_len, short *slot, 224 void **ctx); 225 226 int redis_exists_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 227 char **cmd, int *cmd_len, short *slot, void **ctx); 228 229 int redis_del_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 230 char **cmd, int *cmd_len, short *slot, void **ctx); 231 232 int redis_unlink_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 233 char **cmd, int *cmd_len, short *slot, void **ctx); 234 235 int redis_watch_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 236 char **cmd, int *cmd_len, short *slot, void **ctx); 237 238 int redis_sinter_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 239 char **cmd, int *cmd_len, short *slot, void **ctx); 240 241 int redis_sinterstore_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 242 char **cmd, int *cmd_len, short *slot, void **ctx); 243 244 int redis_sunion_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 245 char **cmd, int *cmd_len, short *slot, void **ctx); 246 247 int redis_sunionstore_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 248 char **cmd, int *cmd_len, short *slot, void **ctx); 249 250 int redis_sdiff_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 251 char **cmd, int *cmd_len, short *slot, void **ctx); 252 253 int redis_sdiffstore_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 254 char **cmd, int *cmd_len, short *slot, void **ctx); 255 256 int redis_command_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 257 char **cmd, int *cmd_len, short *slot, void **ctx); 258 259 int redis_fmt_scan_cmd(char **cmd, REDIS_SCAN_TYPE type, char *key, int key_len, 260 long it, char *pat, int pat_len, long count); 261 262 int redis_geodist_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 263 char **cmd, int *cmd_len, short *slot, void **ctx); 264 265 int redis_migrate_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 266 char **cmd, int *cmd_len, short *slot, void **ctx); 267 268 int redis_xadd_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 269 char **cmd, int *cmd_len, short *slot, void **ctx); 270 271 int redis_xclaim_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 272 char **cmd, int *cmd_len, short *slot, void **ctx); 273 274 int redis_xpending_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 275 char **cmd, int *cmd_len, short *slot, void **ctx); 276 277 int redis_xack_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 278 char **cmd, int *cmd_len, short *slot, void **ctx); 279 280 int redis_xgroup_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 281 char **cmd, int *cmd_len, short *slot, void **ctx); 282 283 int redis_xinfo_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 284 char **cmd, int *cmd_len, short *slot, void **ctx); 285 286 int redis_xread_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 287 char **cmd, int *cmd_len, short *slot, void **ctx); 288 289 int redis_xreadgroup_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 290 char **cmd, int *cmd_len, short *slot, void **ctx); 291 292 int redis_xtrim_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 293 char **cmd, int *cmd_len, short *slot, void **ctx); 294 295 int redis_sentinel_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 296 char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); 297 298 int redis_sentinel_str_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, 299 char *kw, char **cmd, int *cmd_len, short *slot, void **ctx); 300 301 /* Commands that don't communicate with Redis at all (such as getOption, 302 * setOption, _prefix, _serialize, etc). These can be handled in one place 303 * with the method of grabbing our RedisSock* object in different ways 304 * depending if this is a Redis object or a RedisCluster object. */ 305 306 void redis_getoption_handler(INTERNAL_FUNCTION_PARAMETERS, 307 RedisSock *redis_sock, redisCluster *c); 308 void redis_setoption_handler(INTERNAL_FUNCTION_PARAMETERS, 309 RedisSock *redis_sock, redisCluster *c); 310 void redis_prefix_handler(INTERNAL_FUNCTION_PARAMETERS, 311 RedisSock *redis_sock); 312 void redis_serialize_handler(INTERNAL_FUNCTION_PARAMETERS, 313 RedisSock *redis_sock); 314 void redis_unserialize_handler(INTERNAL_FUNCTION_PARAMETERS, 315 RedisSock *redis_sock, zend_class_entry *ex); 316 void redis_compress_handler(INTERNAL_FUNCTION_PARAMETERS, 317 RedisSock *redis_sock); 318 void redis_uncompress_handler(INTERNAL_FUNCTION_PARAMETERS, 319 RedisSock *redis_sock, zend_class_entry *ex); 320 321 void redis_pack_handler(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock); 322 void redis_unpack_handler(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock); 323 324 #endif 325 326 /* vim: set tabstop=4 softtabstop=4 expandtab shiftwidth=4: */ 327