Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/phpredis/phpredis.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPavlo Yatsukhnenko <yatsukhnenko@gmail.com>2019-12-18 15:00:45 +0300
committerMichael Grunder <michael.grunder@gmail.com>2020-02-07 01:14:46 +0300
commitc94e28f1ebabdfceb722ad78eff75ce4fc57f5a3 (patch)
tree39ff8750ed2cf4d1930f98979681a674e90b1e21 /sentinel_library.c
parentb1724b84828eac58c4d3e29b190bd49dc55c209a (diff)
Add RedisSentinel class and tests
Diffstat (limited to 'sentinel_library.c')
-rw-r--r--sentinel_library.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/sentinel_library.c b/sentinel_library.c
new file mode 100644
index 00000000..bff5725c
--- /dev/null
+++ b/sentinel_library.c
@@ -0,0 +1,62 @@
+#include "sentinel_library.h"
+
+static zend_object_handlers redis_sentinel_object_handlers;
+
+static void
+free_redis_sentinel_object(zend_object *object)
+{
+ redis_sentinel_object *obj = (redis_sentinel_object *)((char *)(object) - XtOffsetOf(redis_sentinel_object, std));
+
+ if (obj->sock) {
+ redis_sock_disconnect(obj->sock, 0);
+ redis_free_socket(obj->sock);
+ }
+ zend_object_std_dtor(&obj->std);
+}
+
+zend_object *
+create_sentinel_object(zend_class_entry *ce)
+{
+ redis_sentinel_object *obj = ecalloc(1, sizeof(*obj) + zend_object_properties_size(ce));
+
+ zend_object_std_init(&obj->std, ce);
+ object_properties_init(&obj->std, ce);
+
+ memcpy(&redis_sentinel_object_handlers, zend_get_std_object_handlers(), sizeof(redis_sentinel_object_handlers));
+ redis_sentinel_object_handlers.offset = XtOffsetOf(redis_sentinel_object, std);
+ redis_sentinel_object_handlers.free_obj = free_redis_sentinel_object;
+ obj->std.handlers = &redis_sentinel_object_handlers;
+
+ return &obj->std;
+}
+
+PHP_REDIS_API void
+sentinel_mbulk_reply_zipped_assoc(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, zval *z_tab, void *ctx)
+{
+ char inbuf[4096];
+ int i, nelem;
+ size_t len;
+ zval z_ret;
+
+ /* Throws exception on failure */
+ if (redis_sock_gets(redis_sock, inbuf, sizeof(inbuf) - 1, &len) < 0) {
+ RETURN_FALSE;
+ }
+
+ if (*inbuf != TYPE_MULTIBULK) {
+ if (*inbuf == TYPE_ERR) {
+ redis_sock_set_err(redis_sock, inbuf + 1, len - 1);
+ }
+ RETURN_FALSE;
+ }
+ array_init(&z_ret);
+ nelem = atoi(inbuf + 1);
+ for (i = 0; i < nelem; ++i) {
+ /* redis_mbulk_reply_zipped_raw calls redis_mbulk_reply_zipped
+ * which puts result into return_value via RETVAL_ZVAL */
+ array_init(return_value);
+ redis_mbulk_reply_zipped_raw(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, z_tab, ctx);
+ add_next_index_zval(&z_ret, return_value);
+ }
+ RETURN_ZVAL(&z_ret, 0, 1);
+}