Skip to content

Commit

Permalink
Issue #1577
Browse files Browse the repository at this point in the history
Remove checking of version of msgpack.
Allow to disable json serializer.
Fix tests.
  • Loading branch information
yatsukhnenko authored and michael-grunder committed Jun 21, 2019
1 parent 8206b14 commit 235a27e
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 83 deletions.
132 changes: 84 additions & 48 deletions config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ dnl Make sure that the comment is aligned:
PHP_ARG_ENABLE(redis-session, whether to disable sessions,
[ --disable-redis-session Disable session support], yes, no)

PHP_ARG_ENABLE(redis-json, whether to disable json serializer support,
[ --disable-redis-json Disable json serializer support], yes, no)

PHP_ARG_ENABLE(redis-igbinary, whether to enable igbinary serializer support,
[ --enable-redis-igbinary Enable igbinary serializer support], no, no)

Expand All @@ -26,7 +29,46 @@ if test "$PHP_REDIS" != "no"; then
AC_DEFINE(PHP_SESSION,1,[redis sessions])
fi

dnl Check for igbinary
if test "PHP_REDIS_JSON" != "no"; then
AC_MSG_CHECKING([for json includes])
json_inc_path=""
if test -f "$abs_srcdir/include/php/ext/json/php_json.h"; then
json_inc_path="$abs_srcdir/include/php"
elif test -f "$abs_srcdir/ext/json/php_json.h"; then
json_inc_path="$abs_srcdir"
elif test -f "$phpincludedir/ext/json/php_json.h"; then
json_inc_path="$phpincludedir"
else
for i in php php7; do
if test -f "$prefix/include/$i/ext/json/php_json.h"; then
json_inc_path="$prefix/include/$i"
fi
done
fi

if test "$json_inc_path" = ""; then
AC_MSG_ERROR([Cannot find php_json.h])
else
AC_MSG_RESULT([$json_inc_path])
fi
fi

AC_MSG_CHECKING([for redis json support])
if test "$PHP_REDIS_JSON" != "no"; then
AC_MSG_RESULT([enabled])
AC_DEFINE(HAVE_REDIS_JSON,1,[Whether redis json serializer is enabled])
JSON_INCLUDES="-I$json_inc_path"
JSON_EXT_DIR="$json_inc_path/ext"
ifdef([PHP_ADD_EXTENSION_DEP],
[
PHP_ADD_EXTENSION_DEP(redis, json)
])
PHP_ADD_INCLUDE($JSON_EXT_DIR)
else
JSON_INCLUDES=""
AC_MSG_RESULT([disabled])
fi

if test "$PHP_REDIS_IGBINARY" != "no"; then
AC_MSG_CHECKING([for igbinary includes])
igbinary_inc_path=""
Expand Down Expand Up @@ -68,6 +110,47 @@ dnl Check for igbinary
AC_MSG_RESULT([disabled])
fi

if test "$PHP_REDIS_MSGPACK" != "no"; then
AC_MSG_CHECKING([for msgpack includes])
msgpack_inc_path=""

if test -f "$abs_srcdir/include/php/ext/msgpack/php_msgpack.h"; then
msgpack_inc_path="$abs_srcdir/include/php"
elif test -f "$abs_srcdir/ext/msgpack/php_msgpack.h"; then
msgpack_inc_path="$abs_srcdir"
elif test -f "$phpincludedir/ext/msgpack/php_msgpack.h"; then
msgpack_inc_path="$phpincludedir"
else
for i in php php7; do
if test -f "$prefix/include/$i/ext/msgpack/php_msgpack.h"; then
msgpack_inc_path="$prefix/include/$i"
fi
done
fi

if test "$msgpack_inc_path" = ""; then
AC_MSG_ERROR([Cannot find php_msgpack.h])
else
AC_MSG_RESULT([$msgpack_inc_path])
fi
fi

AC_MSG_CHECKING([for redis msgpack support])
if test "$PHP_REDIS_MSGPACK" != "no"; then
AC_MSG_RESULT([enabled])
AC_DEFINE(HAVE_REDIS_MSGPACK,1,[Whether redis msgpack serializer is enabled])
MSGPACK_INCLUDES="-I$msgpack_inc_path"
MSGPACK_EXT_DIR="$msgpack_inc_path/ext"
ifdef([PHP_ADD_EXTENSION_DEP],
[
PHP_ADD_EXTENSION_DEP(redis, msgpack)
])
PHP_ADD_INCLUDE($MSGPACK_EXT_DIR)
else
MSGPACK_INCLUDES=""
AC_MSG_RESULT([disabled])
fi

if test "$PHP_REDIS_LZF" != "no"; then
AC_DEFINE(HAVE_REDIS_LZF, 1, [ ])
if test "$PHP_LIBLZF" != "no"; then
Expand Down Expand Up @@ -105,53 +188,6 @@ dnl Check for igbinary
AC_DEFINE_UNQUOTED(GIT_REVISION, ["$(git log -1 --format=%H)"], [ ])
fi

dnl Check for msgpack
if test "$PHP_REDIS_MSGPACK" != "no"; then
AC_MSG_CHECKING([for msgpack includes])
msgpack_inc_path=""

if test -f "$abs_srcdir/include/php/ext/msgpack/php_msgpack.h"; then
msgpack_inc_path="$abs_srcdir/include/php"
elif test -f "$abs_srcdir/ext/msgpack/php_msgpack.h"; then
msgpack_inc_path="$abs_srcdir"
elif test -f "$phpincludedir/ext/msgpack/php_msgpack.h"; then
msgpack_inc_path="$phpincludedir"
else
for i in php php7; do
if test -f "$prefix/include/$i/ext/msgpack/php_msgpack.h"; then
msgpack_inc_path="$prefix/include/$i"
fi
done
fi

if test "$msgpack_inc_path" = ""; then
AC_MSG_ERROR([Cannot find php_msgpack.h])
else
AC_MSG_RESULT([$msgpack_inc_path])
fi
fi

AC_MSG_CHECKING([for redis msgpack support])
if test "$PHP_REDIS_MSGPACK" != "no"; then
msgpack_version=`grep -o 'PHP_MSGPACK_VERSION "[0-9\.]\+"' $msgpack_inc_path/ext/msgpack/php_msgpack.h | awk '{print $2}' | tr -d '"'`
if expr $msgpack_version "<" "2.0.3" > /dev/null; then
AC_MSG_ERROR([msgpack 2.0.3 or greater required])
else
AC_MSG_RESULT([enabled])
AC_DEFINE(HAVE_REDIS_MSGPACK,1,[Whether redis msgpack serializer is enabled])
MSGPACK_INCLUDES="-I$msgpack_inc_path"
MSGPACK_EXT_DIR="$msgpack_inc_path/ext"
ifdef([PHP_ADD_EXTENSION_DEP],
[
PHP_ADD_EXTENSION_DEP(redis, msgpack)
])
PHP_ADD_INCLUDE($MSGPACK_EXT_DIR)
fi
else
MSGPACK_INCLUDES=""
AC_MSG_RESULT([disabled])
fi

dnl # --with-redis -> check with-path
dnl SEARCH_PATH="/usr/local /usr" # you might want to change this
dnl SEARCH_FOR="/include/redis.h" # you most likely want to change this
Expand Down
13 changes: 11 additions & 2 deletions library.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@
#include "php_redis.h"
#include "library.h"
#include "redis_commands.h"

#ifdef HAVE_REDIS_JSON
#include <ext/json/php_json.h>
#endif

#include <ext/standard/php_rand.h>

#define UNSERIALIZE_NONE 0
Expand Down Expand Up @@ -2316,11 +2320,14 @@ redis_serialize(RedisSock *redis_sock, zval *z, char **val, size_t *val_len
#endif
break;
case REDIS_SERIALIZER_JSON:
#ifdef HAVE_REDIS_JSON
php_json_encode(&sstr, z, PHP_JSON_OBJECT_AS_ARRAY);
*val = estrndup(ZSTR_VAL(sstr.s), ZSTR_LEN(sstr.s));
*val_len = ZSTR_LEN(sstr.s);
smart_str_free(&sstr);
return 1;
#endif
break;
EMPTY_SWITCH_DEFAULT_CASE()
}

Expand Down Expand Up @@ -2385,12 +2392,14 @@ redis_unserialize(RedisSock* redis_sock, const char *val, int val_len,
#endif
break;
case REDIS_SERIALIZER_JSON:
#if PHP_MAJOR_VERSION == 7 && PHP_MINOR_VERSION < 1
#ifdef HAVE_REDIS_JSON
#if (PHP_MAJOR_VERSION == 7 && PHP_MINOR_VERSION < 1)
JSON_G(error_code) = PHP_JSON_ERROR_NONE;
php_json_decode(z_ret, (char*)val, val_len, 1, PHP_JSON_PARSER_DEFAULT_DEPTH);
ret = JSON_G(error_code) == PHP_JSON_ERROR_NONE;
#else
#else
ret = !php_json_decode(z_ret, (char *)val, val_len, 1, PHP_JSON_PARSER_DEFAULT_DEPTH);
#endif
#endif
break;
EMPTY_SWITCH_DEFAULT_CASE()
Expand Down
40 changes: 32 additions & 8 deletions redis.c
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,12 @@ static const zend_module_dep redis_deps[] = {
#ifdef HAVE_REDIS_IGBINARY
ZEND_MOD_REQUIRED("igbinary")
#endif
#ifdef HAVE_REDIS_MSGPACK
ZEND_MOD_REQUIRED("msgpack")
#endif
#ifdef HAVE_REDIS_JSON
ZEND_MOD_REQUIRED("json")
#endif
#ifdef PHP_SESSION
ZEND_MOD_REQUIRED("session")
#endif
Expand Down Expand Up @@ -809,18 +815,36 @@ PHP_MSHUTDOWN_FUNCTION(redis)
return SUCCESS;
}

static const char *get_available_serializers(void) {
#ifdef HAVE_REDIS_IGBINARY
#ifdef HAVE_REDIS_MSGPACK
return "php, igbinary, msgpack";
static const char *
get_available_serializers(void)
{
#ifdef HAVE_REDIS_JSON
#ifdef HAVE_REDIS_IGBINARY
#ifdef HAVE_REDIS_MSGPACK
return "php, json, igbinary, msgpack";
#else
return "php, json, igbinary";
#endif
#else
return "php, igbinary";
#ifdef HAVE_REDIS_MSGPACK
return "php, json, msgpack";
#else
return "php, json";
#endif
#endif
#else
#ifdef HAVE_REDIS_MSGPACK
return "php, msgpack";
#ifdef HAVE_REDIS_IGBINARY
#ifdef HAVE_REDIS_MSGPACK
return "php, igbinary, msgpack";
#else
return "php, igbinary";
#endif
#else
return "php";
#ifdef HAVE_REDIS_MSGPACK
return "php, msgpack";
#else
return "php";
#endif
#endif
#endif
}
Expand Down
Loading

0 comments on commit 235a27e

Please sign in to comment.