Skip to content

Commit 235a27e

Browse files
yatsukhnenkomichael-grunder
authored andcommitted
Remove checking of version of msgpack. Allow to disable json serializer. Fix tests.
1 parent 8206b14 commit 235a27e

File tree

4 files changed

+151
-83
lines changed

4 files changed

+151
-83
lines changed

config.m4

Lines changed: 84 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ dnl Make sure that the comment is aligned:
88
PHP_ARG_ENABLE(redis-session, whether to disable sessions,
99
[ --disable-redis-session Disable session support], yes, no)
1010

11+
PHP_ARG_ENABLE(redis-json, whether to disable json serializer support,
12+
[ --disable-redis-json Disable json serializer support], yes, no)
13+
1114
PHP_ARG_ENABLE(redis-igbinary, whether to enable igbinary serializer support,
1215
[ --enable-redis-igbinary Enable igbinary serializer support], no, no)
1316

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

29-
dnl Check for igbinary
32+
if test "PHP_REDIS_JSON" != "no"; then
33+
AC_MSG_CHECKING([for json includes])
34+
json_inc_path=""
35+
if test -f "$abs_srcdir/include/php/ext/json/php_json.h"; then
36+
json_inc_path="$abs_srcdir/include/php"
37+
elif test -f "$abs_srcdir/ext/json/php_json.h"; then
38+
json_inc_path="$abs_srcdir"
39+
elif test -f "$phpincludedir/ext/json/php_json.h"; then
40+
json_inc_path="$phpincludedir"
41+
else
42+
for i in php php7; do
43+
if test -f "$prefix/include/$i/ext/json/php_json.h"; then
44+
json_inc_path="$prefix/include/$i"
45+
fi
46+
done
47+
fi
48+
49+
if test "$json_inc_path" = ""; then
50+
AC_MSG_ERROR([Cannot find php_json.h])
51+
else
52+
AC_MSG_RESULT([$json_inc_path])
53+
fi
54+
fi
55+
56+
AC_MSG_CHECKING([for redis json support])
57+
if test "$PHP_REDIS_JSON" != "no"; then
58+
AC_MSG_RESULT([enabled])
59+
AC_DEFINE(HAVE_REDIS_JSON,1,[Whether redis json serializer is enabled])
60+
JSON_INCLUDES="-I$json_inc_path"
61+
JSON_EXT_DIR="$json_inc_path/ext"
62+
ifdef([PHP_ADD_EXTENSION_DEP],
63+
[
64+
PHP_ADD_EXTENSION_DEP(redis, json)
65+
])
66+
PHP_ADD_INCLUDE($JSON_EXT_DIR)
67+
else
68+
JSON_INCLUDES=""
69+
AC_MSG_RESULT([disabled])
70+
fi
71+
3072
if test "$PHP_REDIS_IGBINARY" != "no"; then
3173
AC_MSG_CHECKING([for igbinary includes])
3274
igbinary_inc_path=""
@@ -68,6 +110,47 @@ dnl Check for igbinary
68110
AC_MSG_RESULT([disabled])
69111
fi
70112

113+
if test "$PHP_REDIS_MSGPACK" != "no"; then
114+
AC_MSG_CHECKING([for msgpack includes])
115+
msgpack_inc_path=""
116+
117+
if test -f "$abs_srcdir/include/php/ext/msgpack/php_msgpack.h"; then
118+
msgpack_inc_path="$abs_srcdir/include/php"
119+
elif test -f "$abs_srcdir/ext/msgpack/php_msgpack.h"; then
120+
msgpack_inc_path="$abs_srcdir"
121+
elif test -f "$phpincludedir/ext/msgpack/php_msgpack.h"; then
122+
msgpack_inc_path="$phpincludedir"
123+
else
124+
for i in php php7; do
125+
if test -f "$prefix/include/$i/ext/msgpack/php_msgpack.h"; then
126+
msgpack_inc_path="$prefix/include/$i"
127+
fi
128+
done
129+
fi
130+
131+
if test "$msgpack_inc_path" = ""; then
132+
AC_MSG_ERROR([Cannot find php_msgpack.h])
133+
else
134+
AC_MSG_RESULT([$msgpack_inc_path])
135+
fi
136+
fi
137+
138+
AC_MSG_CHECKING([for redis msgpack support])
139+
if test "$PHP_REDIS_MSGPACK" != "no"; then
140+
AC_MSG_RESULT([enabled])
141+
AC_DEFINE(HAVE_REDIS_MSGPACK,1,[Whether redis msgpack serializer is enabled])
142+
MSGPACK_INCLUDES="-I$msgpack_inc_path"
143+
MSGPACK_EXT_DIR="$msgpack_inc_path/ext"
144+
ifdef([PHP_ADD_EXTENSION_DEP],
145+
[
146+
PHP_ADD_EXTENSION_DEP(redis, msgpack)
147+
])
148+
PHP_ADD_INCLUDE($MSGPACK_EXT_DIR)
149+
else
150+
MSGPACK_INCLUDES=""
151+
AC_MSG_RESULT([disabled])
152+
fi
153+
71154
if test "$PHP_REDIS_LZF" != "no"; then
72155
AC_DEFINE(HAVE_REDIS_LZF, 1, [ ])
73156
if test "$PHP_LIBLZF" != "no"; then
@@ -105,53 +188,6 @@ dnl Check for igbinary
105188
AC_DEFINE_UNQUOTED(GIT_REVISION, ["$(git log -1 --format=%H)"], [ ])
106189
fi
107190

108-
dnl Check for msgpack
109-
if test "$PHP_REDIS_MSGPACK" != "no"; then
110-
AC_MSG_CHECKING([for msgpack includes])
111-
msgpack_inc_path=""
112-
113-
if test -f "$abs_srcdir/include/php/ext/msgpack/php_msgpack.h"; then
114-
msgpack_inc_path="$abs_srcdir/include/php"
115-
elif test -f "$abs_srcdir/ext/msgpack/php_msgpack.h"; then
116-
msgpack_inc_path="$abs_srcdir"
117-
elif test -f "$phpincludedir/ext/msgpack/php_msgpack.h"; then
118-
msgpack_inc_path="$phpincludedir"
119-
else
120-
for i in php php7; do
121-
if test -f "$prefix/include/$i/ext/msgpack/php_msgpack.h"; then
122-
msgpack_inc_path="$prefix/include/$i"
123-
fi
124-
done
125-
fi
126-
127-
if test "$msgpack_inc_path" = ""; then
128-
AC_MSG_ERROR([Cannot find php_msgpack.h])
129-
else
130-
AC_MSG_RESULT([$msgpack_inc_path])
131-
fi
132-
fi
133-
134-
AC_MSG_CHECKING([for redis msgpack support])
135-
if test "$PHP_REDIS_MSGPACK" != "no"; then
136-
msgpack_version=`grep -o 'PHP_MSGPACK_VERSION "[0-9\.]\+"' $msgpack_inc_path/ext/msgpack/php_msgpack.h | awk '{print $2}' | tr -d '"'`
137-
if expr $msgpack_version "<" "2.0.3" > /dev/null; then
138-
AC_MSG_ERROR([msgpack 2.0.3 or greater required])
139-
else
140-
AC_MSG_RESULT([enabled])
141-
AC_DEFINE(HAVE_REDIS_MSGPACK,1,[Whether redis msgpack serializer is enabled])
142-
MSGPACK_INCLUDES="-I$msgpack_inc_path"
143-
MSGPACK_EXT_DIR="$msgpack_inc_path/ext"
144-
ifdef([PHP_ADD_EXTENSION_DEP],
145-
[
146-
PHP_ADD_EXTENSION_DEP(redis, msgpack)
147-
])
148-
PHP_ADD_INCLUDE($MSGPACK_EXT_DIR)
149-
fi
150-
else
151-
MSGPACK_INCLUDES=""
152-
AC_MSG_RESULT([disabled])
153-
fi
154-
155191
dnl # --with-redis -> check with-path
156192
dnl SEARCH_PATH="/usr/local /usr" # you might want to change this
157193
dnl SEARCH_FOR="/include/redis.h" # you most likely want to change this

library.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@
2525
#include "php_redis.h"
2626
#include "library.h"
2727
#include "redis_commands.h"
28+
29+
#ifdef HAVE_REDIS_JSON
2830
#include <ext/json/php_json.h>
31+
#endif
32+
2933
#include <ext/standard/php_rand.h>
3034

3135
#define UNSERIALIZE_NONE 0
@@ -2316,11 +2320,14 @@ redis_serialize(RedisSock *redis_sock, zval *z, char **val, size_t *val_len
23162320
#endif
23172321
break;
23182322
case REDIS_SERIALIZER_JSON:
2323+
#ifdef HAVE_REDIS_JSON
23192324
php_json_encode(&sstr, z, PHP_JSON_OBJECT_AS_ARRAY);
23202325
*val = estrndup(ZSTR_VAL(sstr.s), ZSTR_LEN(sstr.s));
23212326
*val_len = ZSTR_LEN(sstr.s);
23222327
smart_str_free(&sstr);
23232328
return 1;
2329+
#endif
2330+
break;
23242331
EMPTY_SWITCH_DEFAULT_CASE()
23252332
}
23262333

@@ -2385,12 +2392,14 @@ redis_unserialize(RedisSock* redis_sock, const char *val, int val_len,
23852392
#endif
23862393
break;
23872394
case REDIS_SERIALIZER_JSON:
2388-
#if PHP_MAJOR_VERSION == 7 && PHP_MINOR_VERSION < 1
2395+
#ifdef HAVE_REDIS_JSON
2396+
#if (PHP_MAJOR_VERSION == 7 && PHP_MINOR_VERSION < 1)
23892397
JSON_G(error_code) = PHP_JSON_ERROR_NONE;
23902398
php_json_decode(z_ret, (char*)val, val_len, 1, PHP_JSON_PARSER_DEFAULT_DEPTH);
23912399
ret = JSON_G(error_code) == PHP_JSON_ERROR_NONE;
2392-
#else
2400+
#else
23932401
ret = !php_json_decode(z_ret, (char *)val, val_len, 1, PHP_JSON_PARSER_DEFAULT_DEPTH);
2402+
#endif
23942403
#endif
23952404
break;
23962405
EMPTY_SWITCH_DEFAULT_CASE()

redis.c

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,12 @@ static const zend_module_dep redis_deps[] = {
477477
#ifdef HAVE_REDIS_IGBINARY
478478
ZEND_MOD_REQUIRED("igbinary")
479479
#endif
480+
#ifdef HAVE_REDIS_MSGPACK
481+
ZEND_MOD_REQUIRED("msgpack")
482+
#endif
483+
#ifdef HAVE_REDIS_JSON
484+
ZEND_MOD_REQUIRED("json")
485+
#endif
480486
#ifdef PHP_SESSION
481487
ZEND_MOD_REQUIRED("session")
482488
#endif
@@ -809,18 +815,36 @@ PHP_MSHUTDOWN_FUNCTION(redis)
809815
return SUCCESS;
810816
}
811817

812-
static const char *get_available_serializers(void) {
813-
#ifdef HAVE_REDIS_IGBINARY
814-
#ifdef HAVE_REDIS_MSGPACK
815-
return "php, igbinary, msgpack";
818+
static const char *
819+
get_available_serializers(void)
820+
{
821+
#ifdef HAVE_REDIS_JSON
822+
#ifdef HAVE_REDIS_IGBINARY
823+
#ifdef HAVE_REDIS_MSGPACK
824+
return "php, json, igbinary, msgpack";
825+
#else
826+
return "php, json, igbinary";
827+
#endif
816828
#else
817-
return "php, igbinary";
829+
#ifdef HAVE_REDIS_MSGPACK
830+
return "php, json, msgpack";
831+
#else
832+
return "php, json";
833+
#endif
818834
#endif
819835
#else
820-
#ifdef HAVE_REDIS_MSGPACK
821-
return "php, msgpack";
836+
#ifdef HAVE_REDIS_IGBINARY
837+
#ifdef HAVE_REDIS_MSGPACK
838+
return "php, igbinary, msgpack";
839+
#else
840+
return "php, igbinary";
841+
#endif
822842
#else
823-
return "php";
843+
#ifdef HAVE_REDIS_MSGPACK
844+
return "php, msgpack";
845+
#else
846+
return "php";
847+
#endif
824848
#endif
825849
#endif
826850
}

0 commit comments

Comments
 (0)