|
| 1 | +#include "php_redis.h" |
| 2 | +#include "redis_commands.h" |
| 3 | +#include "redis_sentinel.h" |
| 4 | + |
| 5 | +zend_class_entry *redis_sentinel_ce; |
| 6 | + |
| 7 | +ZEND_BEGIN_ARG_INFO_EX(arginfo_ctor, 0, 0, 1) |
| 8 | + ZEND_ARG_INFO(0, host) |
| 9 | + ZEND_ARG_INFO(0, port) |
| 10 | +ZEND_END_ARG_INFO() |
| 11 | + |
| 12 | +zend_function_entry redis_sentinel_functions[] = { |
| 13 | + PHP_ME(RedisSentinel, __construct, arginfo_ctor, ZEND_ACC_PUBLIC) |
| 14 | + PHP_ME(RedisSentinel, ckquorum, arginfo_value, ZEND_ACC_PUBLIC) |
| 15 | + PHP_ME(RedisSentinel, failover, arginfo_value, ZEND_ACC_PUBLIC) |
| 16 | + PHP_ME(RedisSentinel, flushconfig, arginfo_void, ZEND_ACC_PUBLIC) |
| 17 | + PHP_ME(RedisSentinel, getMasterAddrByName, arginfo_value, ZEND_ACC_PUBLIC) |
| 18 | + PHP_ME(RedisSentinel, master, arginfo_value, ZEND_ACC_PUBLIC) |
| 19 | + PHP_ME(RedisSentinel, masters, arginfo_void, ZEND_ACC_PUBLIC) |
| 20 | + PHP_ME(RedisSentinel, ping, arginfo_void, ZEND_ACC_PUBLIC) |
| 21 | + PHP_ME(RedisSentinel, reset, arginfo_value, ZEND_ACC_PUBLIC) |
| 22 | + PHP_ME(RedisSentinel, sentinels, arginfo_value, ZEND_ACC_PUBLIC) |
| 23 | + PHP_ME(RedisSentinel, slaves, arginfo_value, ZEND_ACC_PUBLIC) |
| 24 | + PHP_FE_END |
| 25 | +}; |
| 26 | + |
| 27 | +PHP_METHOD(RedisSentinel, __construct) |
| 28 | +{ |
| 29 | + redis_sentinel_object *obj; |
| 30 | + zend_long port = -1; |
| 31 | + zend_string *host; |
| 32 | + |
| 33 | + if (zend_parse_parameters(ZEND_NUM_ARGS(), "S|l", &host, &port) == FAILURE) { |
| 34 | + RETURN_FALSE; |
| 35 | + } |
| 36 | + |
| 37 | + /* If it's not a unix socket, set to default */ |
| 38 | + if (port < 0 && ZSTR_LEN(host) > 0 && *ZSTR_VAL(host) != '/') { |
| 39 | + port = 26379; |
| 40 | + } |
| 41 | + |
| 42 | + obj = PHPREDIS_GET_OBJECT(redis_sentinel_object, getThis()); |
| 43 | + obj->sock = redis_sock_create(ZSTR_VAL(host), ZSTR_LEN(host), port, 0, 0, 0, NULL, 0); |
| 44 | +} |
| 45 | + |
| 46 | +PHP_METHOD(RedisSentinel, ckquorum) |
| 47 | +{ |
| 48 | + REDIS_PROCESS_KW_CMD("ckquorum", redis_sentinel_str_cmd, redis_boolean_response); |
| 49 | +} |
| 50 | + |
| 51 | +PHP_METHOD(RedisSentinel, failover) |
| 52 | +{ |
| 53 | + REDIS_PROCESS_KW_CMD("failover", redis_sentinel_str_cmd, redis_boolean_response); |
| 54 | +} |
| 55 | + |
| 56 | +PHP_METHOD(RedisSentinel, flushconfig) |
| 57 | +{ |
| 58 | + REDIS_PROCESS_KW_CMD("flushconfig", redis_sentinel_cmd, redis_boolean_response); |
| 59 | +} |
| 60 | + |
| 61 | +PHP_METHOD(RedisSentinel, getMasterAddrByName) |
| 62 | +{ |
| 63 | + REDIS_PROCESS_KW_CMD("get-master-addr-by-name", redis_sentinel_str_cmd, redis_mbulk_reply_raw); |
| 64 | +} |
| 65 | + |
| 66 | +PHP_METHOD(RedisSentinel, master) |
| 67 | +{ |
| 68 | + REDIS_PROCESS_KW_CMD("master", redis_sentinel_str_cmd, redis_mbulk_reply_zipped_raw); |
| 69 | +} |
| 70 | + |
| 71 | +PHP_METHOD(RedisSentinel, masters) |
| 72 | +{ |
| 73 | + REDIS_PROCESS_KW_CMD("masters", redis_sentinel_cmd, sentinel_mbulk_reply_zipped_assoc); |
| 74 | +} |
| 75 | + |
| 76 | +PHP_METHOD(RedisSentinel, ping) |
| 77 | +{ |
| 78 | + REDIS_PROCESS_KW_CMD("PING", redis_empty_cmd, redis_boolean_response); |
| 79 | +} |
| 80 | + |
| 81 | +PHP_METHOD(RedisSentinel, reset) |
| 82 | +{ |
| 83 | + REDIS_PROCESS_KW_CMD("reset", redis_sentinel_str_cmd, redis_boolean_response); |
| 84 | +} |
| 85 | + |
| 86 | +PHP_METHOD(RedisSentinel, sentinels) |
| 87 | +{ |
| 88 | + REDIS_PROCESS_KW_CMD("sentinels", redis_sentinel_str_cmd, sentinel_mbulk_reply_zipped_assoc); |
| 89 | +} |
| 90 | + |
| 91 | +PHP_METHOD(RedisSentinel, slaves) |
| 92 | +{ |
| 93 | + REDIS_PROCESS_KW_CMD("slaves", redis_sentinel_str_cmd, sentinel_mbulk_reply_zipped_assoc); |
| 94 | +} |
0 commit comments