diff --git a/src/Redis.php b/src/Redis.php index bb290d1..65b4d54 100644 --- a/src/Redis.php +++ b/src/Redis.php @@ -31,14 +31,30 @@ */ class Redis { - const AFTER = ''; - const BEFORE = ''; + const AFTER = 'after'; + const BEFORE = 'before'; /** * Options */ const OPT_SERIALIZER = 1; const OPT_PREFIX = 2; + const OPT_READ_TIMEOUT = 3; + const OPT_SCAN = 4; + const OPT_SLAVE_FAILOVER = 5; + + /** + * Cluster options + */ + const FAILOVER_NONE = 0; + const FAILOVER_ERROR = 1; + const FAILOVER_DISTRIBUTE = 2; + + /** + * SCAN options + */ + const SCAN_NORETRY = 0; + const SCAN_RETRY = 1; /** * Serializers @@ -50,8 +66,9 @@ class Redis /** * Multi */ - const MULTI = 0; - const PIPELINE = 1; + const ATOMIC = 0; + const MULTI = 1; + const PIPELINE = 2; /** * Type @@ -321,6 +338,7 @@ public function unwatch( ) {} * @param array $channels an array of channels to subscribe to * @param string | array $callback either a string or an array($instance, 'method_name'). * The callback function receives 3 parameters: the redis instance, the channel name, and the message. + * @return mixed Any non-null return value in the callback will be returned to the caller. * @link http://redis.io/commands/subscribe * @example *
@@ -351,6 +369,7 @@ public function subscribe( $channels, $callback ) {}
* @param array $patterns The number of elements removed from the set.
* @param string|array $callback Either a string or an array with an object and method.
* The callback will get four arguments ($redis, $pattern, $channel, $message)
+ * @param mixed Any non-null return value in the callback will be returned to the caller.
* @link http://redis.io/commands/psubscribe
* @example
*
@@ -374,6 +393,28 @@ public function psubscribe( $patterns, $callback ) {}
*/
public function publish( $channel, $message ) {}
+ /**
+ * A command allowing you to get information on the Redis pub/sub system.
+ * @param string $keyword String, which can be: "channels", "numsub", or "numpat"
+ * @param string|array $argument Optional, variant.
+ * For the "channels" subcommand, you can pass a string pattern.
+ * For "numsub" an array of channel names
+ * @return array|int Either an integer or an array.
+ * - channels Returns an array where the members are the matching channels.
+ * - numsub Returns a key/value array where the keys are channel names and
+ * values are their counts.
+ * - numpat Integer return containing the number active pattern subscriptions.
+ * @link http://redis.io/commands/pubsub
+ * @example
+ *
+ * $redis->pubsub('channels'); // All channels
+ * $redis->pubsub('channels', '*pattern*'); // Just channels matching your pattern
+ * $redis->pubsub('numsub', array('chan1', 'chan2')); // Get subscriber counts for 'chan1' and 'chan2'
+ * $redis->pubsub('numpat'); // Get the number of pattern subscribers
+ *
+ */
+ public function pubsub( $keyword, $argument ) {}
+
/**
* Verify if the specified key exists.
*
@@ -1318,6 +1359,26 @@ public function sMembers( $key ) {}
*/
public function sGetMembers( $key ) {}
+ /**
+ * Scan a set for members.
+ * @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 int $count How many members to return at a time (Redis might return a different amount).
+ * @return array PHPRedis will return an array of keys or FALSE when we're done iterating.
+ * @link http://redis.io/commands/sscan
+ * @example
+ *
+ * $iterator = null;
+ * while ($members = $redis->sScan('set', $iterator)) {
+ * foreach ($members as $member) {
+ * echo $member . PHP_EOL;
+ * }
+ * }
+ *
+ */
+ public function sScan( $key, &$iterator, $pattern = null, $count = 0 ) {}
+
/**
* Sets a value and returns the previous entry at that key.
*
@@ -1626,6 +1687,17 @@ public function bgsave( ) {}
*/
public function lastSave( ) {}
+ /**
+ * Blocks the current client until all the previous write commands are successfully transferred and
+ * acknowledged by at least the specified number of slaves.
+ * @param int $numSlaves Number of slaves that need to acknowledge previous write commands.
+ * @param int $timeout Timeout in milliseconds.
+ * @return int The command returns the number of slaves reached by all the writes performed in the
+ * context of the current connection.
+ * @link http://redis.io/commands/wait
+ * @example $redis->wait(2, 1000);
+ */
+ public function wait( $numSlaves, $timeout ) {}
/**
* Returns the type of data pointed by a given key.
@@ -1722,6 +1794,38 @@ public function setRange( $key, $offset, $value ) {}
*/
public function strlen( $key ) {}
+ /**
+ * Return the position of the first bit set to 1 or 0 in a string. The position is returned, thinking of the
+ * string as an array of bits from left to right, where the first byte's most significant bit is at position 0,
+ * the second byte's most significant bit is at position 8, and so forth.
+ * @param string $key
+ * @param int $bit
+ * @param int $start
+ * @param int $end
+ * @return int The command returns the position of the first bit set to 1 or 0 according to the request.
+ * If we look for set bits (the bit argument is 1) and the string is empty or composed of just
+ * zero bytes, -1 is returned. If we look for clear bits (the bit argument is 0) and the string
+ * only contains bit set to 1, the function returns the first bit not part of the string on the
+ * right. So if the string is three bytes set to the value 0xff the command BITPOS key 0 will
+ * return 24, since up to bit 23 all the bits are 1. Basically, the function considers the right
+ * of the string as padded with zeros if you look for clear bits and specify no range or the
+ * start argument only. However, this behavior changes if you are looking for clear bits and
+ * specify a range with both start and end. If no clear bit is found in the specified range, the
+ * function returns -1 as the user specified a clear range and there are no 0 bits in that range.
+ * @link http://redis.io/commands/bitpos
+ * @example
+ *
+ * $redis->set('key', '\xff\xff');
+ * $redis->bitpos('key', 1); // int(0)
+ * $redis->bitpos('key', 1, 1); // int(8)
+ * $redis->bitpos('key', 1, 3); // int(-1)
+ * $redis->bitpos('key', 0); // int(16)
+ * $redis->bitpos('key', 0, 1); // int(16)
+ * $redis->bitpos('key', 0, 1, 5); // int(-1)
+ *
+ */
+ public function bitpos( $key, $bit, $start = 0, $end = null) {}
+
/**
* Return a single bit out of a larger string
*
@@ -2220,6 +2324,43 @@ public function zRangeByScore( $key, $start, $end, array $options = array() ) {}
*/
public function zRevRangeByScore( $key, $start, $end, array $options = array() ) {}
+ /**
+ * Returns a lexigraphical range of members in a sorted set, assuming the members have the same score. The
+ * min and max values are required to start with '(' (exclusive), '[' (inclusive), or be exactly the values
+ * '-' (negative inf) or '+' (positive inf). The command must be called with either three *or* five
+ * arguments or will return FALSE.
+ * @param string $key The ZSET you wish to run against.
+ * @param int $min The minimum alphanumeric value you wish to get.
+ * @param int $max The maximum alphanumeric value you wish to get.
+ * @param int $offset Optional argument if you wish to start somewhere other than the first element.
+ * @param int $limit Optional argument if you wish to limit the number of elements returned.
+ * @return array Array containing the values in the specified range.
+ * @link http://redis.io/commands/zrangebylex
+ * @example
+ *
+ * foreach (array('a', 'b', 'c', 'd', 'e', 'f', 'g') as $char) {
+ * $redis->zAdd('key', $char);
+ * }
+ *
+ * $redis->zRangeByLex('key', '-', '[c'); // array('a', 'b', 'c')
+ * $redis->zRangeByLex('key', '-', '(c'); // array('a', 'b')
+ * $redis->zRangeByLex('key', '-', '[c'); // array('b', 'c')
+ *
+ */
+ public function zRangeByLex( $key, $min, $max, $offset = null, $limit = null ) {}
+
+ /**
+ * @see zRangeByLex()
+ * @param string $key
+ * @param int $min
+ * @param int $max
+ * @param int $offset
+ * @param int $limit
+ * @return array
+ * @link http://redis.io/commands/zrevrangebylex
+ */
+ public function zRevRangeByLex( $key, $min, $max, $offset = null, $limit = null ) {}
+
/**
* Returns the number of elements of the sorted set stored at the specified key which have
* scores in the range [start,end]. Adding a parenthesis before start or end excludes it
@@ -2461,6 +2602,26 @@ public function zUnion($Output, $ZSetKeys, array $Weights = null, $aggregateFunc
*/
public function zInter($Output, $ZSetKeys, array $Weights = null, $aggregateFunction = 'SUM') {}
+ /**
+ * Scan a sorted set for members, with optional pattern and count.
+ * @param string $key String, the set to scan.
+ * @param int $iterator Long (reference), initialized to NULL.
+ * @param string $pattern String (optional), the pattern to match.
+ * @param int $count How many keys to return per iteration (Redis might return a different number).
+ * @return array PHPRedis will return matching keys from Redis, or FALSE when iteration is complete.
+ * @link http://redis.io/commands/zscan
+ * @example
+ *
+ * $iterator = null;
+ * while ($members = $redis-zscan('zset', $iterator)) {
+ * foreach ($members as $member => $score) {
+ * echo $member . ' => ' . $score . PHP_EOL;
+ * }
+ * }
+ *
+ */
+ public function zScan( $key, &$iterator, $pattern = null, $count = 0 ) {}
+
/**
* Adds a value to the hash stored at key. If this value is already in the hash, FALSE is returned.
*
@@ -2749,6 +2910,27 @@ public function hMset( $key, $hashKeys ) {}
*/
public function hMGet( $key, $hashKeys ) {}
+ /**
+ * Scan a HASH value for members, with an optional pattern and count.
+ * @param string $key
+ * @param int $iterator
+ * @param string $pattern Optional pattern to match against.
+ * @param int $count How many keys to return in a go (only a sugestion to Redis).
+ * @return array An array of members that match our pattern.
+ * @link http://redis.io/commands/hscan
+ * @example
+ *
+ * // $iterator = null;
+ * // while($elements = $redis->hscan('hash', $iterator)) {
+ * // foreach($elements as $key => $value) {
+ * // echo $key . ' => ' . $value . PHP_EOL;
+ * // }
+ * // }
+ *
+ */
+ public function hScan( $key, &$iterator, $pattern = null, $count = 0 ) {}
+
+
/**
* Get or Set the redis config keys.
*
@@ -2882,6 +3064,26 @@ public function _prefix( $value ) {}
*/
public function _unserialize( $value ) {}
+ /**
+ * A utility method to serialize values manually. This method allows you to serialize a value with whatever
+ * serializer is configured, manually. This can be useful for serialization/unserialization of data going in
+ * and out of EVAL commands as phpredis can't automatically do this itself. Note that if no serializer is
+ * set, phpredis will change Array values to 'Array', and Objects to 'Object'.
+ * @param mixed $value The value to be serialized.
+ * @return mixed
+ * @example
+ *
+ * $redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_NONE);
+ * $redis->_serialize("foo"); // returns "foo"
+ * $redis->_serialize(Array()); // Returns "Array"
+ * $redis->_serialize(new stdClass()); // Returns "Object"
+ *
+ * $redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP);
+ * $redis->_serialize("foo"); // Returns 's:3:"foo";'
+ *
+ */
+ public function _serialize( $value ) {}
+
/**
* Dump a key out of a redis database, the value of which can later be passed into redis using the RESTORE command.
* The data that comes out of DUMP is a binary representation of the key as Redis stores it.
@@ -2921,6 +3123,8 @@ public function restore( $key, $ttl, $value ) {}
* @param string $key The key to migrate.
* @param int $db The target DB.
* @param int $timeout The maximum amount of time given to this transfer.
+ * @param bool $copy Should we send the COPY flag to redis.
+ * @param bool $replace Should we send the REPLACE flag to redis.
* @return bool
* @link http://redis.io/commands/migrate
* @example
@@ -2928,7 +3132,7 @@ public function restore( $key, $ttl, $value ) {}
* $redis->migrate('backup', 6379, 'foo', 0, 3600);
*
*/
- public function migrate( $host, $port, $key, $db, $timeout ) {}
+ public function migrate( $host, $port, $key, $db, $timeout, $copy = false, $replace = false ) {}
/**
* Return the current Redis server time.
@@ -2945,6 +3149,86 @@ public function migrate( $host, $port, $key, $db, $timeout ) {}
*
*/
public function time() {}
+
+ /**
+ * Scan the keyspace for keys.
+ * @param int $iterator Iterator, initialized to NULL.
+ * @param string $pattern Pattern to match.
+ * @param int $count Count of keys per iteration (only a suggestion to Redis).
+ * @return array This function will return an array of keys or FALSE if there are no more keys.
+ * @link http://redis.io/commands/scan
+ * @example
+ *
+ * $iterator = null;
+ * while($keys = $redis->scan($iterator)) {
+ * foreach($keys as $key) {
+ * echo $key . PHP_EOL;
+ * }
+ * }
+ *
+ */
+ public function scan( &$iterator, $pattern = null, $count = 0 ) {}
+
+ /**
+ * Adds all the element arguments to the HyperLogLog data structure stored at the key.
+ * @param string $key
+ * @param array $elements
+ * @return bool
+ * @link http://redis.io/commands/pfadd
+ * @example $redis->pfAdd('key', array('elem1', 'elem2'))
+ */
+ public function pfAdd( $key, array $elements ) {}
+
+ /**
+ * When called with a single key, returns the approximated cardinality computed by the HyperLogLog data
+ * structure stored at the specified variable, which is 0 if the variable does not exist.
+ * @param string|array $key
+ * @return int
+ * @link http://redis.io/commands/pfcount
+ * @example
+ *
+ * $redis->pfAdd('key1', array('elem1', 'elem2'));
+ * $redis->pfAdd('key2', array('elem3', 'elem2'));
+ * $redis->pfCount('key1'); // int(2)
+ * $redis->pfCount(array('key1', 'key2')); // int(3)
+ */
+ public function pfCount( $key ) {}
+
+ /**
+ * Merge multiple HyperLogLog values into an unique value that will approximate the cardinality
+ * of the union of the observed Sets of the source HyperLogLog structures.
+ * @param string $destkey
+ * @param array $sourcekeys
+ * @return bool
+ * @link http://redis.io/commands/pfmerge
+ * @example
+ *
+ * $redis->pfAdd('key1', array('elem1', 'elem2'));
+ * $redis->pfAdd('key2', array('elem3', 'elem2'));
+ * $redis->pfMerge('key3', array('key1', 'key2'));
+ * $redis->pfCount('key3'); // int(3)
+ */
+ public function pfMerge( $destkey, array $sourcekeys ) {}
+
+ /**
+ * Send arbitrary things to the redis server.
+ * @param string $command Required command to send to the server.
+ * @param mixed,... $arguments Optional variable amount of arguments to send to the server.
+ * @return mixed
+ * @example
+ *
+ * $redis->rawCommand('SET', 'key', 'value'); // bool(true)
+ * $redis->rawCommand('GET", 'key'); // string(5) "value"
+ *
+ */
+ public function rawCommand( $command, $arguments ) {}
+
+ /**
+ * Detect whether we're in ATOMIC/MULTI/PIPELINE mode.
+ * @return int Either Redis::ATOMIC, Redis::MULTI or Redis::PIPELINE
+ * @example $redis->getMode();
+ */
+ public function getMode() {}
}
class RedisException extends Exception {}