From aa0e0222b96f035d5589b4d973c255c2bad624d0 Mon Sep 17 00:00:00 2001 From: Shaverdova Elena Date: Mon, 5 Aug 2019 18:54:16 +0200 Subject: [PATCH 01/19] Add Redis.sAddArray method --- src/Redis.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/Redis.php b/src/Redis.php index b60dc8e..c04c9cc 100644 --- a/src/Redis.php +++ b/src/Redis.php @@ -4932,6 +4932,28 @@ public function xRevRange($stream, $end, $start, $count = null) public function xTrim($stream, $maxLen, $isApproximate) { } + + /** + * Adds a values to the set value stored at key. + * + * @param string $key Required key + * @param array $values Required values + * + * @return int|bool The number of elements added to the set. + * If this value is already in the set, FALSE is returned + * + * @link https://redis.io/commands/sadd + * @link https://github.com/phpredis/phpredis/commit/3491b188e0022f75b938738f7542603c7aae9077 + * @since phpredis 2.2.8 + * @example + *
+     * $redis->sAddArray('k', array('v1'));                // boolean
+     * $redis->sAddArray('k', array('v1', 'v2', 'v3'));    // boolean
+     * 
+ */ + public function sAddArray($key, array $values) + { + } } class RedisException extends Exception From 983b1ed57c5d6437da157f163a9052b7f4d88c7b Mon Sep 17 00:00:00 2001 From: Maksim Kamashev Date: Tue, 6 Aug 2019 00:10:27 +0300 Subject: [PATCH 02/19] Fix invalid tag --- src/Redis.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Redis.php b/src/Redis.php index c04c9cc..55a0e20 100644 --- a/src/Redis.php +++ b/src/Redis.php @@ -3518,7 +3518,7 @@ public function bzPopMax($key1, $key2, $timeout) * @return array Either an array with the key member and score of the higest or lowest element or an empty array * if the timeout was reached without an element to pop. * - * @see @bzPopMax + * @see bzPopMax * @since >= 5.0 * @link https://redis.io/commands/bzpopmin */ From 446678dadff5ea4493fb8b36f22471ffe6658a24 Mon Sep 17 00:00:00 2001 From: Shaverdova Elena Date: Tue, 6 Aug 2019 15:03:16 +0200 Subject: [PATCH 03/19] In Redis.client second parameter is optional, see $redis->client('list') --- src/Redis.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Redis.php b/src/Redis.php index c04c9cc..440dda5 100644 --- a/src/Redis.php +++ b/src/Redis.php @@ -4388,7 +4388,7 @@ public function clearLastError() * $redis->client('kill', ); // Kill the process at ip:port * */ - public function client($command, $value) + public function client($command, $value = '') { } From a6523cdd3f18aeabb30a42d1448ea9fdfeacb437 Mon Sep 17 00:00:00 2001 From: Shaverdova Elena Date: Tue, 6 Aug 2019 15:28:42 +0200 Subject: [PATCH 04/19] Since Redis.exists may return both bool and int, it's safer to provide both --- src/Redis.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Redis.php b/src/Redis.php index b60dc8e..2a8578c 100644 --- a/src/Redis.php +++ b/src/Redis.php @@ -777,7 +777,7 @@ public function punsubscribe($patterns = null) * * @param string|string[] $key * - * @return bool The number of keys tested that do exist + * @return int|bool The number of keys tested that do exist * * @link https://redis.io/commands/exists * @link https://github.com/phpredis/phpredis#exists From 4db233605ae2f95d9b350c500525e10af77c2fc9 Mon Sep 17 00:00:00 2001 From: Shaverdova Elena Date: Tue, 6 Aug 2019 15:32:02 +0200 Subject: [PATCH 05/19] Redis.hDel may return false if the hash table doesn't exist, or the key doesn't exist --- src/Redis.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Redis.php b/src/Redis.php index b60dc8e..a14f9ff 100644 --- a/src/Redis.php +++ b/src/Redis.php @@ -3617,7 +3617,7 @@ public function hLen($key) * @param string $hashKey1 * @param string ...$otherHashKeys * - * @return int Number of deleted fields + * @return int|false Number of deleted fields * * @link https://redis.io/commands/hdel * @example From 4f8ff0f15e592cdfe3724fb5f412f273fad913c1 Mon Sep 17 00:00:00 2001 From: Shaverdova Elena Date: Tue, 6 Aug 2019 15:35:48 +0200 Subject: [PATCH 06/19] Redis.hLen may return false if the key doesn't exist or isn't a hash --- src/Redis.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Redis.php b/src/Redis.php index b60dc8e..15beb43 100644 --- a/src/Redis.php +++ b/src/Redis.php @@ -3594,7 +3594,7 @@ public function hGet($key, $hashKey) * * @param string $key * - * @return int the number of items in a hash, FALSE if the key doesn't exist or isn't a hash + * @return int|false the number of items in a hash, FALSE if the key doesn't exist or isn't a hash * * @link https://redis.io/commands/hlen * @example From d548931de416c8e4d5cc8c69a0d5f87324a4d765 Mon Sep 17 00:00:00 2001 From: Shaverdova Elena Date: Tue, 6 Aug 2019 16:34:09 +0200 Subject: [PATCH 07/19] Redis.sscan has string $pattern parameter --- src/Redis.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Redis.php b/src/Redis.php index b60dc8e..ea36f97 100644 --- a/src/Redis.php +++ b/src/Redis.php @@ -1855,7 +1855,7 @@ public function sGetMembers($key) * * @param string $key The set to search. * @param int $iterator LONG (reference) to the iterator as we go. - * @param null $pattern String, optional pattern to match against. + * @param string $pattern String, optional pattern to match against. * @param int $count How many members to return at a time (Redis might return a different amount) * * @return array|bool PHPRedis will return an array of keys or FALSE when we're done iterating From b6cc293e9f5235d14c879e3d7e1459aa24c90c2e Mon Sep 17 00:00:00 2001 From: Shaverdova Elena Date: Tue, 6 Aug 2019 16:46:36 +0200 Subject: [PATCH 08/19] Provide parameter types for Redis.zUnion --- src/Redis.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Redis.php b/src/Redis.php index b60dc8e..4561e23 100644 --- a/src/Redis.php +++ b/src/Redis.php @@ -3388,10 +3388,10 @@ public function zUnionStore($output, $zSetKeys, array $weights = null, $aggregat * @see zUnionStore * @deprecated use Redis::zUnionStore() * - * @param $Output - * @param $ZSetKeys + * @param string $Output + * @param array $ZSetKeys * @param array|null $Weights - * @param string $aggregateFunction + * @param string $aggregateFunction */ public function zUnion($Output, $ZSetKeys, array $Weights = null, $aggregateFunction = 'SUM') { From 6e9f6d8ce029cd8bf6e19b2e81da87d785d731b9 Mon Sep 17 00:00:00 2001 From: Natsimhan <5631475+natsimhan@users.noreply.github.com> Date: Wed, 7 Aug 2019 06:56:41 +0200 Subject: [PATCH 09/19] Fixed in the example the use of SCAN function The example of using SCAN did not work properly if $pattern was used. If we do not test the return is FALSE (end of scan) and we used $pattern (Redis MATCH option) the scan function can return empty lists because of the way it works, but we still have to keep going through the list until the function returns FALSE. More information on this feature of Redis in the doc with the MATCH option: https://redis.io/commands/scan#the-match-option --- src/Redis.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Redis.php b/src/Redis.php index 4226975..8e5a778 100644 --- a/src/Redis.php +++ b/src/Redis.php @@ -4548,7 +4548,7 @@ public function time() * @example *
      * $iterator = null;
-     * while($keys = $redis->scan($iterator)) {
+     * while(false !== ($keys = $redis->scan($iterator))) {
      *     foreach($keys as $key) {
      *         echo $key . PHP_EOL;
      *     }

From ad0be299ff9c014a49fb702d77d97e693e147c35 Mon Sep 17 00:00:00 2001
From: Shaverdova Elena 
Date: Thu, 8 Aug 2019 16:09:52 +0200
Subject: [PATCH 10/19] Redis.multi returns Redis

---
 src/Redis.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/Redis.php b/src/Redis.php
index 4561e23..dbb380f 100644
--- a/src/Redis.php
+++ b/src/Redis.php
@@ -571,7 +571,7 @@ public function unlink($key1, $key2 = null, $key3 = null)
      * a Redis::PIPELINE block is simply transmitted faster to the server, but without any guarantee of atomicity.
      * discard cancels a transaction.
      *
-     * @return resource Redis returns the Redis instance and enters multi-mode.
+     * @return Redis returns the Redis instance and enters multi-mode.
      * Once in multi-mode, all subsequent method calls return the same object until exec() is called.
      *
      * @link    https://redis.io/commands/multi

From 5c1b39e0ef98f0f6b059404cc3c8bbc42a93816a Mon Sep 17 00:00:00 2001
From: Maksim Kamashev 
Date: Sat, 10 Aug 2019 00:21:12 +0300
Subject: [PATCH 11/19] Change false to bool

---
 src/Redis.php | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/Redis.php b/src/Redis.php
index bfb384d..55eab0a 100644
--- a/src/Redis.php
+++ b/src/Redis.php
@@ -3594,7 +3594,7 @@ public function hGet($key, $hashKey)
      *
      * @param string $key
      *
-     * @return int|false the number of items in a hash, FALSE if the key doesn't exist or isn't a hash
+     * @return int|bool the number of items in a hash, FALSE if the key doesn't exist or isn't a hash
      *
      * @link    https://redis.io/commands/hlen
      * @example
@@ -3617,7 +3617,7 @@ public function hLen($key)
      * @param string $hashKey1
      * @param string ...$otherHashKeys
      *
-     * @return int|false Number of deleted fields
+     * @return int|bool Number of deleted fields
      *
      * @link    https://redis.io/commands/hdel
      * @example

From 6f8a208474f13edca19188d57dc249714b400e2b Mon Sep 17 00:00:00 2001
From: Jeff Standen 
Date: Fri, 13 Sep 2019 13:23:35 -0700
Subject: [PATCH 12/19] Fixed a typo in the Redis.sRandMember var_dump() output

---
 src/Redis.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/Redis.php b/src/Redis.php
index 55eab0a..e68e820 100644
--- a/src/Redis.php
+++ b/src/Redis.php
@@ -1569,7 +1569,7 @@ public function sPop($key)
      *
      * // array(2) {
      * //   [0]=> string(2) "one"
-     * //   [1]=> string(2) "three"
+     * //   [1]=> string(5) "three"
      * // }
      * 
*/ From 9768f40a5a06f9b9125ffd1fd5f341d7dfcedb9b Mon Sep 17 00:00:00 2001 From: Jeff Standen Date: Fri, 13 Sep 2019 13:19:30 -0700 Subject: [PATCH 13/19] Redis.sPop may include an optional $count parameter --- src/Redis.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Redis.php b/src/Redis.php index 55eab0a..38a25a6 100644 --- a/src/Redis.php +++ b/src/Redis.php @@ -1527,8 +1527,9 @@ public function sCard($key) * Removes and returns a random element from the set value at Key. * * @param string $key + * @param int $count [optional] * - * @return string|mixed|bool "popped" value + * @return string|mixed|array|bool "popped" values * bool FALSE if set identified by key is empty or doesn't exist. * * @link https://redis.io/commands/spop @@ -1539,9 +1540,19 @@ public function sCard($key) * $redis->sAdd('key1' , 'set3'); // 'key1' => {'set3', 'set1', 'set2'} * $redis->sPop('key1'); // 'set1', 'key1' => {'set3', 'set2'} * $redis->sPop('key1'); // 'set3', 'key1' => {'set2'} + * + * // With count + * $redis->sAdd('key2', 'set1', 'set2', 'set3'); + * var_dump( $redis->sPop('key2', 3) ); // Will return all members but in no particular order + * + * // array(3) { + * // [0]=> string(4) "set2" + * // [1]=> string(4) "set3" + * // [2]=> string(4) "set1" + * // } * */ - public function sPop($key) + public function sPop($key, $count = 1) { } From 2779cfc9a1037b2a46b014e3fb0dbd040b951885 Mon Sep 17 00:00:00 2001 From: Alexander Schranz Date: Mon, 14 Oct 2019 22:42:49 +0200 Subject: [PATCH 14/19] Update Docs --- src/Redis.php | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/Redis.php b/src/Redis.php index 8b7b3e2..3b3f72d 100644 --- a/src/Redis.php +++ b/src/Redis.php @@ -3537,6 +3537,52 @@ public function bzPopMin($key1, $key2, $timeout) { } + /** + * Can pop the highest scoring members from one ZSET. + * + * @param string $key + * @param int $count + * + * @return array Either an array with the key member and score of the highest element or an empty array + * if there is no element to pop. + * + * @since >= 5.0 + * @link https://redis.io/commands/zpopmax + * @example + *
+     * // Pop the *lowest* scoring member from set `zs1`.
+     * $redis->zPopMax('zs1');
+     * // Pop the *lowest* 3 scoring member from set `zs1`.
+     * $redis->zPopMax('zs1', 3);
+     * 
+ */ + public function zPopMax($key, $count = 1) + { + } + + /** + * Can pop the lowest scoring members from one ZSET. + * + * @param string $key + * @param int $count + * + * @return array Either an array with the key member and score of the lowest element or an empty array + * if there is no element to pop. + * + * @since >= 5.0 + * @link https://redis.io/commands/zpopmin + * @example + *
+     * // Pop the *lowest* scoring member from set `zs1`.
+     * $redis->zPopMin('zs1');
+     * // Pop the *lowest* 3 scoring member from set `zs1`.
+     * $redis->zPopMin('zs1', 3);
+     * 
+ */ + public function zPopMin($key, $count = 1) + { + } + /** * Adds a value to the hash stored at key. If this value is already in the hash, FALSE is returned. * From 06407d351046c2bbf2268310d2ed746b5beca2aa Mon Sep 17 00:00:00 2001 From: Aleksandr Fedotov Date: Sun, 24 May 2020 23:19:01 +0300 Subject: [PATCH 15/19] Add new constants --- src/Redis.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/Redis.php b/src/Redis.php index 3b3f72d..a46dab4 100644 --- a/src/Redis.php +++ b/src/Redis.php @@ -19,6 +19,10 @@ class Redis const OPT_READ_TIMEOUT = 3; const OPT_SCAN = 4; const OPT_SLAVE_FAILOVER = 5; + const OPT_TCP_KEEPALIVE = 6; + const OPT_COMPRESSION = 7; + const OPT_REPLY_LITERAL = 8; + const OPT_COMPRESSION_LEVEL = 9; /** * Cluster options @@ -42,6 +46,20 @@ class Redis const SERIALIZER_MSGPACK = 3; const SERIALIZER_JSON = 4; + /** + * Compressions + */ + const COMPRESSION_NONE = 0; + const COMPRESSION_LZF = 1; + const COMPRESSION_ZSTD = 2; + + /** + * Compression ZSTD levels + */ + const COMPRESSION_ZSTD_MIN = 1; + const COMPRESSION_ZSTD_DEFAULT = 3; + const COMPRESSION_ZSTD_MAX = 22; + /** * Multi */ @@ -58,6 +76,7 @@ class Redis const REDIS_LIST = 3; const REDIS_ZSET = 4; const REDIS_HASH = 5; + const REDIS_STREAM = 6; /** * Creates a Redis client From 73979d40731b9927f7b7ccf55eeb33cfc6ffadf0 Mon Sep 17 00:00:00 2001 From: Maximilian Schirmer Date: Tue, 13 Oct 2020 13:57:10 +0200 Subject: [PATCH 16/19] Add COMPRESSION_LZ4 constant Available as of 5.3.0 (https://github.com/phpredis/phpredis/releases/tag/5.3.0) --- src/Redis.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Redis.php b/src/Redis.php index a46dab4..7fd34c7 100644 --- a/src/Redis.php +++ b/src/Redis.php @@ -52,6 +52,7 @@ class Redis const COMPRESSION_NONE = 0; const COMPRESSION_LZF = 1; const COMPRESSION_ZSTD = 2; + const COMPRESSION_LZ4 = 3; /** * Compression ZSTD levels From 08a92fa98fc61378c0cf026fb0bd63c8412c6c24 Mon Sep 17 00:00:00 2001 From: Serhii Zarva Date: Fri, 22 Jan 2021 10:36:52 +0100 Subject: [PATCH 17/19] Add SCAN_PREFIX and SCAN_NOPREFIX Since version 5.3.0RC1 the new parameters are supported. https://github.com/phpredis/phpredis/commit/e80600e244b8442cb7c86e99b067966cd59bf2ee --- src/Redis.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Redis.php b/src/Redis.php index 7fd34c7..1405338 100644 --- a/src/Redis.php +++ b/src/Redis.php @@ -36,6 +36,8 @@ class Redis */ const SCAN_NORETRY = 0; const SCAN_RETRY = 1; + const SCAN_PREFIX = 2; + const SCAN_NOPREFIX = 3; /** * Serializers From 35ac1e31db3967bdf65fd88abac717772d13f361 Mon Sep 17 00:00:00 2001 From: Adrien Cantepie Date: Sat, 20 Feb 2021 15:56:25 +0100 Subject: [PATCH 18/19] Update auth phpDoc --- src/Redis.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Redis.php b/src/Redis.php index 1405338..dd0016d 100644 --- a/src/Redis.php +++ b/src/Redis.php @@ -2188,15 +2188,19 @@ public function dbSize() } /** - * Authenticate the connection using a password. + * Authenticate the connection using a password or a username and password.. * Warning: The password is sent in plain-text over the network. * - * @param string $password + * @param mixed $password * * @return bool TRUE if the connection is authenticated, FALSE otherwise * * @link https://redis.io/commands/auth - * @example $redis->auth('foobared'); + * @example + *
+     * $redis->auth('bar'); // Authenticate with the password 'bar'
+     * $redis->auth(['user' => 'foo', 'pass' => 'bar]); // Authenticate with the username 'foo', and password 'bar' 
+     * 
*/ public function auth($password) { From cdf07b55dca57a5f149a26aa0a51cc2f80a01b27 Mon Sep 17 00:00:00 2001 From: gongwen Date: Fri, 7 May 2021 22:12:18 +0800 Subject: [PATCH 19/19] Fixed in the example the use of Redis.zAdd --- src/Redis.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Redis.php b/src/Redis.php index dd0016d..145d673 100644 --- a/src/Redis.php +++ b/src/Redis.php @@ -2951,7 +2951,7 @@ public function brpoplpush($srcKey, $dstKey, $timeout) * @example *
      * 
-     * $redis->zAdd('z', 1, 'v1', 2, 'v2', 3, 'v3', 4, 'v4' );  // int(2)
+     * $redis->zAdd('z', 1, 'v1', 2, 'v2', 3, 'v3', 4, 'v4' );  // int(4)
      * $redis->zRem('z', 'v2', 'v3');                           // int(2)
      * $redis->zAdd('z', ['NX'], 5, 'v5');                      // int(1)
      * $redis->zAdd('z', ['NX'], 6, 'v5');                      // int(0)