You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

287 lines
7.0 KiB

%bcond_with tests
%bcond_without igbinary
%bcond_without msgpack
%global _root_bindir %{_bindir}
%global pecl_name redis
%global with_zts 0%{!?_without_zts:%{?__ztsphp:1}}
# after 20-json, 40-igbinary and 40-msgpack
%global ini_name 50-%{pecl_name}.ini
%global upstream_version 6.1.0
%global sources %{pecl_name}-%{upstream_version}%{?upstream_prever}
%global _configure ../%{sources}/configure
Name: php-pecl-redis
Version: 6.1.0
Release: 1%{?dist}
License: PHP-3.01
URL: https://pecl.php.net/package/redis
Source0: https://pecl.php.net/get/%{sources}.tgz
Summary: PHP extension for interfacing with key-value stores
BuildRequires: make
BuildRequires: gcc
BuildRequires: php-devel >= 7.4
BuildRequires: php-pear
BuildRequires: php-json
%if %{with igbinary}
BuildRequires: php-pecl-igbinary-devel
%endif
%if %{with msgpack}
BuildRequires: php-pecl-msgpack-devel >= 2.0.3
%endif
BuildRequires: pkgconfig(liblzf)
BuildRequires: pkgconfig(libzstd) >= 1.3.0
BuildRequires: pkgconfig(liblz4)
# to run Test suite
%if %{with tests}
BuildRequires: redis
%endif
Requires: php(zend-abi) = %{php_zend_api}
Requires: php(api) = %{php_core_api}
Requires: php-json%{?_isa}
%if %{with igbinary}
Requires: php-igbinary%{?_isa}
%endif
%if %{with msgpack}
Requires: php-msgpack%{?_isa}
%endif
Obsoletes: php-%{pecl_name} < 3
Provides: php-%{pecl_name} = %{version}
Provides: php-%{pecl_name}%{?_isa} = %{version}
Provides: php-pecl(%{pecl_name}) = %{version}
Provides: php-pecl(%{pecl_name})%{?_isa} = %{version}
%description
This extension provides an API for communicating with RESP-based key-value
stores, such as Redis, Valkey, and KeyDB.
This client implements most of the latest API.
As method only works when also implemented on the server side,
some doesn't work with an old server version.
%prep
%setup -q -c
# Don't install/register tests, license, and bundled library
sed -e 's/role="test"/role="src"/' \
-e '/LICENSE/s/role="doc"/role="src"/' \
-e '/liblzf/d' \
-i package.xml
cd %{sources}
# Use system library
rm -r liblzf
# Sanity check, really often broken
extver=$(sed -n '/#define PHP_REDIS_VERSION/{s/.* "//;s/".*$//;p}' php_redis.h)
if test "x${extver}" != "x%{upstream_version}%{?upstream_prever}"; then
: Error: Upstream extension version is ${extver}, expecting %{upstream_version}%{?upstream_prever}.
exit 1
fi
cd ..
mkdir NTS
%if %{with_zts}
mkdir ZTS
%endif
# Drop in the bit of configuration
cat > %{ini_name} << 'EOF'
; Enable %{pecl_name} extension module
extension = %{pecl_name}.so
; phpredis can be used to store PHP sessions.
; To do this, uncomment and configure below
; RPM note : save_handler and save_path are defined
; for mod_php, in /etc/httpd/conf.d/php.conf
; for php-fpm, in %{_sysconfdir}/php-fpm.d/*conf
;session.save_handler = %{pecl_name}
;session.save_path = "tcp://host1:6379?weight=1, tcp://host2:6379?weight=2&timeout=2.5, tcp://host3:6379?weight=2"
; Configuration
;redis.arrays.algorithm = ''
;redis.arrays.auth = ''
;redis.arrays.autorehash = 0
;redis.arrays.connecttimeout = 0
;redis.arrays.consistent = 0
;redis.arrays.distributor = ''
;redis.arrays.functions = ''
;redis.arrays.hosts = ''
;redis.arrays.index = 0
;redis.arrays.lazyconnect = 0
;redis.arrays.names = ''
;redis.arrays.pconnect = 0
;redis.arrays.previous = ''
;redis.arrays.readtimeout = 0
;redis.arrays.retryinterval = 0
;redis.clusters.auth = 0
;redis.clusters.cache_slots = 0
;redis.clusters.persistent = 0
;redis.clusters.read_timeout = 0
;redis.clusters.seeds = ''
;redis.clusters.timeout = 0
;redis.pconnect.pooling_enabled = 1
;redis.pconnect.connection_limit = 0
;redis.pconnect.echo_check_liveness = 1
;redis.pconnect.pool_detect_dirty = 0
;redis.pconnect.pool_poll_timeout = 0
;redis.pconnect.pool_pattern => ''
;redis.session.locking_enabled = 0
;redis.session.lock_expire = 0
;redis.session.lock_retries = 100
;redis.session.lock_wait_time = 20000
;redis.session.early_refresh = 0
;redis.session.compression = none
;redis.session.compression_level = 3
EOF
%build
%{?dtsenable}
peclconf() {
%configure \
--enable-redis \
--enable-redis-session \
%if %{with igbinary}
--enable-redis-igbinary \
%endif
%if %{with msgpack}
--enable-redis-msgpack \
%endif
--enable-redis-lzf \
--with-liblzf \
--enable-redis-zstd \
--with-libzstd \
--enable-redis-lz4 \
--with-liblz4 \
--with-php-config=$1
}
cd %{sources}
%{__phpize}
sed -e 's/INSTALL_ROOT/DESTDIR/' -i build/Makefile.global
cd ../NTS
peclconf %{__phpconfig}
%make_build
%if %{with_zts}
cd ../ZTS
peclconf %{__ztsphpconfig}
%make_build
%endif
%install
%{?dtsenable}
# Install the NTS stuff
%make_install -C NTS
install -D -m 644 %{ini_name} %{buildroot}%{php_inidir}/%{ini_name}
%if %{with_zts}
# Install the ZTS stuff
%make_install -C ZTS
install -D -m 644 %{ini_name} %{buildroot}%{php_ztsinidir}/%{ini_name}
%endif
# Install the package XML file
install -D -m 644 package.xml %{buildroot}%{pecl_xmldir}/%{name}.xml
# Documentation
cd %{sources}
for i in $(grep 'role="doc"' ../package.xml | sed -e 's/^.*name="//;s/".*$//')
do install -Dpm 644 $i %{buildroot}%{pecl_docdir}/%{pecl_name}/$i
done
%check
# simple module load test
DEPS="--no-php-ini"
for i in json igbinary msgpack
do [ -f %{php_extdir}/${i}.so ] && DEPS="$DEPS --define extension=${i}.so"
done
%{__php} $DEPS \
--define extension=%{buildroot}%{php_extdir}/%{pecl_name}.so \
--modules | grep '^%{pecl_name}$'
%if %{with_zts}
%{__ztsphp} $DEPS \
--define extension=%{buildroot}%{php_ztsextdir}/%{pecl_name}.so \
--modules | grep '^%{pecl_name}$'
%endif
%if %{with tests}
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
%else
SRV=%{_root_bindir}/redis-server
CLI=%{_root_bindir}/redis-cli
%endif
%endif
mkdir -p data
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/server.log \
--dir $PWD/data \
--pidfile $pidfile
: Run the test Suite
sed -e "s/6379/$port/" -i *.php
ret=0
export TEST_PHP_EXECUTABLE=%{__php}
export TEST_PHP_ARGS="$DEPS \
--define extension=%{buildroot}%{php_extdir}/%{pecl_name}.so"
$TEST_PHP_EXECUTABLE $TEST_PHP_ARGS TestRedis.php || ret=1
: Cleanup
if [ -f $pidfile ]; then
$CLI -p $port shutdown nosave
sleep 2
fi
cat $PWD/server.log
exit $ret
%else
: Upstream test suite disabled
%endif
%files
%license %{sources}/LICENSE
%{pecl_xmldir}/%{name}.xml
%{php_extdir}/%{pecl_name}.so
%config(noreplace) %{php_inidir}/%{ini_name}
%if %{with_zts}
%{php_ztsextdir}/%{pecl_name}.so
%config(noreplace) %{php_ztsinidir}/%{ini_name}
%endif
%changelog