Patch-Source: https://github.com/phpredis/phpredis/commit/a51215ce2b22bcd1f506780c35b6833471e0b8cb 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