Skip to content

Commit

Permalink
Merge 2.x into main (#1341)
Browse files Browse the repository at this point in the history
* Codestyle changes related to php-cs-fixer update (#1311)

* Codestyle changes

* Added missing type-hints

* Added GETDEL command to KeyPrefixProcessor (#1306)

* Added GETDEL command to KeyPrefixProcessor

* Added test coverage

* Codestyle fixes

* Added timeout after FT.CREATE call

* Added support for JSON.MERGE command (#1304)

* Added support for JSON.MSET command (#1307)

* Fixed subcommand test bug (#1313)

* Update CHANGELOG.md

* Update CHANGELOG.md

* Fixed bug with incorrect multiple words processing (#1325)

* Fixed bug with incorrect multiple words processing

* Convert subcommand string to lower case

* Update SubcommandStrategyResolver.php

* Added test coverage

* Codestyle fixes

---------

Co-authored-by: Till Krüss <tillkruss@users.noreply.github.com>

* Added support for FUNCTION DUMP, FUNCTION FLUSH, FUNCTION RESTORE commands (#1332)

* Added support for CLIENT NO-EVICT command (#1335)

* Added support for FUNCTION KILL, FUNCTION LIST, FUNCTION STATS commands (#1334)

* Added support for FUNCTION KILL, FUNCTION LIST, FUNCTION STATS commands

* Marked tests as relay-incompatible

* Added support for tests running against redis cluster (#1236)

* Added support for tests running against redis cluster

* Test coverage

* Added comment about master nodes

* Codestyle fix

* Revert changes

* Revert DBNUM

* Added cluster endpoints to relay tests env configuration

* Exclude cluster tests from relay tests environment

* Removed TODO comment

* Changed cluster image version to unstable

* Updated configuration to match unstable cluster

* Fixed path

* Updated cluster CI configuration

* Removed redundant flag

* Removed backslash

* Updated file path

* Updated file path variable

* Added docker cluster initialization as additional step

* Run cluster tests as separate workflow

* Codestyle fixes

* Updated exported files

* Added additional timeout so cluster image could be settled

* Added support for different cluster image, use docker compose for cluster tests CI

* Remove unused flag

* Removed variable from volume path

* Added sleep timeout to allow docker setup after running

* Added timeout before tests run

* Updated linter settings

* Include indent changes for.sh files

* Added missing coverage

* Revert expected files and mark docker folder as exclusion

* Specify folder itself as excluded

* Moved cluster tests as separate job in tests.yml

* Updated name to contain cluster word

---------

Co-authored-by: Chayim <chayim@users.noreply.github.com>

---------

Co-authored-by: Till Krüss <tillkruss@users.noreply.github.com>
Co-authored-by: Chayim <chayim@users.noreply.github.com>
  • Loading branch information
3 people committed Jul 25, 2023
1 parent 00e8764 commit ac37f5b
Show file tree
Hide file tree
Showing 36 changed files with 1,026 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .codespellrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ skip=./.git
check-hidden=
check-filenames=
builtin=clear,rare,informal,usage,code,names
ignore-words-list=master,masters,slave,slaves,whitelist,cas,exat,smove,SUGGET,sugget
ignore-words-list=master,masters,slave,slaves,whitelist,cas,exat,smove,SUGGET,sugget,ro
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ block_comment_end = */
[*.php]
max_line_length = 150

[*.{md,yml,yaml,neon}]
[*.{md,yml,yaml,neon,sh}]
indent_size = 2

[tests/**.php]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ jobs:
EXPECTED="LICENSE,README.md,autoload.php,composer.json"
CURRENT="$(
git archive HEAD \
| tar --list --exclude="src" --exclude="src/*" --exclude="bin" --exclude="bin/*" \
| tar --list --exclude="src" --exclude="src/*" --exclude="bin" --exclude="bin/*" --exclude="docker" --exclude="docker/*" \
| paste --serial --delimiters=","
)"
echo "CURRENT =${CURRENT}"
Expand Down
43 changes: 43 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,46 @@ jobs:
run: |
wget "https://github.com/php-coveralls/php-coveralls/releases/download/v2.5.3/php-coveralls.phar"
php ./php-coveralls.phar -v
predis-cluster:

name: PHP ${{ matrix.php }} (Redis Cluster latest)
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
php:
- '7.2'
- '7.3'
- '7.4'
- '8.0'
- '8.1'
- '8.2'

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Run redis cluster
uses: isbang/compose-action@v1.4.1
with:
compose-file: "./docker/unstable_cluster/docker-compose.yml"

- name: Setup PHP with Composer and extensions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: relay
coverage: ${{ (matrix.php == '8.1') && 'xdebug' || 'none' }}

- name: Install Composer dependencies
uses: ramsey/composer-install@v2
with:
dependency-versions: highest
composer-options: ${{ matrix.php == '8.0' && '--ignore-platform-reqs' || '' }}

- name: Run tests against cluster
run: |
sleep 5 # Timeout to make sure that docker image is setup
vendor/bin/phpunit --group cluster
18 changes: 9 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
## Changelog

## Unreleased
## v2.2.0 (2023-06-14)

### Changed
- Added `PrefixableCommandInterface` (#1262)

### Removed
- Removed Webdis and Phpiredis support (#1291)
Predis v2.2.0 introduces official support for [Redis Stack](https://redis.io/docs/stack/) as well as a [Relay](https://github.com/cachewerk/relay) integration for substantially [faster read performance](https://github.com/predis/predis/wiki/Using-Relay).

## v2.2.0-RC1 (2023-05-09)

Expand All @@ -16,11 +12,15 @@
- Added support for Redis `JSON`, `Bloom`, `Search` and `TimeSeries` module (#1253)
- Added support for `ACL SETUSER, GETUSER, DRYRUN` commands (#1193)

### Changed
- Minor code style and type-hint changes (#1311)

### Fixed
- Fixed prefixes for `XTRIM` and `XREVRANGE` commands (#1230)
- Fix `fclose()` being called on invalid stream resource (#1199)
- Fix `BitByte` and `ExpireOptions` traits skip processing on null values (#1169)
- Fix missing `@return` annotations (#1265)
- Fixed `fclose()` being called on invalid stream resource (#1199)
- Fixed `BitByte` and `ExpireOptions` traits skip processing on null values (#1169)
- Fixed missing `@return` annotations (#1265)
- Fixed `GETDEL` prefixing (#1306)

## v2.1.2 (2023-03-02)

Expand Down
7 changes: 7 additions & 0 deletions docker/unstable_cluster/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM redis/redis-stack-server:latest as rss

COPY create_cluster.sh /create_cluster.sh
RUN ls -R /opt/redis-stack
RUN chmod a+x /create_cluster.sh

ENTRYPOINT [ "/create_cluster.sh"]
47 changes: 47 additions & 0 deletions docker/unstable_cluster/create_cluster.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#! /bin/bash

mkdir -p /nodes
touch /nodes/nodemap
if [ -z ${START_PORT} ]; then
START_PORT=6372
fi
if [ -z ${END_PORT} ]; then
END_PORT=6377
fi
if [ ! -z "$3" ]; then
START_PORT=$2
START_PORT=$3
fi
echo "STARTING: ${START_PORT}"
echo "ENDING: ${END_PORT}"

for PORT in `seq ${START_PORT} ${END_PORT}`; do
mkdir -p /nodes/$PORT
if [[ -e /redis.conf ]]; then
cp /redis.conf /nodes/$PORT/redis.conf
else
touch /nodes/$PORT/redis.conf
fi
cat << EOF >> /nodes/$PORT/redis.conf
port ${PORT}
cluster-enabled yes
daemonize yes
logfile /redis.log
dir /nodes/$PORT
EOF

set -x
/opt/redis-stack/bin/redis-server /nodes/$PORT/redis.conf
sleep 1
if [ $? -ne 0 ]; then
echo "Redis failed to start, exiting."
continue
fi
echo 127.0.0.1:$PORT >> /nodes/nodemap
done
if [ -z "${REDIS_PASSWORD}" ]; then
echo yes | /opt/redis-stack/bin/redis-cli --cluster create `seq -f 127.0.0.1:%g ${START_PORT} ${END_PORT}` --cluster-replicas 1
else
echo yes | opt/redis-stack/bin/redis-cli -a ${REDIS_PASSWORD} --cluster create `seq -f 127.0.0.1:%g ${START_PORT} ${END_PORT}` --cluster-replicas 1
fi
tail -f /redis.log
17 changes: 17 additions & 0 deletions docker/unstable_cluster/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: "3.9"
services:
cluster:
container_name: redis-cluster
build:
context: .
dockerfile: Dockerfile
ports:
- "6372:6372"
- "6373:6373"
- "6374:6374"
- "6375:6375"
- "6376:6376"
- "6377:6378"
volumes:
- "./redis.conf:/redis.conf:ro"

9 changes: 9 additions & 0 deletions docker/unstable_cluster/redis.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Redis Cluster config file will be shared across all nodes.
# Do not change the following configurations that are already set:
# port, cluster-enabled, daemonize, logfile, dir
protected-mode no
loadmodule /opt/redis-stack/lib/redisearch.so
loadmodule /opt/redis-stack/lib/redisgraph.so
loadmodule /opt/redis-stack/lib/redistimeseries.so
loadmodule /opt/redis-stack/lib/rejson.so
loadmodule /opt/redis-stack/lib/redisbloom.so
5 changes: 5 additions & 0 deletions phpunit.relay.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<group>relay-incompatible</group>
<group>realm-stack</group>
<group>ext-curl</group>
<group>cluster</group>
</exclude>
</groups>

Expand All @@ -36,5 +37,9 @@
<const name="REDIS_SERVER_PORT" value="6379" />
<const name="REDIS_SERVER_DBNUM" value="0" />
<env name="USE_RELAY" value="true" />

<!-- Redis Cluster -->
<!-- Only master nodes endpoints included -->
<const name="REDIS_CLUSTER_ENDPOINTS" value="127.0.0.1:6372,127.0.0.1:6373,127.0.0.1:6374" />
</php>
</phpunit>
5 changes: 5 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<group>realm-stack</group>
<group>ext-relay</group>
<group>ext-curl</group>
<group>cluster</group>
<!-- <group>connected</group> -->
<!-- <group>disconnected</group> -->
<!-- <group>commands</group> -->
Expand All @@ -49,5 +50,9 @@
<const name="REDIS_SERVER_PORT" value="6379" />
<const name="REDIS_SERVER_DBNUM" value="0" />
<env name="USE_RELAY" value="false" />

<!-- Redis Cluster -->
<!-- Only master nodes endpoints included -->
<const name="REDIS_CLUSTER_ENDPOINTS" value="127.0.0.1:6372,127.0.0.1:6373,127.0.0.1:6374" />
</php>
</phpunit>
14 changes: 14 additions & 0 deletions src/Cluster/ClusterStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ protected function getDefaultCommands()
'SORT' => [$this, 'getKeyFromSortCommand'],
'DUMP' => $getKeyFromFirstArgument,
'RESTORE' => $getKeyFromFirstArgument,
'FLUSHDB' => [$this, 'getFakeKey'],

/* commands operating on string values */
'APPEND' => $getKeyFromFirstArgument,
Expand Down Expand Up @@ -163,6 +164,9 @@ protected function getDefaultCommands()
'EVAL' => [$this, 'getKeyFromScriptingCommands'],
'EVALSHA' => [$this, 'getKeyFromScriptingCommands'],

/* server */
'INFO' => [$this, 'getFakeKey'],

/* commands performing geospatial operations */
'GEOADD' => $getKeyFromFirstArgument,
'GEOHASH' => $getKeyFromFirstArgument,
Expand Down Expand Up @@ -216,6 +220,16 @@ public function setCommandHandler($commandID, $callback = null)
$this->commands[$commandID] = $callback;
}

/**
* Get fake key for commands with no key argument.
*
* @return string
*/
protected function getFakeKey(): string
{
return 'key';
}

/**
* Extracts the key from the first argument of a command instance.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Container/AbstractContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct(ClientInterface $client)
/**
* {@inheritDoc}
*/
public function __call($subcommandID, $arguments)
public function __call(string $subcommandID, array $arguments)
{
array_unshift($arguments, strtoupper($subcommandID));

Expand Down
8 changes: 7 additions & 1 deletion src/Command/Container/FUNCTIONS.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@
use Predis\Response\Status;

/**
* @method string load(string $functionCode, bool $replace = 'false')
* @method Status delete(string $libraryName)
* @method string dump()
* @method Status flush(?string $mode = null)
* @method Status kill()
* @method array list(string $libraryNamePattern = null, bool $withCode = false)
* @method string load(string $functionCode, bool $replace = 'false')
* @method Status restore(string $value, string $policy = null)
* @method array stats()
*/
class FUNCTIONS extends AbstractContainer
{
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Redis/FUNCTIONS.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function getId()

public function setArguments(array $arguments)
{
$strategy = $this->strategyResolver->resolve('functions', $arguments[0]);
$strategy = $this->strategyResolver->resolve('functions', strtolower($arguments[0]));
$arguments = $strategy->processArguments($arguments);

parent::setArguments($arguments);
Expand Down
26 changes: 26 additions & 0 deletions src/Command/Strategy/ContainerCommands/Functions/DumpStrategy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

/*
* This file is part of the Predis package.
*
* (c) 2009-2020 Daniele Alessandri
* (c) 2021-2023 Till Krüss
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Predis\Command\Strategy\ContainerCommands\Functions;

use Predis\Command\Strategy\SubcommandStrategyInterface;

class DumpStrategy implements SubcommandStrategyInterface
{
/**
* {@inheritDoc}
*/
public function processArguments(array $arguments): array
{
return $arguments;
}
}
32 changes: 32 additions & 0 deletions src/Command/Strategy/ContainerCommands/Functions/FlushStrategy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/*
* This file is part of the Predis package.
*
* (c) 2009-2020 Daniele Alessandri
* (c) 2021-2023 Till Krüss
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Predis\Command\Strategy\ContainerCommands\Functions;

use Predis\Command\Strategy\SubcommandStrategyInterface;

class FlushStrategy implements SubcommandStrategyInterface
{
/**
* {@inheritDoc}
*/
public function processArguments(array $arguments): array
{
$processedArguments = [$arguments[0]];

if (array_key_exists(1, $arguments) && null !== $arguments[1]) {
$processedArguments[] = strtoupper($arguments[1]);
}

return $processedArguments;
}
}
26 changes: 26 additions & 0 deletions src/Command/Strategy/ContainerCommands/Functions/KillStrategy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

/*
* This file is part of the Predis package.
*
* (c) 2009-2020 Daniele Alessandri
* (c) 2021-2023 Till Krüss
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Predis\Command\Strategy\ContainerCommands\Functions;

use Predis\Command\Strategy\SubcommandStrategyInterface;

class KillStrategy implements SubcommandStrategyInterface
{
/**
* {@inheritDoc}
*/
public function processArguments(array $arguments): array
{
return $arguments;
}
}
Loading

0 comments on commit ac37f5b

Please sign in to comment.