diff --git a/src/Redis.php b/src/Redis.php index b60dc8e..145d673 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 @@ -32,6 +36,8 @@ class Redis */ const SCAN_NORETRY = 0; const SCAN_RETRY = 1; + const SCAN_PREFIX = 2; + const SCAN_NOPREFIX = 3; /** * Serializers @@ -42,6 +48,21 @@ class Redis const SERIALIZER_MSGPACK = 3; const SERIALIZER_JSON = 4; + /** + * Compressions + */ + const COMPRESSION_NONE = 0; + const COMPRESSION_LZF = 1; + const COMPRESSION_ZSTD = 2; + const COMPRESSION_LZ4 = 3; + + /** + * Compression ZSTD levels + */ + const COMPRESSION_ZSTD_MIN = 1; + const COMPRESSION_ZSTD_DEFAULT = 3; + const COMPRESSION_ZSTD_MAX = 22; + /** * Multi */ @@ -58,6 +79,7 @@ class Redis const REDIS_LIST = 3; const REDIS_ZSET = 4; const REDIS_HASH = 5; + const REDIS_STREAM = 6; /** * Creates a Redis client @@ -571,7 +593,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 @@ -777,7 +799,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 @@ -1527,8 +1549,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 +1562,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) { } @@ -1569,7 +1602,7 @@ public function sPop($key) * * // array(2) { * // [0]=> string(2) "one" - * // [1]=> string(2) "three" + * // [1]=> string(5) "three" * // } * */ @@ -1855,7 +1888,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 @@ -2155,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) { @@ -2914,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)
@@ -3388,10 +3425,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')
     {
@@ -3518,7 +3555,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
      */
@@ -3526,6 +3563,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. * @@ -3594,7 +3677,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|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 +3700,7 @@ public function hLen($key) * @param string $hashKey1 * @param string ...$otherHashKeys * - * @return int Number of deleted fields + * @return int|bool Number of deleted fields * * @link https://redis.io/commands/hdel * @example @@ -4388,7 +4471,7 @@ public function clearLastError() * $redis->client('kill', ); // Kill the process at ip:port *
*/ - public function client($command, $value) + public function client($command, $value = '') { } @@ -4548,7 +4631,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;
      *     }
@@ -4932,6 +5015,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