From 7ab3311e96b92a12e748f7e8b673d43d3f294da2 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Thu, 11 Jul 2024 09:32:19 +0200 Subject: add upstream patch for PHP 8.4 allow to build with valkey --- php-pecl-redis6.spec | 77 +++++++++++++--------------------- redis-upstream.patch | 116 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 146 insertions(+), 47 deletions(-) create mode 100644 redis-upstream.patch diff --git a/php-pecl-redis6.spec b/php-pecl-redis6.spec index 6163676..db32f4a 100644 --- a/php-pecl-redis6.spec +++ b/php-pecl-redis6.spec @@ -8,7 +8,7 @@ # %if 0%{?scl:1} -%scl_package php-pecl-redis +%scl_package php-pecl-redis6 %bcond_with tests %else %bcond_without tests @@ -16,7 +16,12 @@ %endif %bcond_without igbinary %bcond_without msgpack - +%if 0%{?fedora} >= 41 +%bcond_without valkey +%else +# Use valkey instead of redis for tests +%bcond_with valkey +%endif # Use keydb instead of redis for tests %bcond_with keydb @@ -33,11 +38,13 @@ Summary: Extension for communicating with the Redis key-value store Name: %{?scl_prefix}php-pecl-redis6 Version: %{upstream_version}%{?upstream_prever:~%{upstream_prever}} -Release: 1%{?dist}%{!?scl:%{!?nophptag:%(%{__php} -r 'echo ".".PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION;')}} +Release: 2%{?dist}%{!?scl:%{!?nophptag:%(%{__php} -r 'echo ".".PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION;')}} License: PHP-3.01 URL: https://pecl.php.net/package/redis Source0: https://pecl.php.net/get/%{sources}.tgz +Patch0: %{pecl_name}-upstream.patch + BuildRequires: make BuildRequires: %{?dtsprefix}gcc BuildRequires: %{?scl_prefix}php-devel >= 7.2 @@ -54,12 +61,16 @@ BuildRequires: pkgconfig(libzstd) >= 1.3.0 BuildRequires: pkgconfig(liblz4) # to run Test suite %if %{with tests} +%if %{with valkey} +BuildRequires: valkey +%else %if %{with keydb} BuildRequires: keydb %else BuildRequires: redis %endif %endif +%endif Requires: %{?scl_prefix}php(zend-abi) = %{php_zend_api} Requires: %{?scl_prefix}php(api) = %{php_core_api} @@ -94,25 +105,6 @@ Conflicts: %{?scl_prefix}php-pecl-%{pecl_name}4 < 6 Conflicts: %{?scl_prefix}php-pecl-%{pecl_name}5 < 6 %endif -%if "%{?packager}" == "Remi Collet" && 0%{!?scl:1} && 0%{?rhel} == 7 -# Other third party repo stuff -%if "%{php_version}" > "7.1" -Obsoletes: php71u-pecl-%{pecl_name} <= %{version} -Obsoletes: php71w-pecl-%{pecl_name} <= %{version} -%endif -%if "%{php_version}" > "7.2" -Obsoletes: php72u-pecl-%{pecl_name} <= %{version} -Obsoletes: php72w-pecl-%{pecl_name} <= %{version} -%endif -%if "%{php_version}" > "7.3" -Obsoletes: php73-pecl-%{pecl_name} <= %{version} -Obsoletes: php73w-pecl-%{pecl_name} <= %{version} -%endif -%if "%{php_version}" > "7.4" -Obsoletes: php74-pecl-%{pecl_name} <= %{version} -%endif -%endif - %description The phpredis extension provides an API for communicating @@ -130,11 +122,13 @@ Package built for PHP %(%{__php} -r 'echo PHP_MAJOR_VERSION.".".PHP_MINOR_VERSIO # Don't install/register tests, license, and bundled library sed -e 's/role="test"/role="src"/' \ - %{?_licensedir:-e '/LICENSE/s/role="doc"/role="src"/' } \ + -e '/LICENSE/s/role="doc"/role="src"/' \ -e '/liblzf/d' \ -i package.xml cd %{sources} +%patch -P0 -p1 + # Use system library rm -r liblzf @@ -282,6 +276,10 @@ done cd %{sources}/tests : Launch redis server +%if %{with valkey} +SRV=%{_root_bindir}/valkey-server +CLI=%{_root_bindir}/valkey-cli +%else %if %{with keydb} SRV=%{_root_bindir}/keydb-server CLI=%{_root_bindir}/keydb-cli @@ -289,15 +287,16 @@ CLI=%{_root_bindir}/keydb-cli SRV=%{_root_bindir}/redis-server CLI=%{_root_bindir}/redis-cli %endif +%endif mkdir -p data -pidfile=$PWD/redis.pid +pidfile=$PWD/server.pid port=$(%{__php} -r 'echo 9000 + PHP_MAJOR_VERSION*100 + PHP_MINOR_VERSION*10 + PHP_INT_SIZE + %{?fedora}%{?rhel} + 0%{?scl:1};') $SRV \ --bind 127.0.0.1 \ --port $port \ --daemonize yes \ - --logfile $PWD/redis.log \ + --logfile $PWD/server.log \ --dir $PWD/data \ --pidfile $pidfile @@ -316,7 +315,7 @@ if [ -f $pidfile ]; then $CLI -p $port shutdown nosave sleep 2 fi -cat $PWD/redis.log +cat $PWD/server.log exit $ret %else @@ -324,28 +323,8 @@ exit $ret %endif -%if 0%{?fedora} < 24 && 0%{?rhel} < 8 -# when pear installed alone, after us -%triggerin -- %{?scl_prefix}php-pear -if [ -x %{__pecl} ] ; then - %{pecl_install} %{pecl_xmldir}/%{name}.xml >/dev/null || : -fi - -# posttrans as pear can be installed after us -%posttrans -if [ -x %{__pecl} ] ; then - %{pecl_install} %{pecl_xmldir}/%{name}.xml >/dev/null || : -fi - -%postun -if [ $1 -eq 0 -a -x %{__pecl} ] ; then - %{pecl_uninstall} %{pecl_name} >/dev/null || : -fi -%endif - - %files -%{?_licensedir:%license %{sources}/LICENSE} +%license %{sources}/LICENSE %doc %{pecl_docdir}/%{pecl_name} %{pecl_xmldir}/%{name}.xml @@ -359,6 +338,10 @@ fi %changelog +* Thu Jul 11 2024 Remi Collet - 6.0.2-2 +- add upstream patch for PHP 8.4 +- allow to build with valkey + * Mon Oct 23 2023 Remi Collet - 6.0.2-1 - update to 6.0.2 diff --git a/redis-upstream.patch b/redis-upstream.patch new file mode 100644 index 0000000..03bd34f --- /dev/null +++ b/redis-upstream.patch @@ -0,0 +1,116 @@ +From a51215ce2b22bcd1f506780c35b6833471e0b8cb Mon Sep 17 00:00:00 2001 +From: michael-grunder +Date: Mon, 18 Mar 2024 14:42:35 -0700 +Subject: [PATCH] Update random includes. + +PHP 8.4 has some breaking changes with respect to where PHP's random methods and +helpers are. This commit fixes those issues while staying backward compatible. + +Fixes #2463 +--- + backoff.c | 12 ++++++------ + library.c | 7 ++++++- + redis.c | 6 +++++- + 3 files changed, 17 insertions(+), 8 deletions(-) + +diff --git a/backoff.c b/backoff.c +index d0961fcfaf..1be04a8fe8 100644 +--- a/backoff.c ++++ b/backoff.c +@@ -1,14 +1,14 @@ + #include "common.h" + ++#if PHP_VERSION_ID < 80400 + #include +- +-#if PHP_VERSION_ID >= 70100 +-#include + #else ++#include ++#endif ++ ++#if PHP_VERSION_ID < 70100 + static zend_long php_mt_rand_range(zend_long min, zend_long max) { +- zend_long number = php_rand(); +- RAND_RANGE(number, min, max, PHP_RAND_MAX); +- return number; ++ return min + php_rand() % (max - min + 1) + } + #endif + +diff --git a/library.c b/library.c +index 3d65c8529d..f81556a9ed 100644 +--- a/library.c ++++ b/library.c +@@ -56,9 +56,14 @@ + #include + #endif + +-#include + #include + ++#if PHP_VERSION_ID < 80400 ++#include ++#else ++#include ++#endif ++ + #define UNSERIALIZE_NONE 0 + #define UNSERIALIZE_KEYS 1 + #define UNSERIALIZE_VALS 2 +diff --git a/redis.c b/redis.c +index ec6f65d2ed..2330bf7edf 100644 +--- a/redis.c ++++ b/redis.c +@@ -27,12 +27,16 @@ + #include "redis_cluster.h" + #include "redis_commands.h" + #include "redis_sentinel.h" +-#include + #include + #include + #include + #include + ++#if PHP_VERSION_ID < 80400 ++#include ++#else ++#include ++#endif + + #ifdef PHP_SESSION + #include +From c139de3abac1dd33b97ef0de5af41b6e3a78f7ab Mon Sep 17 00:00:00 2001 +From: michael-grunder +Date: Sat, 1 Jun 2024 13:09:30 -0700 +Subject: [PATCH] We don't need to use a ranom value for our ECHO liveness + challenge. + +A microsecond resolution timestamp combined with a monotonically +incremented counter should be sufficient. + +This also fixes PHP 8.4 compilation as PHP 8.4 doesn't seem to have +`php_rand()`. +--- + library.c | 4 +++- + 1 file changed, 3 insertions(+), 1 deletion(-) + +diff --git a/library.c b/library.c +index ce0cbda26..42a132c4c 100644 +--- a/library.c ++++ b/library.c +@@ -2886,11 +2886,13 @@ redis_sock_create(char *host, int host_len, int port, + } + + static int redis_uniqid(char *buf, size_t buflen) { ++ static unsigned long counter = 0; + struct timeval tv; ++ + gettimeofday(&tv, NULL); + + return snprintf(buf, buflen, "phpredis:%08lx%05lx:%08lx", +- (long)tv.tv_sec, (long)tv.tv_usec, (long)php_rand()); ++ (long)tv.tv_sec, (long)tv.tv_usec, counter++); + } + + static int redis_stream_liveness_check(php_stream *stream) { -- cgit