Skip to content

Updates from edtechd branch #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 27 commits into
base: php7
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
355a6aa
fix redis_globals, make shared at snaphot build
Jan-E Jul 4, 2015
5055603
Merge pull request #1 from Jan-E/php7
edtechd Jul 4, 2015
fd425df
fix missing _basic_globals / _basic_globals_id
Jan-E Jul 4, 2015
1699603
Merge pull request #2 from Jan-E/php7
edtechd Jul 4, 2015
7c649a6
other fix _basic_globals / _basic_globals_d
Jan-E Jul 5, 2015
16554bb
remove previous fix _basic_globals / _basic_globals_d
Jan-E Jul 5, 2015
bc1c028
Merge pull request #3 from Jan-E/php7
edtechd Jul 5, 2015
a3a1ff0
Changed type for length variables to size_t, improved handling of NUL…
edtechd Jul 5, 2015
2b2a52f
Should be long long on Debian
Jan-E Jul 6, 2015
be8ac4d
Change in library.h as well
Jan-E Jul 6, 2015
57c2e7d
fix incompatible types
Jan-E Jul 6, 2015
7e0c91d
fix more incompatible types
Jan-E Jul 6, 2015
da30ced
fix more incompatible types
Jan-E Jul 6, 2015
fdfe559
fix makes pointer from integer without a cast
Jan-E Jul 6, 2015
caec901
Merge pull request #4 from Jan-E/php7
edtechd Jul 6, 2015
c84ef79
Fixed incorrect types
edtechd Jul 9, 2015
cf85243
Fixed zend_mm_head_corrupted error, but there are memory leaks (TODO:…
edtechd Jul 9, 2015
bf99c94
Fixed incompatible types
edtechd Jul 10, 2015
6bdd92e
Fixed #6 Segfaults in eval() and evalSha() functions
edtechd Jul 15, 2015
2f8d21c
Fixed #8 memory management improved
edtechd Jul 15, 2015
babc77e
Fixed vim mode command
laruence Aug 6, 2015
8aa2a5a
remove version checking
laruence Aug 6, 2015
83764e9
remove TSRMLS_XX
laruence Aug 6, 2015
6df04e1
Fixed warnings
laruence Aug 6, 2015
8e0d51b
That was a big change :< (not complete yet)
laruence Aug 6, 2015
c218328
Another big change (the previously implementation is really mess! :< …
laruence Aug 7, 2015
c3e443b
Merge pull request #11 from laruence/php7
edtechd Aug 7, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
975 changes: 441 additions & 534 deletions cluster_library.c

Large diffs are not rendered by default.

63 changes: 30 additions & 33 deletions cluster_library.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
#define CLUSTER_LAZY_CONNECT(s) \
if(s->lazy_connect) { \
s->lazy_connect = 0; \
redis_sock_server_open(s, 1 TSRMLS_CC); \
redis_sock_server_open(s, 1); \
}

/* Clear out our "last error" */
Expand All @@ -69,12 +69,12 @@

/* Protected sending of data down the wire to a RedisSock->stream */
#define CLUSTER_SEND_PAYLOAD(sock, buf, len) \
(sock && sock->stream && !redis_check_eof(sock, 1 TSRMLS_CC) && \
(sock && sock->stream && !redis_check_eof(sock, 1) && \
php_stream_write(sock->stream, buf, len)==len)

/* Macro to read our reply type character */
#define CLUSTER_VALIDATE_REPLY_TYPE(sock, type) \
(redis_check_eof(sock, 1 TSRMLS_CC) == 0 && \
(redis_check_eof(sock, 1) == 0 && \
(php_stream_getc(sock->stream) == type))

/* Reset our last single line reply buffer and length */
Expand Down Expand Up @@ -148,10 +148,10 @@ typedef enum CLUSTER_REDIR_TYPE {
} CLUSTER_REDIR_TYPE;

/* MULTI BULK response callback typedef */
typedef int (*mbulk_cb)(RedisSock*,zval*,long long, void* TSRMLS_DC);
typedef int (*mbulk_cb)(RedisSock*,zval*,long long, void*);

/* Specific destructor to free a cluster object */
// void redis_destructor_redis_cluster(zend_rsrc_list_entry *rsrc TSRMLS_DC);
// void redis_destructor_redis_cluster(zend_rsrc_list_entry *rsrc);

/* A Redis Cluster master node */
typedef struct redisClusterNode {
Expand All @@ -173,9 +173,6 @@ typedef struct clusterFoldItem clusterFoldItem;

/* RedisCluster implementation structure */
typedef struct redisCluster {
/* Object reference for Zend */
zend_object std;

/* Timeout and read timeout (for normal operations) */
double timeout;
double read_timeout;
Expand Down Expand Up @@ -241,6 +238,9 @@ typedef struct redisCluster {
int redir_host_len;
unsigned short redir_slot;
unsigned short redir_port;

/* Object reference for Zend */
zend_object std;
} redisCluster;

/* RedisCluster response processing callback */
Expand All @@ -263,9 +263,8 @@ struct clusterFoldItem {

/* Key and value container, with info if they need freeing */
typedef struct clusterKeyVal {
char *key, *val;
int key_len, val_len;
int key_free, val_free;
zend_string *key;
zend_string *val;
} clusterKeyVal;

/* Container to hold keys (and possibly values) for when we need to distribute
Expand All @@ -280,7 +279,7 @@ typedef struct clusterDistList {
* command execution, in which we'll want to return the value (or add it) */
typedef struct clusterMultiCtx {
/* Our running array */
zval *z_multi;
zval z_multi;

/* How many keys did we request for this bit */
int count;
Expand Down Expand Up @@ -317,18 +316,16 @@ typedef struct clusterReply {
} clusterReply;

/* Direct variant response handler */
clusterReply *cluster_read_resp(redisCluster *c TSRMLS_DC);
clusterReply *cluster_read_resp(redisCluster *c);
clusterReply *cluster_read_sock_resp(RedisSock *redis_sock,
REDIS_REPLY_TYPE type, size_t reply_len TSRMLS_DC);
REDIS_REPLY_TYPE type, size_t reply_len);
void cluster_free_reply(clusterReply *reply, int free_data);

/* Cluster distribution helpers for WATCH */
HashTable *cluster_dist_create();
void cluster_dist_free(HashTable *ht);
int cluster_dist_add_key(redisCluster *c, HashTable *ht, char *key,
int key_len, clusterKeyVal **kv);
void cluster_dist_add_val(redisCluster *c, clusterKeyVal *kv, zval *val
TSRMLS_DC);
int cluster_dist_add_key(redisCluster *c, HashTable *ht, zend_string *key, clusterKeyVal **kv);
void cluster_dist_add_val(redisCluster *c, clusterKeyVal *kv, zval *val );

/* Aggregation for multi commands like MGET, MSET, and MSETNX */
void cluster_multi_init(clusterMultiCmd *mc, char *kw, int kw_len);
Expand All @@ -344,26 +341,26 @@ unsigned short cluster_hash_key(const char *key, int len);
long long mstime(void);

PHP_REDIS_API short cluster_send_command(redisCluster *c, short slot, const char *cmd,
int cmd_len TSRMLS_DC);
int cmd_len);

PHP_REDIS_API void cluster_disconnect(redisCluster *c TSRMLS_DC);
PHP_REDIS_API void cluster_disconnect(redisCluster *c);

PHP_REDIS_API int cluster_send_exec(redisCluster *c, short slot TSRMLS_DC);
PHP_REDIS_API int cluster_send_discard(redisCluster *c, short slot TSRMLS_DC);
PHP_REDIS_API int cluster_abort_exec(redisCluster *c TSRMLS_DC);
PHP_REDIS_API int cluster_send_exec(redisCluster *c, short slot);
PHP_REDIS_API int cluster_send_discard(redisCluster *c, short slot);
PHP_REDIS_API int cluster_abort_exec(redisCluster *c);
PHP_REDIS_API int cluster_reset_multi(redisCluster *c);

PHP_REDIS_API short cluster_find_slot(redisCluster *c, const char *host,
unsigned short port);
PHP_REDIS_API int cluster_send_slot(redisCluster *c, short slot, char *cmd,
int cmd_len, REDIS_REPLY_TYPE rtype TSRMLS_DC);
int cmd_len, REDIS_REPLY_TYPE rtype);

PHP_REDIS_API int cluster_init_seeds(redisCluster *c, HashTable *ht_seeds);
PHP_REDIS_API int cluster_map_keyspace(redisCluster *c TSRMLS_DC);
PHP_REDIS_API int cluster_map_keyspace(redisCluster *c);
PHP_REDIS_API void cluster_free_node(redisClusterNode *node);

PHP_REDIS_API char **cluster_sock_read_multibulk_reply(RedisSock *redis_sock,
int *len TSRMLS_DC);
int *len);

/*
* Redis Cluster response handlers. Our response handlers generally take the
Expand Down Expand Up @@ -416,7 +413,7 @@ PHP_REDIS_API void cluster_mbulk_assoc_resp(INTERNAL_FUNCTION_PARAMETERS,
PHP_REDIS_API void cluster_multi_mbulk_resp(INTERNAL_FUNCTION_PARAMETERS,
redisCluster *c, void *ctx);
PHP_REDIS_API zval *cluster_zval_mbulk_resp(INTERNAL_FUNCTION_PARAMETERS,
redisCluster *c, int pull, mbulk_cb cb);
redisCluster *c, int pull, mbulk_cb cb, zval *rv);

/* Handlers for things like DEL/MGET/MSET/MSETNX */
PHP_REDIS_API void cluster_del_resp(INTERNAL_FUNCTION_PARAMETERS,
Expand All @@ -442,16 +439,16 @@ PHP_REDIS_API void cluster_client_list_resp(INTERNAL_FUNCTION_PARAMETERS,

/* MULTI BULK processing callbacks */
int mbulk_resp_loop(RedisSock *redis_sock, zval *z_result,
long long count, void *ctx TSRMLS_DC);
long long count, void *ctx);
int mbulk_resp_loop_raw(RedisSock *redis_sock, zval *z_result,
long long count, void *ctx TSRMLS_DC);
long long count, void *ctx);
int mbulk_resp_loop_zipstr(RedisSock *redis_sock, zval *z_result,
long long count, void *ctx TSRMLS_DC);
long long count, void *ctx);
int mbulk_resp_loop_zipdbl(RedisSock *redis_sock, zval *z_result,
long long count, void *ctx TSRMLS_DC);
long long count, void *ctx);
int mbulk_resp_loop_assoc(RedisSock *redis_sock, zval *z_result,
long long count, void *ctx TSRMLS_DC);
long long count, void *ctx);

#endif

/* vim: set tabstop=4 softtabstops=4 noexpandtab shiftwidth=4: */
/* vim: set tabstop=4 softtabstop=4 noexpandtab shiftwidth=4: */
7 changes: 0 additions & 7 deletions cluster_library.loT

This file was deleted.

10 changes: 5 additions & 5 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ typedef enum _PUBSUB_TYPE {
#define IF_NOT_ATOMIC() if(redis_sock->mode != ATOMIC)
#define IF_ATOMIC() if(redis_sock->mode == ATOMIC)
#define ELSE_IF_MULTI() else if(redis_sock->mode == MULTI) { \
if(redis_response_enqueued(redis_sock TSRMLS_CC) == 1) { \
if(redis_response_enqueued(redis_sock) == 1) { \
RETURN_ZVAL(getThis(), 1, 0);\
} else { \
RETURN_FALSE; \
Expand Down Expand Up @@ -139,7 +139,7 @@ typedef enum _PUBSUB_TYPE {
}

#define SOCKET_WRITE_COMMAND(redis_sock, cmd, cmd_len) \
if(redis_sock_write(redis_sock, cmd, cmd_len TSRMLS_CC) < 0) { \
if(redis_sock_write(redis_sock, cmd, cmd_len) < 0) { \
efree(cmd); \
RETURN_FALSE; \
}
Expand All @@ -161,7 +161,7 @@ typedef enum _PUBSUB_TYPE {

#define REDIS_ELSE_IF_MULTI(function, closure_context) \
else if(redis_sock->mode == MULTI) { \
if(redis_response_enqueued(redis_sock TSRMLS_CC) == 1) {\
if(redis_response_enqueued(redis_sock) == 1) {\
REDIS_SAVE_CALLBACK(function, closure_context); \
RETURN_ZVAL(getThis(), 1, 0);\
} else {\
Expand Down Expand Up @@ -200,7 +200,7 @@ typedef enum _PUBSUB_TYPE {
* function is redis_<cmdname>_cmd */
#define REDIS_PROCESS_CMD(cmdname, resp_func) \
RedisSock *redis_sock; char *cmd; int cmd_len; void *ctx=NULL; \
if(redis_sock_get(getThis(), &redis_sock TSRMLS_CC, 0)<0 || \
if(redis_sock_get(getThis(), &redis_sock, 0)<0 || \
redis_##cmdname##_cmd(INTERNAL_FUNCTION_PARAM_PASSTHRU,redis_sock, \
&cmd, &cmd_len, NULL, &ctx)==FAILURE) { \
RETURN_FALSE; \
Expand All @@ -215,7 +215,7 @@ typedef enum _PUBSUB_TYPE {
* and keyword which is passed to us*/
#define REDIS_PROCESS_KW_CMD(kw, cmdfunc, resp_func) \
RedisSock *redis_sock; char *cmd; int cmd_len; void *ctx=NULL; \
if(redis_sock_get(getThis(), &redis_sock TSRMLS_CC, 0)<0 || \
if(redis_sock_get(getThis(), &redis_sock, 0)<0 || \
cmdfunc(INTERNAL_FUNCTION_PARAM_PASSTHRU, redis_sock, kw, &cmd, \
&cmd_len, NULL, &ctx)==FAILURE) { \
RETURN_FALSE; \
Expand Down
9 changes: 4 additions & 5 deletions config.w32
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// vim: ft=javascript:

ARG_ENABLE("redis", "whether to enable redis support", "yes");
ARG_ENABLE("redis", "whether to enable redis support", "no");
ARG_ENABLE("redis-session", "whether to enable sessions", "yes");
ARG_ENABLE("redis-igbinary", "whether to enable igbinary serializer support", "no");
ARG_ENABLE("redis-igbinary", "whether to enable igbinary serializer support", "yes");

if (PHP_REDIS != "no") {
EXTENSION("redis", "redis.c library.c redis_commands.c redis_array.c redis_array_impl.c redis_cluster.c cluster_library.c");
var sources = "redis.c library.c redis_commands.c redis_array.c redis_array_impl.c redis_cluster.c cluster_library.c";
AC_DEFINE("HAVE_REDIS", 1);
ADD_FLAG("CFLAGS_REDIS", ' /D PHP_EXPORTS=1 ');

if (PHP_REDIS_SESSION != "no") {
ADD_SOURCES(configure_module_dirname, "redis_session.c", "redis");
Expand All @@ -26,6 +25,6 @@ if (PHP_REDIS != "no") {
}
}


EXTENSION("redis", sources);
}

Loading