class RedisCluster (View source)

Helper autocomplete for php redis cluster extension.

Constants

OPT_SLAVE_FAILOVER

Options

FAILOVER_NONE

Cluster options

FAILOVER_ERROR

FAILOVER_DISTRIBUTE

FAILOVER_DISTRIBUTE_SLAVES

Methods

__construct(string|null $name, array|null $seeds = null, int|float $timeout = 0, int|float $read_timeout = 0, bool $persistent = false, mixed $auth = null, array|null $context = null)

Creates a Redis Cluster client

bool
close()

Disconnects from the RedisCluster instance, except when pconnect is used.

mixed
get(string $key)

Get the value related to the specified key

RedisCluster|string|bool
set(string $key, mixed $value, mixed $options = null)

Set the string value in argument as value of the key.

RedisCluster|array|false
mget(array $keys)

Returns the values of all specified keys.

RedisCluster|bool
mset(array $key_values)

Sets multiple key-value pairs in one atomic command.

RedisCluster|array|false
msetnx(array $key_values)

No description

RedisCluster|int|false
del(array|string $key, string ...$other_keys)

Remove specified keys.

RedisCluster|bool
setex(string $key, int $expire, mixed $value)

Set the string value in argument as value of the key, with a time to live.

RedisCluster|bool
psetex(string $key, int $timeout, string $value)

PSETEX works exactly like SETEX with the sole difference that the expire time is specified in milliseconds instead of seconds.

RedisCluster|bool
setnx(string $key, mixed $value)

Set the string value in argument as value of the key if the key doesn't already exist in the database.

RedisCluster|string|bool
getset(string $key, mixed $value)

Sets a value and returns the previous entry at that key.

RedisCluster|int|bool
exists(mixed $key, mixed ...$other_keys)

Verify if the specified key exists.

RedisCluster|array|false
keys(string $pattern)

Returns the keys that match a certain pattern.

RedisCluster|int|false
type(string $key)

Returns the type of data pointed by a given key.

RedisCluster|bool|string|array
lPop(string $key, int $count = 0)

Returns and removes the first element of the list.

RedisCluster|bool|string|array
rPop(string $key, int $count = 0)

Returns and removes the last element of the list.

RedisCluster|bool
lSet(string $key, int $index, mixed $value)

Set the list at index with the new value.

RedisCluster|string|array|false
sPop(string $key, int $count = 0)

Removes and returns a random element from the set value at Key.

RedisCluster|int|bool
lPush(string $key, mixed $value, mixed ...$other_values)

Adds the string values to the head (left) of the list. Creates the list if the key didn't exist.

RedisCluster|int|false
rPush(string $key, mixed ...$elements)

Adds the string values to the tail (right) of the list. Creates the list if the key didn't exist.

RedisCluster|array|null|false
blPop(string|array $key, string|float|int $timeout_or_key, mixed ...$extra_args)

BLPOP is a blocking list pop primitive.

RedisCluster|array|null|false
brPop(string|array $key, string|float|int $timeout_or_key, mixed ...$extra_args)

BRPOP is a blocking list pop primitive.

RedisCluster|bool|int
rPushx(string $key, string $value)

Adds the string value to the tail (right) of the list if the ist exists. FALSE in case of Failure.

RedisCluster|int|bool
lPushx(string $key, mixed $value)

Adds the string value to the head (left) of the list if the list exists.

RedisCluster|int|false
lInsert(string $key, string $pos, mixed $pivot, mixed $value)

Insert value in the list before or after the pivot value. the parameter options specify the position of the insert (before or after). If the list didn't exists, or the pivot didn't exists, the value is not inserted.

mixed
lindex(string $key, int $index)

Return the specified element of the list stored at the specified key.

RedisCluster|int|bool
lrem(string $key, mixed $value, int $count = 0)

Removes the first count occurrences of the value element from the list.

mixed
brpoplpush(string $srckey, string $deskey, int $timeout)

A blocking version of rpoplpush, with an integral timeout in the third parameter.

RedisCluster|bool|string
rpoplpush(string $src, string $dst)

Pops a value from the tail of a list, and pushes it to the front of another list.

RedisCluster|int|bool
lLen(string $key)

Returns the size of a list identified by Key. If the list didn't exist or is empty, the command returns 0. If the data type identified by Key is not a list, the command return FALSE.

RedisCluster|int|false
scard(string $key)

Returns the set cardinality (number of elements) of the set stored at key.

RedisCluster|array|false
sMembers(string $key)

Returns all the members of the set value stored at key.

RedisCluster|bool
sismember(string $key, mixed $value)

Returns if member is a member of the set stored at key.

RedisCluster|int|false
sAdd(string $key, mixed $value, mixed ...$other_values)

Adds a values to the set value stored at key.

RedisCluster|bool|int
sAddArray(string $key, array $values)

Adds a values to the set value stored at key.

RedisCluster|int|false
srem(string $key, mixed $value, mixed ...$other_values)

Removes the specified members from the set value stored at key.

RedisCluster|bool|array
sUnion(string $key, string ...$other_keys)

Performs the union between N sets and returns it.

RedisCluster|int|false
sUnionStore(string $dst, string $key, string ...$other_keys)

Performs the same action as sUnion, but stores the result in the first key

RedisCluster|array|false
sInter(array|string $key, string ...$other_keys)

Returns the members of a set resulting from the intersection of all the sets held at the specified keys. If just a single key is specified, then this command produces the members of this set. If one of the keys is missing, FALSE is returned.

RedisCluster|int|false
sInterStore(array|string $key, string ...$other_keys)

Performs a sInter command and stores the result in a new set.

RedisCluster|array|false
sDiff(string $key, string ...$other_keys)

Performs the difference between N sets and returns it.

RedisCluster|int|false
sDiffStore(string $dst, string $key, string ...$other_keys)

Performs the same action as sDiff, but stores the result in the first key

RedisCluster|string|array|false
sRandMember(string $key, int $count = 0)

Returns a random element(s) from the set value at Key, without removing it.

RedisCluster|int|false
strlen(string $key)

Get the length of a string value.

RedisCluster|bool
persist(string $key)

Remove the expiration timer from a key.

RedisCluster|int|false
ttl(string $key)

Returns the remaining time to live of a key that has a timeout.

RedisCluster|int|false
pttl(string $key)

Returns the remaining time to live of a key that has an expire set, with the sole difference that TTL returns the amount of remaining time in seconds while PTTL returns it in milliseconds. In Redis 2.6 or older the command returns -1 if the key does not exist or if the key exist but has no associated expire. Starting with Redis 2.8 the return value in case of error changed: Returns -2 if the key does not exist. Returns -1 if the key exists but has no associated expire.

RedisCluster|int|false
zCard(string $key)

Returns the cardinality of an ordered set.

RedisCluster|int|false
zCount(string $key, string $start, string $end)

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 from the range. +inf and -inf are also valid limits.

RedisCluster|int|false
zRemRangeByScore(string $key, string $min, string $max)

Deletes the elements of the sorted set stored at the specified key which have scores in the range [start,end].

RedisCluster|float|false
zScore(string $key, mixed $member)

Returns the score of a given member in the specified sorted set.

RedisCluster|int|float|false
zAdd(string $key, array|float $score_or_options, mixed ...$more_scores_and_mems)

Adds the specified member with a given score to the sorted set stored at key.

RedisCluster|float|false
zIncrBy(string $key, float $value, string $member)

Increments the score of a member from a sorted set by a given amount.

RedisCluster|int|false
hLen(string $key)

Returns the length of a hash, in number of items

RedisCluster|array|false
hKeys(string $key)

Returns the keys in a hash, as an array of strings.

RedisCluster|array|false
hVals(string $key)

Returns the values in a hash, as an array of strings.

mixed
hGet(string $key, string $member)

Gets a value from the hash stored at key.

RedisCluster|array|false
hGetAll(string $key)

Returns the whole hash, as an array of strings indexed by strings.

RedisCluster|bool
hExists(string $key, string $member)

Verify if the specified member exists in a key.

RedisCluster|int|false
hIncrBy(string $key, string $member, int $value)

Increments the value of a member from a hash by a given amount.

RedisCluster|int|false
hSet(string $key, string $member, mixed $value)

Adds a value to the hash stored at key. If this value is already in the hash, FALSE is returned.

RedisCluster|bool
hSetNx(string $key, string $member, mixed $value)

Adds a value to the hash stored at key only if this field isn't already in the hash.

RedisCluster|array|false
hMget(string $key, array $keys)

Retrieve the values associated to the specified fields in the hash.

RedisCluster|bool
hMset(string $key, array $key_values)

Fills in a whole hash. Non-string values are converted to string, using the standard (string) cast.

RedisCluster|int|false
hDel(string $key, string $member, string ...$other_members)

Removes a values from the hash stored at key.

RedisCluster|float|false
hIncrByFloat(string $key, string $member, float $value)

Increment the float value of a hash field by the given amount

RedisCluster|string|false
dump(string $key)

Dump a key out of a redis database, the value of which can later be passed into redis using the RESTORE command.

RedisCluster|int|false
zRank(string $key, mixed $member)

Returns the rank of a given member in the specified sorted set, starting at 0 for the item with the smallest score. zRevRank starts at 0 for the item with the largest score.

RedisCluster|int|false
zRevRank(string $key, mixed $member)

No description

RedisCluster|int|false
incr(string $key, int $by = 1)

Increment the number stored at key by one.

RedisCluster|int|false
decr(string $key, int $by = 1)

Decrement the number stored at key by one.

RedisCluster|int|false
incrBy(string $key, int $value)

Increment the number stored at key by one. If the second argument is filled, it will be used as the integer value of the increment.

RedisCluster|int|false
decrBy(string $key, int $value)

Decrement the number stored at key by one. If the second argument is filled, it will be used as the integer value of the decrement.

RedisCluster|float|false
incrByFloat(string $key, float $value)

Increment the float value of a key by the given amount

RedisCluster|bool
expire(string $key, int $timeout, string|null $mode = null)

Sets an expiration date (a timeout) on an item.

RedisCluster|bool
pexpire(string $key, int $timeout, string|null $mode = null)

Sets an expiration date (a timeout in milliseconds) on an item.

RedisCluster|bool
expireAt(string $key, int $timestamp, string|null $mode = null)

Sets an expiration date (a timestamp) on an item.

RedisCluster|bool
pexpireAt(string $key, int $timestamp, string|null $mode = null)

Sets an expiration date (a timestamp) on an item. Requires a timestamp in milliseconds

RedisCluster|bool|int
append(string $key, mixed $value)

Append specified string to the string stored in specified key.

RedisCluster|int|false
getBit(string $key, int $value)

Return a single bit out of a larger string

RedisCluster|int|false
setBit(string $key, int $offset, bool $onoff)

Changes a single bit of a string.

RedisCluster|bool|int
bitop(string $operation, string $deskey, string $srckey, string ...$otherkeys)

Bitwise operation on multiple keys.

RedisCluster|int|false
bitpos(string $key, bool $bit, int $start = 0, int $end = -1, bool $bybit = false)

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.

RedisCluster|bool|int
bitcount(string $key, int $start = 0, int $end = -1, bool $bybit = false)

Count bits in a string.

RedisCluster|string|bool
lGet(string $key, int $index)

No description

RedisCluster|string|false
getRange(string $key, int $start, int $end)

Return a substring of a larger string

RedisCluster|bool
ltrim(string $key, int $start, int $end)

Trims an existing list so that it will contain only a specified range of elements.

RedisCluster|array|false
lrange(string $key, int $start, int $end)

Returns the specified elements of the list stored at the specified key in the range [start, end]. start and stop are interpretated as indices: 0 the first element, 1 the second ... -1 the last element, -2 the penultimate .

RedisCluster|int|false
zRemRangeByRank(string $key, string $min, string $max)

Deletes the elements of the sorted set stored at the specified key which have rank in the range [start,end].

RedisCluster|bool|int
publish(string $channel, string $message)

Publish messages to channels. Warning: this function will probably change in the future.

RedisCluster|bool
rename(string $key_src, string $key_dst)

Renames a key.

RedisCluster|bool
renameNx(string $key, string $newkey)

Renames a key.

RedisCluster|int|false
pfcount(string $key)

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.

RedisCluster|bool
pfadd(string $key, array $elements)

Adds all the element arguments to the HyperLogLog data structure stored at the key.

RedisCluster|bool
pfmerge(string $key, array $keys)

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.

RedisCluster|int|false
setRange(string $key, int $offset, string $value)

Changes a substring of a larger string.

RedisCluster|bool
restore(string $key, int $timeout, string $value, array|null $options = null)

Restore a key from the result of a DUMP operation.

RedisCluster|bool
sMove(string $src, string $dst, string $member)

Moves the specified member from the set at srcKey to the set at dstKey.

RedisCluster|array|bool
zRange(string $key, mixed $start, mixed $end, array|bool|null $options = null)

Returns a range of elements from the ordered set stored at the specified key, with values in the range [start, end]. start and stop are interpreted as zero-based indices: 0 the first element, 1 the second ... -1 the last element, -2 the penultimate .

RedisCluster|bool|array
zRevRange(string $key, string $min, string $max, array|null $options = null)

Returns the elements of the sorted set stored at the specified key in the range [start, end] in reverse order. start and stop are interpretated as zero-based indices: 0 the first element, 1 the second ... -1 the last element, -2 the penultimate .

RedisCluster|array|false
zRangeByScore(string $key, string $start, string $end, array $options = [])

Returns the 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 from the range.

RedisCluster|bool|array
zRevRangeByScore(string $key, string $min, string $max, array|null $options = null)

No description

RedisCluster|array|false
zRangeByLex(string $key, string $min, string $max, int $offset = -1, int $count = -1)

Returns a range of members in a sorted set, by lexicographical range

RedisCluster|bool|array
zRevRangeByLex(string $key, string $min, string $max, array|null $options = null)

No description

RedisCluster|int|false
zLexCount(string $key, string $min, string $max)

Count the number of members in a sorted set between a given lexicographical range.

RedisCluster|int|false
zRemRangeByLex(string $key, string $min, string $max)

Remove all members in a sorted set between the given lexicographical range.

RedisCluster|int|false
zunionstore(string $dst, array $keys, array|null $weights = null, string|null $aggregate = null)

Add multiple sorted sets and store the resulting sorted set in a new key

RedisCluster|int|false
zinterstore(string $dst, array $keys, array|null $weights = null, string|null $aggregate = null)

Intersect multiple sorted sets and store the resulting sorted set in a new key

RedisCluster|int|false
zRem(string $key, string $value, string ...$other_values)

Deletes a specified member from the ordered set.

RedisCluster|array|bool|int|string
sort(string $key, array|null $options = null)

Sort

RedisCluster|int|string|false
object(string $subcommand, string $key)

Describes the object pointed to by a key.

void
subscribe(array $channels, callable $cb)

Subscribe to channels. Warning: this function will probably change in the future.

void
psubscribe(array $patterns, callable $callback)

Subscribe to channels by pattern

bool|array
unsubscribe(array $channels)

Unsubscribes the client from the given channels, or from all of them if none is given.

bool|array
punsubscribe(string $pattern, string ...$other_patterns)

Unsubscribes the client from the given patterns, or from all of them if none is given.

mixed
evalsha(string $script_sha, array $args = [], int $num_keys = 0)

Evaluate a LUA script serverside, from the SHA1 hash of the script instead of the script itself.

bool|array
scan(null|int|string $iterator, string|array $key_or_address, string|null $pattern = null, int $count = 0)

Scan the keyspace for keys.

array|false
sscan(string $key, null|int|string $iterator, string|null $pattern = null, int $count = 0)

Scan a set for members.

RedisCluster|bool|array
zscan(string $key, null|int|string $iterator, string|null $pattern = null, int $count = 0)

Scan a sorted set for members, with optional pattern and count.

array|bool
hscan(string $key, null|int|string $iterator, string|null $pattern = null, int $count = 0)

Scan a HASH value for members, with an optional pattern and count.

int
getMode()

Detect whether we're in ATOMIC/MULTI/PIPELINE mode.

string|null
getLastError()

The last error message (if any)

bool
clearLastError()

Clear the last error message

mixed
getOption(int $option)

Get client option

bool
setOption(int $option, mixed $value)

Set client option.

bool|string
_prefix(string $key)

A utility method to prefix the key with the prefix setting for phpredis.

bool|string
_serialize(mixed $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'.

mixed
_unserialize(string $value)

A utility method to unserialize data with whatever serializer is set up. If there is no serializer set, the value will be returned unchanged. If there is a serializer set up, and the data passed in is malformed, an exception will be thrown. This can be useful if phpredis is serializing values, and you return something from redis in a LUA script that is serialized.

array
_masters()

Return all redis master nodes

RedisCluster|bool
multi(int $value = Redis::MULTI)

Enter and exit transactional mode.

array|false
exec()

No description

bool
discard()

No description

RedisCluster|bool
watch(string $key, string ...$other_keys)

Watches a key for modifications by another client. If the key is modified between WATCH and EXEC, the MULTI/EXEC transaction will fail (return FALSE). unwatch cancels all the watching of all keys by this client.

bool
unwatch()

No description

RedisCluster|bool
save(string|array $key_or_address)

Performs a synchronous save at a specific node.

RedisCluster|bool
bgSave(string|array $key_or_address)

Performs a background save at a specific node.

RedisCluster|bool
flushDB(string|array $key_or_address, bool $async = false)

Removes all entries from the current database at a specific node.

RedisCluster|bool
flushAll(string|array $key_or_address, bool $async = false)

Removes all entries from all databases at a specific node.

RedisCluster|int
dbSize(string|array $key_or_address)

Returns the current database's size at a specific node.

RedisCluster|bool
bgrewriteaof(string|array $key_or_address)

Starts the background rewrite of AOF (Append-Only File) at a specific node.

RedisCluster|int|false
lastSave(string|array $key_or_address)

Returns the timestamp of the last disk save at a specific node.

RedisCluster|array|false
info(string|array $key_or_address, string ...$sections)

Returns an associative array of strings and integers

mixed
role(string|array $key_or_address)

No description

RedisCluster|bool|string
randomKey(string|array $key_or_address)

Returns a random key at the specified node

RedisCluster|bool|array
time(string|array $key_or_address)

Return the specified node server time.

mixed
ping(string|array $key_or_address, string|null $message = null)

Check the specified node status

RedisCluster|string|false
echo(string|array $key_or_address, string $msg)

Returns message.

mixed
command(mixed ...$extra_args)

Returns Array reply of details about all Redis Cluster commands.

mixed
rawcommand(string|array $key_or_address, string $command, mixed ...$args)

Send arbitrary things to the redis server at the specified node

mixed
cluster(string|array $key_or_address, string $command, mixed ...$extra_args)

Executes cluster command

array|string|bool
client(string|array $key_or_address, string $subcommand, string|null $arg = null)

Allows you to get information of the cluster client

mixed
config(string|array $key_or_address, string $subcommand, mixed ...$extra_args)

Get or Set the redis config keys.

mixed
pubsub(string|array $key_or_address, string ...$values)

A command allowing you to get information on the Redis pub/sub system.

mixed
script(string|array $key_or_address, mixed ...$args)

Execute the Redis SCRIPT command to perform various operations on the scripting subsystem.

mixed
slowlog(string|array $key_or_address, mixed ...$args)

This function is used in order to read and reset the Redis slow queries log.

RedisCluster|int|false
geoadd(string $key, float $lng, float $lat, string $member, mixed ...$other_triples_and_options)

Add one or more geospatial items in the geospatial index represented using a sorted set

RedisCluster|array|false
geohash(string $key, string $member, string ...$other_members)

Returns members of a geospatial index as standard geohash strings

RedisCluster|array|false
geopos(string $key, string $member, string ...$other_members)

Returns longitude and latitude of members of a geospatial index

RedisCluster|float|false
geodist(string $key, string $src, string $dest, string|null $unit = null)

Returns the distance between two members of a geospatial index

mixed
georadius(string $key, float $lng, float $lat, float $radius, string $unit, array $options = [])

Query a sorted set representing a geospatial index to fetch members matching a given maximum distance from a point

mixed
georadiusbymember(string $key, string $member, float $radius, string $unit, array $options = [])

Query a sorted set representing a geospatial index to fetch members matching a given maximum distance from a member

string
_compress(string $value)

No description

string
_uncompress(string $value)

No description

string
_pack(mixed $value)

No description

mixed
_unpack(string $value)

No description

string|null
_redir()

No description

mixed
acl(string|array $key_or_address, string $subcmd, string ...$args)

No description

RedisCluster|array|false
waitaof(string|array $key_or_address, int $numlocal, int $numreplicas, int $timeout)

No description

Redis|string|false
lMove(string $src, string $dst, string $wherefrom, string $whereto)

No description

Redis|string|false
blmove(string $src, string $dst, string $wherefrom, string $whereto, float $timeout)

No description

array
bzPopMax(string|array $key, string|int $timeout_or_key, mixed ...$extra_args)

No description

array
bzPopMin(string|array $key, string|int $timeout_or_key, mixed ...$extra_args)

No description

RedisCluster|array|null|false
bzmpop(float $timeout, array $keys, string $from, int $count = 1)

No description

RedisCluster|array|null|false
zmpop(array $keys, string $from, int $count = 1)

No description

RedisCluster|array|null|false
blmpop(float $timeout, array $keys, string $from, int $count = 1)

No description

RedisCluster|array|null|false
lmpop(array $keys, string $from, int $count = 1)

No description

RedisCluster|bool
copy(string $src, string $dst, array|null $options = null)

No description

float
decrbyfloat(string $key, float $value)

No description

mixed
eval(string $script, array $args = [], int $num_keys = 0)

No description

mixed
eval_ro(string $script, array $args = [], int $num_keys = 0)

No description

mixed
evalsha_ro(string $script_sha, array $args = [], int $num_keys = 0)

No description

RedisCluster|int|bool
touch(mixed $key, mixed ...$other_keys)

No description

RedisCluster|int|false
expiretime(string $key)

No description

RedisCluster|int|false
pexpiretime(string $key)

No description

mixed
georadius_ro(string $key, float $lng, float $lat, float $radius, string $unit, array $options = [])

No description

mixed
georadiusbymember_ro(string $key, string $member, float $radius, string $unit, array $options = [])

No description

RedisCluster|array
geosearch(string $key, array|string $position, array|int|float $shape, string $unit, array $options = [])

No description

RedisCluster|array|int|false
geosearchstore(string $dst, string $src, array|string $position, array|int|float $shape, string $unit, array $options = [])

No description

mixed
getDel(string $key)

No description

RedisCluster|array|false
getWithMeta(string $key)

No description

RedisCluster|string|false
getEx(string $key, array $options = [])

No description

RedisCluster|string|array|int|false
lcs(string $key1, string $key2, array|null $options = null)

No description

array|false
getTransferredBytes()

No description

void
clearTransferredBytes()

No description

Redis|int|false
expiremember(string $key, string $field, int $ttl, string|null $unit = null)

No description

Redis|int|false
expirememberat(string $key, string $field, int $timestamp)

No description

RedisCluster|string|array
hRandField(string $key, array|null $options = null)

No description

RedisCluster|int|false
hStrLen(string $key, string $field)

No description

RedisCluster|array|false
hexpire(string $key, int $ttl, array $fields, string|null $mode = null)

No description

RedisCluster|array|false
hpexpire(string $key, int $ttl, array $fields, string|null $mode = null)

No description

RedisCluster|array|false
hexpireat(string $key, int $time, array $fields, string|null $mode = null)

No description

RedisCluster|array|false
hpexpireat(string $key, int $mstime, array $fields, string|null $mode = null)

No description

RedisCluster|array|false
httl(string $key, array $fields)

No description

RedisCluster|array|false
hpttl(string $key, array $fields)

No description

RedisCluster|array|false
hexpiretime(string $key, array $fields)

No description

RedisCluster|array|false
hpexpiretime(string $key, array $fields)

No description

RedisCluster|array|false
hpersist(string $key, array $fields)

No description

Redis|null|bool|int|array
lPos(string $key, mixed $value, array|null $options = null)

No description

RedisCluster|int|false
sintercard(array $keys, int $limit = -1)

No description

RedisCluster|array|false
sMisMember(string $key, string $member, string ...$other_members)

No description

RedisCluster|array|bool|int|string
sort_ro(string $key, array|null $options = null)

No description

RedisCluster|int|false
unlink(array|string $key, string ...$other_keys)

No description

RedisCluster|int|false
xack(string $key, string $group, array $ids)

No description

RedisCluster|string|false
xadd(string $key, string $id, array $values, int $maxlen = 0, bool $approx = false)

No description

RedisCluster|string|array|false
xclaim(string $key, string $group, string $consumer, int $min_iddle, array $ids, array $options)

No description

RedisCluster|int|false
xdel(string $key, array $ids)

No description

mixed
xgroup(string $operation, string|null $key = null, string|null $group = null, string|null $id_or_consumer = null, bool $mkstream = false, int $entries_read = -2)

No description

RedisCluster|bool|array
xautoclaim(string $key, string $group, string $consumer, int $min_idle, string $start, int $count = -1, bool $justid = false)

No description

mixed
xinfo(string $operation, string|null $arg1 = null, string|null $arg2 = null, int $count = -1)

No description

RedisCluster|int|false
xlen(string $key)

No description

RedisCluster|array|false
xpending(string $key, string $group, string|null $start = null, string|null $end = null, int $count = -1, string|null $consumer = null)

No description

RedisCluster|bool|array
xrange(string $key, string $start, string $end, int $count = -1)

No description

RedisCluster|bool|array
xread(array $streams, int $count = -1, int $block = -1)

No description

RedisCluster|bool|array
xreadgroup(string $group, string $consumer, array $streams, int $count = 1, int $block = 1)

No description

RedisCluster|bool|array
xrevrange(string $key, string $start, string $end, int $count = -1)

No description

RedisCluster|int|false
xtrim(string $key, int $maxlen, bool $approx = false, bool $minid = false, int $limit = -1)

No description

RedisCluster|int|false
zintercard(array $keys, int $limit = -1)

No description

RedisCluster|bool|array
zPopMax(string $key, int|null $value = null)

No description

RedisCluster|bool|array
zPopMin(string $key, int|null $value = null)

No description

RedisCluster|int|false
zrangestore(string $dstkey, string $srckey, int $start, int $end, array|bool|null $options = null)

No description

RedisCluster|string|array
zRandMember(string $key, array|null $options = null)

No description

Redis|array|false
zMscore(string $key, mixed $member, mixed ...$other_members)

No description

RedisCluster|array|false
zinter(array $keys, array|null $weights = null, array|null $options = null)

No description

RedisCluster|int|false
zdiffstore(string $dst, array $keys)

No description

RedisCluster|array|false
zunion(array $keys, array|null $weights = null, array|null $options = null)

No description

RedisCluster|array|false
zdiff(array $keys, array|null $options = null)

No description

Details

__construct(string|null $name, array|null $seeds = null, int|float $timeout = 0, int|float $read_timeout = 0, bool $persistent = false, mixed $auth = null, array|null $context = null)

Creates a Redis Cluster client

Parameters

string|null $name
array|null $seeds
int|float $timeout
int|float $read_timeout
bool $persistent
mixed $auth
array|null $context

Exceptions

RedisClusterException

Examples

<pre>
// Declaring a cluster with an array of seeds
$redisCluster = new RedisCluster(null,['127.0.0.1:6379']);

// Loading a cluster configuration by name
// In order to load a named array, one must first define the seed nodes in redis.ini.
// The following lines would define the cluster 'mycluster', and be loaded automatically by phpredis.

// # In redis.ini
// redis.clusters.seeds = "mycluster[]=localhost:7000&test[]=localhost:7001"
// redis.clusters.timeout = "mycluster=5"
// redis.clusters.read_timeout = "mycluster=10"
// redis.clusters.auth = "mycluster=password" OR ['user' => 'foo', 'pass' => 'bar] as example

//Then, this cluster can be loaded by doing the following

$redisClusterPro = new RedisCluster('mycluster');
$redisClusterDev = new RedisCluster('test');
</pre>

bool close()

Disconnects from the RedisCluster instance, except when pconnect is used.

Return Value

bool

mixed get(string $key)

Get the value related to the specified key

Parameters

string $key

Return Value

mixed

If key didn't exist, FALSE is returned. Otherwise, the value related to this key is returned.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->get('key');
</pre>

RedisCluster|string|bool set(string $key, mixed $value, mixed $options = null)

Since: If you're using Redis >= 2.6.12, you can pass extended options as explained in example

Set the string value in argument as value of the key.

Parameters

string $key
mixed $value
mixed $options

If you pass an integer, phpredis will redirect to SETEX, and will try to use Redis

= 2.6.12 extended options if you pass an array with valid values.

Return Value

RedisCluster|string|bool

TRUE if the command is successful.

Exceptions

RedisClusterException

Examples

<pre>
// Simple key -> value set
$redisCluster->set('key', 'value');

// Will redirect, and actually make an SETEX call
$redisCluster->set('key','value', 10);

// Will set the key, if it doesn't exist, with a ttl of 10 seconds
$redisCluster->set('key', 'value', Array('nx', 'ex'=>10));

// Will set a key, if it does exist, with a ttl of 1000 milliseconds
$redisCluster->set('key', 'value', Array('xx', 'px'=>1000));
</pre>

RedisCluster|array|false mget(array $keys)

Returns the values of all specified keys.

For every key that does not hold a string value or does not exist, the special value false is returned. Because of this, the operation never fails.

Parameters

array $keys

Return Value

RedisCluster|array|false

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->del('x', 'y', 'z', 'h');    // remove x y z
$redisCluster->mset(array('x' => 'a', 'y' => 'b', 'z' => 'c'));
$redisCluster->hset('h', 'field', 'value');
var_dump($redisCluster->mget(array('x', 'y', 'z', 'h')));
// Output:
// array(3) {
// [0]=>
// string(1) "a"
// [1]=>
// string(1) "b"
// [2]=>
// string(1) "c"
// [3]=>
// bool(false)
// }
</pre>

RedisCluster|bool mset(array $key_values)

Sets multiple key-value pairs in one atomic command.

MSETNX only returns TRUE if all the keys were set (see SETNX).

Parameters

array $key_values

Pairs: array(key => value, ...)

Return Value

RedisCluster|bool

TRUE in case of success, FALSE in case of failure.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->mset(array('key0' => 'value0', 'key1' => 'value1'));
var_dump($redisCluster->get('key0'));
var_dump($redisCluster->get('key1'));
// Output:
// string(6) "value0"
// string(6) "value1"
</pre>

RedisCluster|array|false msetnx(array $key_values)

No description

Parameters

array $key_values

Return Value

RedisCluster|array|false

1 (if the keys were set) or 0 (no key was set)

Exceptions

RedisClusterException

See also

mset()

RedisCluster|int|false del(array|string $key, string ...$other_keys)

Remove specified keys.

Parameters

array|string $key
string ...$other_keys

Return Value

RedisCluster|int|false

Number of keys deleted.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->set('key1', 'val1');
$redisCluster->set('key2', 'val2');
$redisCluster->set('key3', 'val3');
$redisCluster->set('key4', 'val4');
$redisCluster->del('key1', 'key2');          // return 2
$redisCluster->del(array('key3', 'key4'));   // return 2
</pre>

RedisCluster|bool setex(string $key, int $expire, mixed $value)

Set the string value in argument as value of the key, with a time to live.

Parameters

string $key
int $expire
mixed $value

Return Value

RedisCluster|bool

TRUE if the command is successful.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->setex('key', 3600, 'value'); // sets key → value, with 1h TTL.
</pre>

RedisCluster|bool psetex(string $key, int $timeout, string $value)

PSETEX works exactly like SETEX with the sole difference that the expire time is specified in milliseconds instead of seconds.

Parameters

string $key
int $timeout
string $value

Return Value

RedisCluster|bool

TRUE if the command is successful.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->psetex('key', 1000, 'value'); // sets key → value, with 1s TTL.
</pre>

RedisCluster|bool setnx(string $key, mixed $value)

Set the string value in argument as value of the key if the key doesn't already exist in the database.

Parameters

string $key
mixed $value

Return Value

RedisCluster|bool

TRUE in case of success, FALSE in case of failure.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->setnx('key', 'value');   // return TRUE
$redisCluster->setnx('key', 'value');   // return FALSE
</pre>

RedisCluster|string|bool getset(string $key, mixed $value)

Sets a value and returns the previous entry at that key.

Parameters

string $key
mixed $value

Return Value

RedisCluster|string|bool

A string, the previous value located at this key.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->set('x', '42');
$exValue = $redisCluster->getset('x', 'lol');   // return '42', replaces x by 'lol'
$newValue = $redisCluster->get('x');            // return 'lol'
</pre>

RedisCluster|int|bool exists(mixed $key, mixed ...$other_keys)

Verify if the specified key exists.

Parameters

mixed $key
mixed ...$other_keys

Return Value

RedisCluster|int|bool

If the key exists, return TRUE, otherwise return FALSE.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->set('key', 'value');
$redisCluster->exists('key');               //  TRUE
$redisCluster->exists('NonExistingKey');    // FALSE
</pre>

RedisCluster|array|false keys(string $pattern)

Returns the keys that match a certain pattern.

Parameters

string $pattern

pattern, using '*' as a wildcard.

Return Value

RedisCluster|array|false

of STRING: The keys that match a certain pattern.

Exceptions

RedisClusterException

Examples

<pre>
$allKeys = $redisCluster->keys('*');   // all keys will match this.
$keyWithUserPrefix = $redisCluster->keys('user*');
</pre>

RedisCluster|int|false type(string $key)

Returns the type of data pointed by a given key.

Parameters

string $key

Return Value

RedisCluster|int|false

Exceptions

RedisClusterException

Examples

$redisCluster->type('key');

RedisCluster|bool|string|array lPop(string $key, int $count = 0)

Returns and removes the first element of the list.

Parameters

string $key
int $count

Return Value

RedisCluster|bool|string|array

if command executed successfully BOOL FALSE in case of failure (empty list)

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->rPush('key1', 'A');
$redisCluster->rPush('key1', 'B');
$redisCluster->rPush('key1', 'C');
var_dump( $redisCluster->lRange('key1', 0, -1) );
// Output:
// array(3) {
//   [0]=> string(1) "A"
//   [1]=> string(1) "B"
//   [2]=> string(1) "C"
// }
$redisCluster->lPop('key1');
var_dump( $redisCluster->lRange('key1', 0, -1) );
// Output:
// array(2) {
//   [0]=> string(1) "B"
//   [1]=> string(1) "C"
// }
</pre>

RedisCluster|bool|string|array rPop(string $key, int $count = 0)

Returns and removes the last element of the list.

Parameters

string $key
int $count

Return Value

RedisCluster|bool|string|array

if command executed successfully BOOL FALSE in case of failure (empty list)

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->rPush('key1', 'A');
$redisCluster->rPush('key1', 'B');
$redisCluster->rPush('key1', 'C');
var_dump( $redisCluster->lRange('key1', 0, -1) );
// Output:
// array(3) {
//   [0]=> string(1) "A"
//   [1]=> string(1) "B"
//   [2]=> string(1) "C"
// }
$redisCluster->rPop('key1');
var_dump( $redisCluster->lRange('key1', 0, -1) );
// Output:
// array(2) {
//   [0]=> string(1) "A"
//   [1]=> string(1) "B"
// }
</pre>

RedisCluster|bool lSet(string $key, int $index, mixed $value)

Set the list at index with the new value.

Parameters

string $key
int $index
mixed $value

Return Value

RedisCluster|bool

TRUE if the new value is setted. FALSE if the index is out of range, or data type identified by key

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->rPush('key1', 'A');
$redisCluster->rPush('key1', 'B');
$redisCluster->rPush('key1', 'C');  // key1 => [ 'A', 'B', 'C' ]
$redisCluster->lGet('key1', 0);     // 'A'
$redisCluster->lSet('key1', 0, 'X');
$redisCluster->lGet('key1', 0);     // 'X'
</pre>

RedisCluster|string|array|false sPop(string $key, int $count = 0)

Removes and returns a random element from the set value at Key.

Parameters

string $key
int $count

Return Value

RedisCluster|string|array|false

"popped" value, bool FALSE if set identified by key is empty or doesn't exist.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->sAdd('key1' , 'set1');
$redisCluster->sAdd('key1' , 'set2');
$redisCluster->sAdd('key1' , 'set3');
var_dump($redisCluster->sMembers('key1'));// 'key1' => {'set3', 'set1', 'set2'}
$redisCluster->sPop('key1');// 'set1'
var_dump($redisCluster->sMembers('key1'));// 'key1' => {'set3', 'set2'}
$redisCluster->sPop('key1');// 'set3',
var_dump($redisCluster->sMembers('key1'));// 'key1' => {'set2'}
</pre>

RedisCluster|int|bool lPush(string $key, mixed $value, mixed ...$other_values)

Adds the string values to the head (left) of the list. Creates the list if the key didn't exist.

If the key exists and is not a list, FALSE is returned.

Parameters

string $key
mixed $value

String, value to push in key

mixed ...$other_values

Return Value

RedisCluster|int|bool

The new length of the list in case of success, FALSE in case of Failure.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->lPush('l', 'v1', 'v2', 'v3', 'v4')   // int(4)
var_dump( $redisCluster->lRange('l', 0, -1) );
//// Output:
// array(4) {
//   [0]=> string(2) "v4"
//   [1]=> string(2) "v3"
//   [2]=> string(2) "v2"
//   [3]=> string(2) "v1"
// }
</pre>

RedisCluster|int|false rPush(string $key, mixed ...$elements)

Adds the string values to the tail (right) of the list. Creates the list if the key didn't exist.

If the key exists and is not a list, FALSE is returned.

Parameters

string $key
mixed ...$elements

Return Value

RedisCluster|int|false

The new length of the list in case of success, FALSE in case of Failure.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->rPush('r', 'v1', 'v2', 'v3', 'v4');    // int(4)
var_dump( $redisCluster->lRange('r', 0, -1) );
//// Output:
// array(4) {
//   [0]=> string(2) "v1"
//   [1]=> string(2) "v2"
//   [2]=> string(2) "v3"
//   [3]=> string(2) "v4"
// }
</pre>

RedisCluster|array|null|false blPop(string|array $key, string|float|int $timeout_or_key, mixed ...$extra_args)

BLPOP is a blocking list pop primitive.

It is the blocking version of LPOP because it blocks the connection when there are no elements to pop from any of the given lists. An element is popped from the head of the first list that is non-empty, with the given keys being checked in the order that they are given.

Parameters

string|array $key

Array containing the keys of the lists Or STRING Key1 STRING Key2 STRING Key3 ... STRING Keyn

string|float|int $timeout_or_key

Timeout or key

mixed ...$extra_args

Return Value

RedisCluster|array|null|false

array('listName', 'element')

Exceptions

RedisClusterException

Examples

<pre>
// Non blocking feature
$redisCluster->lPush('key1', 'A');
$redisCluster->del('key2');

$redisCluster->blPop('key1', 'key2', 10); // array('key1', 'A')
// OR
$redisCluster->blPop(array('key1', 'key2'), 10); // array('key1', 'A')

$redisCluster->brPop('key1', 'key2', 10); // array('key1', 'A')
// OR
$redisCluster->brPop(array('key1', 'key2'), 10); // array('key1', 'A')

// Blocking feature

// process 1
$redisCluster->del('key1');
$redisCluster->blPop('key1', 10);
// blocking for 10 seconds

// process 2
$redisCluster->lPush('key1', 'A');

// process 1
// array('key1', 'A') is returned
</pre>

RedisCluster|array|null|false brPop(string|array $key, string|float|int $timeout_or_key, mixed ...$extra_args)

BRPOP is a blocking list pop primitive.

It is the blocking version of RPOP because it blocks the connection when there are no elements to pop from any of the given lists. An element is popped from the tail of the first list that is non-empty, with the given keys being checked in the order that they are given. See the BLPOP documentation(https://redis.io/commands/blpop) for the exact semantics, since BRPOP is identical to BLPOP with the only difference being that it pops elements from the tail of a list instead of popping from the head.

Parameters

string|array $key

Array containing the keys of the lists Or STRING Key1 STRING Key2 STRING Key3 ... STRING Keyn

string|float|int $timeout_or_key

Timeout or key

mixed ...$extra_args

Return Value

RedisCluster|array|null|false

array('listName', 'element')

Exceptions

RedisClusterException

Examples

<pre>
// Non blocking feature
$redisCluster->lPush('key1', 'A');
$redisCluster->del('key2');

$redisCluster->blPop('key1', 'key2', 10); // array('key1', 'A')
// OR
$redisCluster->blPop(array('key1', 'key2'), 10); // array('key1', 'A')

$redisCluster->brPop('key1', 'key2', 10); // array('key1', 'A')
// OR
$redisCluster->brPop(array('key1', 'key2'), 10); // array('key1', 'A')

// Blocking feature

// process 1
$redisCluster->del('key1');
$redisCluster->blPop('key1', 10);
// blocking for 10 seconds

// process 2
$redisCluster->lPush('key1', 'A');

// process 1
// array('key1', 'A') is returned
</pre>

RedisCluster|bool|int rPushx(string $key, string $value)

Adds the string value to the tail (right) of the list if the ist exists. FALSE in case of Failure.

Parameters

string $key
string $value

String, value to push in key

Return Value

RedisCluster|bool|int

The new length of the list in case of success, FALSE in case of Failure.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->del('key1');
$redisCluster->rPushx('key1', 'A'); // returns 0
$redisCluster->rPush('key1', 'A'); // returns 1
$redisCluster->rPushx('key1', 'B'); // returns 2
$redisCluster->rPushx('key1', 'C'); // returns 3
// key1 now points to the following list: [ 'A', 'B', 'C' ]
</pre>

RedisCluster|int|bool lPushx(string $key, mixed $value)

Adds the string value to the head (left) of the list if the list exists.

Parameters

string $key
mixed $value

Value to push in key

Return Value

RedisCluster|int|bool

The new length of the list in case of success, FALSE in case of Failure.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->del('key1');
$redisCluster->lPushx('key1', 'A');     // returns 0
$redisCluster->lPush('key1', 'A');      // returns 1
$redisCluster->lPushx('key1', 'B');     // returns 2
$redisCluster->lPushx('key1', 'C');     // returns 3
// key1 now points to the following list: [ 'C', 'B', 'A' ]
</pre>

RedisCluster|int|false lInsert(string $key, string $pos, mixed $pivot, mixed $value)

Insert value in the list before or after the pivot value. the parameter options specify the position of the insert (before or after). If the list didn't exists, or the pivot didn't exists, the value is not inserted.

Parameters

string $key
string $pos

RedisCluster::BEFORE | RedisCluster::AFTER

mixed $pivot
mixed $value

Return Value

RedisCluster|int|false

The number of the elements in the list, -1 if the pivot didn't exists.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->del('key1');
$redisCluster->lInsert('key1', RedisCluster::AFTER, 'A', 'X');    // 0

$redisCluster->lPush('key1', 'A');
$redisCluster->lPush('key1', 'B');
$redisCluster->lPush('key1', 'C');

$redisCluster->lInsert('key1', RedisCluster::BEFORE, 'C', 'X');   // 4
$redisCluster->lRange('key1', 0, -1);                      // array('X', 'C', 'B', 'A')

$redisCluster->lInsert('key1', RedisCluster::AFTER, 'C', 'Y');    // 5
$redisCluster->lRange('key1', 0, -1);                      // array('X', 'C', 'Y', 'B', 'A')

$redisCluster->lInsert('key1', RedisCluster::AFTER, 'W', 'value'); // -1
</pre>

mixed lindex(string $key, int $index)

Return the specified element of the list stored at the specified key.

0 the first element, 1 the second ... -1 the last element, -2 the penultimate ... Return FALSE in case of a bad index or a key that doesn't point to a list.

Parameters

string $key
int $index

Return Value

mixed

the element at this index, Bool FALSE if the key identifies a non-string data type, or no value corresponds to this index in the list Key.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->rPush('key1', 'A');
$redisCluster->rPush('key1', 'B');
$redisCluster->rPush('key1', 'C');  // key1 => [ 'A', 'B', 'C' ]
$redisCluster->lGet('key1', 0);     // 'A'
$redisCluster->lGet('key1', -1);    // 'C'
$redisCluster->lGet('key1', 10);    // `FALSE`
</pre>

RedisCluster|int|bool lrem(string $key, mixed $value, int $count = 0)

Removes the first count occurrences of the value element from the list.

If count is zero, all the matching elements are removed. If count is negative, elements are removed from tail to head.

Parameters

string $key
mixed $value
int $count

Return Value

RedisCluster|int|bool

the number of elements to remove bool FALSE if the value identified by key is not a list.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->lPush('key1', 'A');
$redisCluster->lPush('key1', 'B');
$redisCluster->lPush('key1', 'C');
$redisCluster->lPush('key1', 'A');
$redisCluster->lPush('key1', 'A');

$redisCluster->lRange('key1', 0, -1);   // array('A', 'A', 'C', 'B', 'A')
$redisCluster->lrem('key1', 'A', 2);    // 2
$redisCluster->lRange('key1', 0, -1);   // array('C', 'B', 'A')
</pre>

mixed brpoplpush(string $srckey, string $deskey, int $timeout)

A blocking version of rpoplpush, with an integral timeout in the third parameter.

Parameters

string $srckey
string $deskey
int $timeout

Return Value

mixed

The element that was moved in case of success, FALSE in case of timeout.

Exceptions

RedisClusterException

RedisCluster|bool|string rpoplpush(string $src, string $dst)

Since: redis >= 1.2

Pops a value from the tail of a list, and pushes it to the front of another list.

Also return this value.

Parameters

string $src
string $dst

Return Value

RedisCluster|bool|string

The element that was moved in case of success, FALSE in case of failure.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->del('x', 'y');

$redisCluster->lPush('x', 'abc');
$redisCluster->lPush('x', 'def');
$redisCluster->lPush('y', '123');
$redisCluster->lPush('y', '456');

// move the last of x to the front of y.
var_dump($redisCluster->rpoplpush('x', 'y'));
var_dump($redisCluster->lRange('x', 0, -1));
var_dump($redisCluster->lRange('y', 0, -1));

////Output:
//
//string(3) "abc"
//array(1) {
//  [0]=>
//  string(3) "def"
//}
//array(3) {
//  [0]=>
//  string(3) "abc"
//  [1]=>
//  string(3) "456"
//  [2]=>
//  string(3) "123"
//}
</pre>

RedisCluster|int|bool lLen(string $key)

Returns the size of a list identified by Key. If the list didn't exist or is empty, the command returns 0. If the data type identified by Key is not a list, the command return FALSE.

Parameters

string $key

Return Value

RedisCluster|int|bool

The size of the list identified by Key exists. bool FALSE if the data type identified by Key is not list

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->rPush('key1', 'A');
$redisCluster->rPush('key1', 'B');
$redisCluster->rPush('key1', 'C');  // key1 => [ 'A', 'B', 'C' ]
$redisCluster->lLen('key1');       // 3
$redisCluster->rPop('key1');
$redisCluster->lLen('key1');       // 2
</pre>

RedisCluster|int|false scard(string $key)

Returns the set cardinality (number of elements) of the set stored at key.

Parameters

string $key

Return Value

RedisCluster|int|false

the cardinality (number of elements) of the set, or 0 if key does not exist.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->sAdd('key1' , 'set1');
$redisCluster->sAdd('key1' , 'set2');
$redisCluster->sAdd('key1' , 'set3');   // 'key1' => {'set1', 'set2', 'set3'}
$redisCluster->scard('key1');           // 3
$redisCluster->scard('keyX');           // 0
</pre>

RedisCluster|array|false sMembers(string $key)

Returns all the members of the set value stored at key.

This has the same effect as running SINTER with one argument key.

Parameters

string $key

Return Value

RedisCluster|array|false

All elements of the set.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->del('s');
$redisCluster->sAdd('s', 'a');
$redisCluster->sAdd('s', 'b');
$redisCluster->sAdd('s', 'a');
$redisCluster->sAdd('s', 'c');
var_dump($redisCluster->sMembers('s'));

////Output:
//
//array(3) {
//  [0]=>
//  string(1) "b"
//  [1]=>
//  string(1) "c"
//  [2]=>
//  string(1) "a"
//}
// The order is random and corresponds to redis' own internal representation of the set structure.
</pre>

RedisCluster|bool sismember(string $key, mixed $value)

Returns if member is a member of the set stored at key.

Parameters

string $key
mixed $value

Return Value

RedisCluster|bool

TRUE if value is a member of the set at key key, FALSE otherwise.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->sAdd('key1' , 'set1');
$redisCluster->sAdd('key1' , 'set2');
$redisCluster->sAdd('key1' , 'set3'); // 'key1' => {'set1', 'set2', 'set3'}

$redisCluster->sIsMember('key1', 'set1'); // TRUE
$redisCluster->sIsMember('key1', 'setX'); // FALSE
</pre>

RedisCluster|int|false sAdd(string $key, mixed $value, mixed ...$other_values)

Adds a values to the set value stored at key.

If this value is already in the set, FALSE is returned.

Parameters

string $key

Required key

mixed $value

Required value

mixed ...$other_values

Return Value

RedisCluster|int|false

The number of elements added to the set

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->sAdd('k', 'v1');                // int(1)
$redisCluster->sAdd('k', 'v1', 'v2', 'v3');    // int(2)
</pre>

RedisCluster|bool|int sAddArray(string $key, array $values)

Adds a values to the set value stored at key.

If this value is already in the set, FALSE is returned.

Parameters

string $key

Required key

array $values

Return Value

RedisCluster|bool|int

The number of elements added to the set

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->sAddArray('k', ['v1', 'v2', 'v3']);
//This is a feature in php only. Same as $redisCluster->sAdd('k', 'v1', 'v2', 'v3');
</pre>

RedisCluster|int|false srem(string $key, mixed $value, mixed ...$other_values)

Removes the specified members from the set value stored at key.

Parameters

string $key
mixed $value
mixed ...$other_values

Return Value

RedisCluster|int|false

The number of elements removed from the set.

Exceptions

RedisClusterException

Examples

<pre>
var_dump( $redisCluster->sAdd('k', 'v1', 'v2', 'v3') );    // int(3)
var_dump( $redisCluster->sRem('k', 'v2', 'v3') );          // int(2)
var_dump( $redisCluster->sMembers('k') );
//// Output:
// array(1) {
//   [0]=> string(2) "v1"
// }
</pre>

RedisCluster|bool|array sUnion(string $key, string ...$other_keys)

Performs the union between N sets and returns it.

Parameters

string $key

Any number of keys corresponding to sets in redis.

string ...$other_keys

Return Value

RedisCluster|bool|array

of strings: The union of all these sets.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->del('s0', 's1', 's2');

$redisCluster->sAdd('s0', '1');
$redisCluster->sAdd('s0', '2');
$redisCluster->sAdd('s1', '3');
$redisCluster->sAdd('s1', '1');
$redisCluster->sAdd('s2', '3');
$redisCluster->sAdd('s2', '4');

var_dump($redisCluster->sUnion('s0', 's1', 's2'));

//// Output:
//
//array(4) {
//  [0]=>
//  string(1) "3"
//  [1]=>
//  string(1) "4"
//  [2]=>
//  string(1) "1"
//  [3]=>
//  string(1) "2"
//}
</pre>

RedisCluster|int|false sUnionStore(string $dst, string $key, string ...$other_keys)

Performs the same action as sUnion, but stores the result in the first key

Parameters

string $dst

the key to store the diff into.

string $key

Any number of keys corresponding to sets in redis.

string ...$other_keys

Return Value

RedisCluster|int|false

Any number of keys corresponding to sets in redis.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->del('s0', 's1', 's2');

$redisCluster->sAdd('s0', '1');
$redisCluster->sAdd('s0', '2');
$redisCluster->sAdd('s1', '3');
$redisCluster->sAdd('s1', '1');
$redisCluster->sAdd('s2', '3');
$redisCluster->sAdd('s2', '4');

var_dump($redisCluster->sUnionStore('dst', 's0', 's1', 's2'));
var_dump($redisCluster->sMembers('dst'));

//// Output:
//
//int(4)
//array(4) {
//  [0]=>
//  string(1) "3"
//  [1]=>
//  string(1) "4"
//  [2]=>
//  string(1) "1"
//  [3]=>
//  string(1) "2"
//}
</pre>

RedisCluster|array|false sInter(array|string $key, string ...$other_keys)

Returns the members of a set resulting from the intersection of all the sets held at the specified keys. If just a single key is specified, then this command produces the members of this set. If one of the keys is missing, FALSE is returned.

Parameters

array|string $key
string ...$other_keys

Return Value

RedisCluster|array|false

contain the result of the intersection between those keys. If the intersection between the different sets is empty, the return value will be empty array.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->sAdd('key1', 'val1');
$redisCluster->sAdd('key1', 'val2');
$redisCluster->sAdd('key1', 'val3');
$redisCluster->sAdd('key1', 'val4');

$redisCluster->sAdd('key2', 'val3');
$redisCluster->sAdd('key2', 'val4');

$redisCluster->sAdd('key3', 'val3');
$redisCluster->sAdd('key3', 'val4');

var_dump($redisCluster->sInter('key1', 'key2', 'key3'));

// Output:
//
//array(2) {
//  [0]=>
//  string(4) "val4"
//  [1]=>
//  string(4) "val3"
//}
</pre>

RedisCluster|int|false sInterStore(array|string $key, string ...$other_keys)

Performs a sInter command and stores the result in a new set.

Parameters

array|string $key

the key to store the diff into.

string ...$other_keys

Return Value

RedisCluster|int|false

The cardinality of the resulting set, or FALSE in case of a missing key.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->sAdd('key1', 'val1');
$redisCluster->sAdd('key1', 'val2');
$redisCluster->sAdd('key1', 'val3');
$redisCluster->sAdd('key1', 'val4');

$redisCluster->sAdd('key2', 'val3');
$redisCluster->sAdd('key2', 'val4');

$redisCluster->sAdd('key3', 'val3');
$redisCluster->sAdd('key3', 'val4');

var_dump($redisCluster->sInterStore('output', 'key1', 'key2', 'key3'));
var_dump($redisCluster->sMembers('output'));

//// Output:
//
//int(2)
//array(2) {
//  [0]=>
//  string(4) "val4"
//  [1]=>
//  string(4) "val3"
//}
</pre>

RedisCluster|array|false sDiff(string $key, string ...$other_keys)

Performs the difference between N sets and returns it.

Parameters

string $key

Any number of keys corresponding to sets in redis.

string ...$other_keys

Return Value

RedisCluster|array|false

of strings: The difference of the first set will all the others.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->del('s0', 's1', 's2');

$redisCluster->sAdd('s0', '1');
$redisCluster->sAdd('s0', '2');
$redisCluster->sAdd('s0', '3');
$redisCluster->sAdd('s0', '4');

$redisCluster->sAdd('s1', '1');
$redisCluster->sAdd('s2', '3');

var_dump($redisCluster->sDiff('s0', 's1', 's2'));

//// Output:
//
//array(2) {
//  [0]=>
//  string(1) "4"
//  [1]=>
//  string(1) "2"
//}
</pre>

RedisCluster|int|false sDiffStore(string $dst, string $key, string ...$other_keys)

Performs the same action as sDiff, but stores the result in the first key

Parameters

string $dst

the key to store the diff into.

string $key

Any number of keys corresponding to sets in redis

string ...$other_keys

Return Value

RedisCluster|int|false

The cardinality of the resulting set, or FALSE in case of a missing key.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->del('s0', 's1', 's2');

$redisCluster->sAdd('s0', '1');
$redisCluster->sAdd('s0', '2');
$redisCluster->sAdd('s0', '3');
$redisCluster->sAdd('s0', '4');

$redisCluster->sAdd('s1', '1');
$redisCluster->sAdd('s2', '3');

var_dump($redisCluster->sDiffStore('dst', 's0', 's1', 's2'));
var_dump($redisCluster->sMembers('dst'));

//// Output:
//
//int(2)
//array(2) {
//  [0]=>
//  string(1) "4"
//  [1]=>
//  string(1) "2"
//}
</pre>

RedisCluster|string|array|false sRandMember(string $key, int $count = 0)

Returns a random element(s) from the set value at Key, without removing it.

Parameters

string $key
int $count [optional]

Return Value

RedisCluster|string|array|false

value(s) from the set bool FALSE if set identified by key is empty or doesn't exist and count argument isn't passed.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->sAdd('key1' , 'one');
$redisCluster->sAdd('key1' , 'two');
$redisCluster->sAdd('key1' , 'three');              // 'key1' => {'one', 'two', 'three'}

var_dump( $redisCluster->sRandMember('key1') );     // 'key1' => {'one', 'two', 'three'}

// string(5) "three"

var_dump( $redisCluster->sRandMember('key1', 2) );  // 'key1' => {'one', 'two', 'three'}

// array(2) {
//   [0]=> string(2) "one"
//   [1]=> string(2) "three"
// }
</pre>

RedisCluster|int|false strlen(string $key)

Get the length of a string value.

Parameters

string $key

Return Value

RedisCluster|int|false

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->set('key', 'value');
$redisCluster->strlen('key'); // 5
</pre>

RedisCluster|bool persist(string $key)

Remove the expiration timer from a key.

Parameters

string $key

Return Value

RedisCluster|bool

TRUE if a timeout was removed, FALSE if the key didn’t exist or didn’t have an expiration timer.

Exceptions

RedisClusterException

Examples

$redisCluster->persist('key');

RedisCluster|int|false ttl(string $key)

Returns the remaining time to live of a key that has a timeout.

This introspection capability allows a Redis client to check how many seconds a given key will continue to be part of the dataset. In Redis 2.6 or older the command returns -1 if the key does not exist or if the key exist but has no associated expire. Starting with Redis 2.8 the return value in case of error changed: Returns -2 if the key does not exist. Returns -1 if the key exists but has no associated expire.

Parameters

string $key

Return Value

RedisCluster|int|false

the time left to live in seconds.

Exceptions

RedisClusterException

Examples

$redisCluster->ttl('key');

RedisCluster|int|false pttl(string $key)

Returns the remaining time to live of a key that has an expire set, with the sole difference that TTL returns the amount of remaining time in seconds while PTTL returns it in milliseconds. In Redis 2.6 or older the command returns -1 if the key does not exist or if the key exist but has no associated expire. Starting with Redis 2.8 the return value in case of error changed: Returns -2 if the key does not exist. Returns -1 if the key exists but has no associated expire.

Parameters

string $key

Return Value

RedisCluster|int|false

the time left to live in milliseconds.

Exceptions

RedisClusterException

Examples

$redisCluster->pttl('key');

RedisCluster|int|false zCard(string $key)

Returns the cardinality of an ordered set.

Parameters

string $key

Return Value

RedisCluster|int|false

the set's cardinality

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->zAdd('key', 0, 'val0');
$redisCluster->zAdd('key', 2, 'val2');
$redisCluster->zAdd('key', 10, 'val10');
$redisCluster->zCard('key');            // 3
</pre>

RedisCluster|int|false zCount(string $key, string $start, string $end)

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 from the range. +inf and -inf are also valid limits.

Parameters

string $key
string $start
string $end

Return Value

RedisCluster|int|false

the size of a corresponding zRangeByScore.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->zAdd('key', 0, 'val0');
$redisCluster->zAdd('key', 2, 'val2');
$redisCluster->zAdd('key', 10, 'val10');
$redisCluster->zCount('key', 0, 3); // 2, corresponding to array('val0', 'val2')
</pre>

RedisCluster|int|false zRemRangeByScore(string $key, string $min, string $max)

Deletes the elements of the sorted set stored at the specified key which have scores in the range [start,end].

Parameters

string $key
string $min
string $max

Return Value

RedisCluster|int|false

The number of values deleted from the sorted set

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->zAdd('key', 0, 'val0');
$redisCluster->zAdd('key', 2, 'val2');
$redisCluster->zAdd('key', 10, 'val10');
$redisCluster->zRemRangeByScore('key', '0', '3'); // 2
</pre>

RedisCluster|float|false zScore(string $key, mixed $member)

Returns the score of a given member in the specified sorted set.

Parameters

string $key
mixed $member

Return Value

RedisCluster|float|false

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->zAdd('key', 2.5, 'val2');
$redisCluster->zScore('key', 'val2'); // 2.5
</pre>

RedisCluster|int|float|false zAdd(string $key, array|float $score_or_options, mixed ...$more_scores_and_mems)

Adds the specified member with a given score to the sorted set stored at key.

Parameters

string $key

Required key

array|float $score_or_options
mixed ...$more_scores_and_mems

Return Value

RedisCluster|int|float|false

Number of values added

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->zAdd('z', 1, 'v2', 2, 'v2', 3, 'v3', 4, 'v4' );  // int(3)
$redisCluster->zRem('z', 'v2', 'v3');                           // int(2)
var_dump( $redisCluster->zRange('z', 0, -1) );

//// Output:
// array(1) {
//   [0]=> string(2) "v4"
// }
</pre>

RedisCluster|float|false zIncrBy(string $key, float $value, string $member)

Increments the score of a member from a sorted set by a given amount.

Parameters

string $key
float $value

(double) value that will be added to the member's score

string $member

Return Value

RedisCluster|float|false

the new value

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->del('key');
$redisCluster->zIncrBy('key', 2.5, 'member1');// key or member1 didn't exist, so member1's score is to 0 ;
                                             //before the increment and now has the value 2.5
$redisCluster->zIncrBy('key', 1, 'member1');    // 3.5
</pre>

RedisCluster|int|false hLen(string $key)

Returns the length of a hash, in number of items

Parameters

string $key

Return Value

RedisCluster|int|false

the number of items in a hash, FALSE if the key doesn't exist or isn't a hash.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->del('h');
$redisCluster->hSet('h', 'key1', 'hello');
$redisCluster->hSet('h', 'key2', 'plop');
$redisCluster->hLen('h'); // returns 2
</pre>

RedisCluster|array|false hKeys(string $key)

Returns the keys in a hash, as an array of strings.

Parameters

string $key

Return Value

RedisCluster|array|false

An array of elements, the keys of the hash. This works like PHP's array_keys().

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->del('h');
$redisCluster->hSet('h', 'a', 'x');
$redisCluster->hSet('h', 'b', 'y');
$redisCluster->hSet('h', 'c', 'z');
$redisCluster->hSet('h', 'd', 't');
var_dump($redisCluster->hKeys('h'));

//// Output:
//
// array(4) {
// [0]=>
// string(1) "a"
// [1]=>
// string(1) "b"
// [2]=>
// string(1) "c"
// [3]=>
// string(1) "d"
// }
// The order is random and corresponds to redis' own internal representation of the set structure.
</pre>

RedisCluster|array|false hVals(string $key)

Returns the values in a hash, as an array of strings.

Parameters

string $key

Return Value

RedisCluster|array|false

An array of elements, the values of the hash. This works like PHP's array_values().

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->del('h');
$redisCluster->hSet('h', 'a', 'x');
$redisCluster->hSet('h', 'b', 'y');
$redisCluster->hSet('h', 'c', 'z');
$redisCluster->hSet('h', 'd', 't');
var_dump($redisCluster->hVals('h'));

//// Output:
//
// array(4) {
//   [0]=>
//   string(1) "x"
//   [1]=>
//   string(1) "y"
//   [2]=>
//   string(1) "z"
//   [3]=>
//   string(1) "t"
// }
// The order is random and corresponds to redis' own internal representation of the set structure.
</pre>

mixed hGet(string $key, string $member)

Gets a value from the hash stored at key.

If the hash table doesn't exist, or the key doesn't exist, FALSE is returned.

Parameters

string $key
string $member

Return Value

mixed

The value, if the command executed successfully BOOL FALSE in case of failure

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->del('h');
$redisCluster->hSet('h', 'a', 'x');
$redisCluster->hGet('h', 'a'); // 'X'
</pre>

RedisCluster|array|false hGetAll(string $key)

Returns the whole hash, as an array of strings indexed by strings.

Parameters

string $key

Return Value

RedisCluster|array|false

An array of elements, the contents of the hash.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->del('h');
$redisCluster->hSet('h', 'a', 'x');
$redisCluster->hSet('h', 'b', 'y');
$redisCluster->hSet('h', 'c', 'z');
$redisCluster->hSet('h', 'd', 't');
var_dump($redisCluster->hGetAll('h'));

//// Output:
//
// array(4) {
//   ["a"]=>
//   string(1) "x"
//   ["b"]=>
//   string(1) "y"
//   ["c"]=>
//   string(1) "z"
//   ["d"]=>
//   string(1) "t"
// }
// The order is random and corresponds to redis' own internal representation of the set structure.
</pre>

RedisCluster|bool hExists(string $key, string $member)

Verify if the specified member exists in a key.

Parameters

string $key
string $member

Return Value

RedisCluster|bool

If the member exists in the hash table, return TRUE, otherwise return FALSE.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->hSet('h', 'a', 'x');
$redisCluster->hExists('h', 'a');               //  TRUE
$redisCluster->hExists('h', 'NonExistingKey');  // FALSE
</pre>

RedisCluster|int|false hIncrBy(string $key, string $member, int $value)

Increments the value of a member from a hash by a given amount.

Parameters

string $key
string $member
int $value

(integer) value that will be added to the member's value

Return Value

RedisCluster|int|false

the new value

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->del('h');
$redisCluster->hIncrBy('h', 'x', 2); // returns 2: h[x] = 2 now.
$redisCluster->hIncrBy('h', 'x', 1); // h[x] ← 2 + 1. Returns 3
</pre>

RedisCluster|int|false hSet(string $key, string $member, mixed $value)

Adds a value to the hash stored at key. If this value is already in the hash, FALSE is returned.

Parameters

string $key
string $member
mixed $value

Return Value

RedisCluster|int|false

1 if value didn't exist and was added successfully, 0 if the value was already present and was replaced, FALSE if there was an error.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->del('h')
$redisCluster->hSet('h', 'key1', 'hello');  // 1, 'key1' => 'hello' in the hash at "h"
$redisCluster->hGet('h', 'key1');           // returns "hello"

$redisCluster->hSet('h', 'key1', 'plop');   // 0, value was replaced.
$redisCluster->hGet('h', 'key1');           // returns "plop"
</pre>

RedisCluster|bool hSetNx(string $key, string $member, mixed $value)

Adds a value to the hash stored at key only if this field isn't already in the hash.

Parameters

string $key
string $member
mixed $value

Return Value

RedisCluster|bool

TRUE if the field was set, FALSE if it was already present.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->del('h')
$redisCluster->hSetNx('h', 'key1', 'hello'); // TRUE, 'key1' => 'hello' in the hash at "h"
$redisCluster->hSetNx('h', 'key1', 'world'); // FALSE, 'key1' => 'hello' in the hash at "h". No change since the
field wasn't replaced.
</pre>

RedisCluster|array|false hMget(string $key, array $keys)

Retrieve the values associated to the specified fields in the hash.

Parameters

string $key
array $keys

Return Value

RedisCluster|array|false

Array An array of elements, the values of the specified fields in the hash, with the hash keys as array keys.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->del('h');
$redisCluster->hSet('h', 'field1', 'value1');
$redisCluster->hSet('h', 'field2', 'value2');
$redisCluster->hMget('h', array('field1', 'field2')); // returns array('field1' => 'value1', 'field2' =>
'value2')
</pre>

RedisCluster|bool hMset(string $key, array $key_values)

Fills in a whole hash. Non-string values are converted to string, using the standard (string) cast.

NULL values are stored as empty strings

Parameters

string $key
array $key_values

key → value array

Return Value

RedisCluster|bool

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->del('user:1');
$redisCluster->hMSet('user:1', array('name' => 'Joe', 'salary' => 2000));
$redisCluster->hIncrBy('user:1', 'salary', 100); // Joe earns 100 more now.
</pre>

RedisCluster|int|false hDel(string $key, string $member, string ...$other_members)

Removes a values from the hash stored at key.

If the hash table doesn't exist, or the key doesn't exist, FALSE is returned.

Parameters

string $key
string $member
string ...$other_members

Return Value

RedisCluster|int|false

Number of deleted fields

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->hMSet('h',
              array(
                   'f1' => 'v1',
                   'f2' => 'v2',
                   'f3' => 'v3',
                   'f4' => 'v4',
              ));

var_dump( $redisCluster->hDel('h', 'f1') );        // int(1)
var_dump( $redisCluster->hDel('h', 'f2', 'f3') );  // int(2)

var_dump( $redisCluster->hGetAll('h') );

//// Output:
//
//  array(1) {
//    ["f4"]=> string(2) "v4"
//  }
</pre>

RedisCluster|float|false hIncrByFloat(string $key, string $member, float $value)

Increment the float value of a hash field by the given amount

Parameters

string $key
string $member
float $value

Return Value

RedisCluster|float|false

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->hset('h', 'float', 3);
$redisCluster->hset('h', 'int',   3);
var_dump( $redisCluster->hIncrByFloat('h', 'float', 1.5) ); // float(4.5)

var_dump( $redisCluster->hGetAll('h') );

//// Output:
//
// array(2) {
//   ["float"]=>
//   string(3) "4.5"
//   ["int"]=>
//   string(1) "3"
// }
</pre>

RedisCluster|string|false dump(string $key)

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.

Parameters

string $key

Return Value

RedisCluster|string|false

The Redis encoded value of the key, or FALSE if the key doesn't exist

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->set('foo', 'bar');
$val = $redisCluster->dump('foo'); // $val will be the Redis encoded key value
</pre>

RedisCluster|int|false zRank(string $key, mixed $member)

Returns the rank of a given member in the specified sorted set, starting at 0 for the item with the smallest score. zRevRank starts at 0 for the item with the largest score.

Parameters

string $key
mixed $member

Return Value

RedisCluster|int|false

the item's score.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->del('z');
$redisCluster->zAdd('key', 1, 'one');
$redisCluster->zAdd('key', 2, 'two');
$redisCluster->zRank('key', 'one');     // 0
$redisCluster->zRank('key', 'two');     // 1
$redisCluster->zRevRank('key', 'one');  // 1
$redisCluster->zRevRank('key', 'two');  // 0
</pre>

RedisCluster|int|false zRevRank(string $key, mixed $member)

No description

Parameters

string $key
mixed $member

Return Value

RedisCluster|int|false

the item's score

Exceptions

RedisClusterException

See also

zRank()

RedisCluster|int|false incr(string $key, int $by = 1)

Increment the number stored at key by one.

Parameters

string $key
int $by

Return Value

RedisCluster|int|false

the new value

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->incr('key1'); // key1 didn't exists, set to 0 before the increment and now has the value 1
$redisCluster->incr('key1'); // 2
$redisCluster->incr('key1'); // 3
$redisCluster->incr('key1'); // 4
</pre>

RedisCluster|int|false decr(string $key, int $by = 1)

Decrement the number stored at key by one.

Parameters

string $key
int $by

Return Value

RedisCluster|int|false

the new value

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->decr('key1'); // key1 didn't exists, set to 0 before the increment and now has the value -1
$redisCluster->decr('key1'); // -2
$redisCluster->decr('key1'); // -3
</pre>

RedisCluster|int|false incrBy(string $key, int $value)

Increment the number stored at key by one. If the second argument is filled, it will be used as the integer value of the increment.

Parameters

string $key key
int $value

value that will be added to key (only for incrBy)

Return Value

RedisCluster|int|false

the new value

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->incr('key1');        // key1 didn't exists, set to 0 before the increment and now has the value 1
$redisCluster->incr('key1');        // 2
$redisCluster->incr('key1');        // 3
$redisCluster->incr('key1');        // 4
$redisCluster->incrBy('key1', 10);  // 14
</pre>

RedisCluster|int|false decrBy(string $key, int $value)

Decrement the number stored at key by one. If the second argument is filled, it will be used as the integer value of the decrement.

Parameters

string $key
int $value

that will be subtracted to key (only for decrBy)

Return Value

RedisCluster|int|false

the new value

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->decr('key1');        // key1 didn't exists, set to 0 before the increment and now has the value -1
$redisCluster->decr('key1');        // -2
$redisCluster->decr('key1');        // -3
$redisCluster->decrBy('key1', 10);  // -13
</pre>

RedisCluster|float|false incrByFloat(string $key, float $value)

Increment the float value of a key by the given amount

Parameters

string $key
float $value

Return Value

RedisCluster|float|false

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->set('x', 3);
var_dump( $redisCluster->incrByFloat('x', 1.5) );   // float(4.5)

var_dump( $redisCluster->get('x') );                // string(3) "4.5"
</pre>

RedisCluster|bool expire(string $key, int $timeout, string|null $mode = null)

Sets an expiration date (a timeout) on an item.

Parameters

string $key

The key that will disappear.

int $timeout

The key's remaining Time To Live, in seconds.

string|null $mode

Return Value

RedisCluster|bool

TRUE in case of success, FALSE in case of failure.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->set('x', '42');
$redisCluster->expire('x', 3);  // x will disappear in 3 seconds.
sleep(5);                    // wait 5 seconds
$redisCluster->get('x');            // will return `FALSE`, as 'x' has expired.
</pre>

RedisCluster|bool pexpire(string $key, int $timeout, string|null $mode = null)

Sets an expiration date (a timeout in milliseconds) on an item.

Parameters

string $key

The key that will disappear.

int $timeout

The key's remaining Time To Live, in milliseconds.

string|null $mode

Return Value

RedisCluster|bool

TRUE in case of success, FALSE in case of failure.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->set('x', '42');
$redisCluster->pexpire('x', 11500); // x will disappear in 11500 milliseconds.
$redisCluster->ttl('x');            // 12
$redisCluster->pttl('x');           // 11500
</pre>

RedisCluster|bool expireAt(string $key, int $timestamp, string|null $mode = null)

Sets an expiration date (a timestamp) on an item.

Parameters

string $key

The key that will disappear.

int $timestamp

Unix timestamp. The key's date of death, in seconds from Epoch time.

string|null $mode

Return Value

RedisCluster|bool

TRUE in case of success, FALSE in case of failure.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->set('x', '42');
$now = time();               // current timestamp
$redisCluster->expireAt('x', $now + 3); // x will disappear in 3 seconds.
sleep(5);                        // wait 5 seconds
$redisCluster->get('x');                // will return `FALSE`, as 'x' has expired.
</pre>

RedisCluster|bool pexpireAt(string $key, int $timestamp, string|null $mode = null)

Sets an expiration date (a timestamp) on an item. Requires a timestamp in milliseconds

Parameters

string $key

The key that will disappear.

int $timestamp

Unix timestamp. The key's date of death, in seconds from Epoch time.

string|null $mode

Return Value

RedisCluster|bool

TRUE in case of success, FALSE in case of failure.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->set('x', '42');
$redisCluster->pExpireAt('x', 1555555555005);
$redisCluster->ttl('x');                       // 218270121
$redisCluster->pttl('x');                      // 218270120575
</pre>

RedisCluster|bool|int append(string $key, mixed $value)

Append specified string to the string stored in specified key.

Parameters

string $key
mixed $value

Return Value

RedisCluster|bool|int

Size of the value after the append

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->set('key', 'value1');
$redisCluster->append('key', 'value2'); // 12
$redisCluster->get('key');              // 'value1value2'
</pre>

RedisCluster|int|false getBit(string $key, int $value)

Return a single bit out of a larger string

Parameters

string $key
int $value

Return Value

RedisCluster|int|false

the bit value (0 or 1)

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->set('key', "\x7f");  // this is 0111 1111
$redisCluster->getBit('key', 0);    // 0
$redisCluster->getBit('key', 1);    // 1
</pre>

RedisCluster|int|false setBit(string $key, int $offset, bool $onoff)

Changes a single bit of a string.

Parameters

string $key
int $offset
bool $onoff

bool or int (1 or 0)

Return Value

RedisCluster|int|false

0 or 1, the value of the bit before it was set.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->set('key', "*");     // ord("*") = 42 = 0x2f = "0010 1010"
$redisCluster->setBit('key', 5, 1); // returns 0
$redisCluster->setBit('key', 7, 1); // returns 0
$redisCluster->get('key');          // chr(0x2f) = "/" = b("0010 1111")
</pre>

RedisCluster|bool|int bitop(string $operation, string $deskey, string $srckey, string ...$otherkeys)

Bitwise operation on multiple keys.

Parameters

string $operation

either "AND", "OR", "NOT", "XOR"

string $deskey

return key

string $srckey
string ...$otherkeys

Return Value

RedisCluster|bool|int

The size of the string stored in the destination key.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->set('bit1', '1'); // 11 0001
$redisCluster->set('bit2', '2'); // 11 0010

$redisCluster->bitOp('AND', 'bit', 'bit1', 'bit2'); // bit = 110000
$redisCluster->bitOp('OR',  'bit', 'bit1', 'bit2'); // bit = 110011
$redisCluster->bitOp('NOT', 'bit', 'bit1', 'bit2'); // bit = 110011
$redisCluster->bitOp('XOR', 'bit', 'bit1', 'bit2'); // bit = 11
</pre>

RedisCluster|int|false bitpos(string $key, bool $bit, int $start = 0, int $end = -1, bool $bybit = false)

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.

Parameters

string $key

The key to check (must be a string)

bool $bit

Whether to look for an unset (0) or set (1) bit.

int $start

Where in the string to start looking.

int $end

Where in the string to stop looking.

bool $bybit

If true, Redis will treat $start and $end as BIT values and not bytes, so if start was 0 and end was 2, Redis would only search the first two bits.

Return Value

RedisCluster|int|false

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.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->set('key', '\xff\xff');
$redisCluster->bitpos('key', 1); // int(0)
$redisCluster->bitpos('key', 1, 1); // int(8)
$redisCluster->bitpos('key', 1, 3); // int(-1)
$redisCluster->bitpos('key', 0); // int(16)
$redisCluster->bitpos('key', 0, 1); // int(16)
$redisCluster->bitpos('key', 0, 1, 5); // int(-1)
</pre>

RedisCluster|bool|int bitcount(string $key, int $start = 0, int $end = -1, bool $bybit = false)

Count bits in a string.

Parameters

string $key
int $start
int $end
bool $bybit

Return Value

RedisCluster|bool|int

The number of bits set to 1 in the value behind the input key.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->set('bit', '345'); // // 11 0011  0011 0100  0011 0101
var_dump( $redisCluster->bitCount('bit', 0, 0) ); // int(4)
var_dump( $redisCluster->bitCount('bit', 1, 1) ); // int(3)
var_dump( $redisCluster->bitCount('bit', 2, 2) ); // int(4)
var_dump( $redisCluster->bitCount('bit', 0, 2) ); // int(11)
</pre>

RedisCluster|string|bool lGet(string $key, int $index)

No description

Parameters

string $key
int $index

Return Value

RedisCluster|string|bool

Exceptions

RedisClusterException

See also

lIndex()

RedisCluster|string|false getRange(string $key, int $start, int $end)

Return a substring of a larger string

Parameters

string $key
int $start
int $end

Return Value

RedisCluster|string|false

the substring

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->set('key', 'string value');
$redisCluster->getRange('key', 0, 5);   // 'string'
$redisCluster->getRange('key', -5, -1); // 'value'
</pre>

RedisCluster|bool ltrim(string $key, int $start, int $end)

Trims an existing list so that it will contain only a specified range of elements.

Parameters

string $key
int $start
int $end

Return Value

RedisCluster|bool

Bool return FALSE if the key identify a non-list value.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->rPush('key1', 'A');
$redisCluster->rPush('key1', 'B');
$redisCluster->rPush('key1', 'C');
$redisCluster->lRange('key1', 0, -1); // array('A', 'B', 'C')
$redisCluster->ltrim('key1', 0, 1);
$redisCluster->lRange('key1', 0, -1); // array('A', 'B')
</pre>

RedisCluster|array|false lrange(string $key, int $start, int $end)

Returns the specified elements of the list stored at the specified key in the range [start, end]. start and stop are interpretated as indices: 0 the first element, 1 the second ... -1 the last element, -2 the penultimate .

..

Parameters

string $key
int $start
int $end

Return Value

RedisCluster|array|false

containing the values in specified range.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->rPush('key1', 'A');
$redisCluster->rPush('key1', 'B');
$redisCluster->rPush('key1', 'C');
$redisCluster->lrange('key1', 0, -1); // array('A', 'B', 'C')
</pre>

RedisCluster|int|false zRemRangeByRank(string $key, string $min, string $max)

Deletes the elements of the sorted set stored at the specified key which have rank in the range [start,end].

Parameters

string $key
string $min
string $max

Return Value

RedisCluster|int|false

The number of values deleted from the sorted set

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->zAdd('key', 1, 'one');
$redisCluster->zAdd('key', 2, 'two');
$redisCluster->zAdd('key', 3, 'three');
$redisCluster->zRemRangeByRank('key', 0, 1); // 2
$redisCluster->zRange('key', 0, -1, true); // array('three' => 3)
</pre>

RedisCluster|bool|int publish(string $channel, string $message)

Publish messages to channels. Warning: this function will probably change in the future.

Parameters

string $channel

a channel to publish to

string $message string

Return Value

RedisCluster|bool|int

Number of clients that received the message

Exceptions

RedisClusterException

Examples

$redisCluster->publish('chan-1', 'hello, world!'); // send message.

RedisCluster|bool rename(string $key_src, string $key_dst)

Renames a key.

Parameters

string $key_src
string $key_dst

Return Value

RedisCluster|bool

TRUE in case of success, FALSE in case of failure.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->set('x', '42');
$redisCluster->rename('x', 'y');
$redisCluster->get('y');   // → 42
$redisCluster->get('x');   // → `FALSE`
</pre>

RedisCluster|bool renameNx(string $key, string $newkey)

Renames a key.

Same as rename, but will not replace a key if the destination already exists. This is the same behaviour as setNx.

Parameters

string $key
string $newkey

Return Value

RedisCluster|bool

TRUE in case of success, FALSE in case of failure.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->set('x', '42');
$redisCluster->renameNx('x', 'y');
$redisCluster->get('y');   // → 42
$redisCluster->get('x');   // → `FALSE`
</pre>

RedisCluster|int|false pfcount(string $key)

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.

Parameters

string $key

Return Value

RedisCluster|int|false

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->pfadd('key1', array('elem1', 'elem2'));
$redisCluster->pfadd('key2', array('elem3', 'elem2'));
$redisCluster->pfcount('key1'); // int(2)
$redisCluster->pfcount(array('key1', 'key2')); // int(3)
</pre>

RedisCluster|bool pfadd(string $key, array $elements)

Adds all the element arguments to the HyperLogLog data structure stored at the key.

Parameters

string $key
array $elements

Return Value

RedisCluster|bool

Exceptions

RedisClusterException

Examples

$redisCluster->pfadd('key', array('elem1', 'elem2'))

RedisCluster|bool pfmerge(string $key, array $keys)

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.

Parameters

string $key
array $keys

Return Value

RedisCluster|bool

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->pfadd('key1', array('elem1', 'elem2'));
$redisCluster->pfadd('key2', array('elem3', 'elem2'));
$redisCluster->pfmerge('key3', array('key1', 'key2'));
$redisCluster->pfCount('key3'); // int(3)
</pre>

RedisCluster|int|false setRange(string $key, int $offset, string $value)

Changes a substring of a larger string.

Parameters

string $key
int $offset
string $value

Return Value

RedisCluster|int|false

the length of the string after it was modified.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->set('key', 'Hello world');
$redisCluster->setRange('key', 6, "redis"); // returns 11
$redisCluster->get('key');                  // "Hello redis"
</pre>

RedisCluster|bool restore(string $key, int $timeout, string $value, array|null $options = null)

Restore a key from the result of a DUMP operation.

Parameters

string $key

The key name

int $timeout

How long the key should live (if zero, no expire will be set on the key)

string $value

(binary). The Redis encoded key value (from DUMP)

array|null $options

Return Value

RedisCluster|bool

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->set('foo', 'bar');
$val = $redisCluster->dump('foo');
$redisCluster->restore('bar', 0, $val); // The key 'bar', will now be equal to the key 'foo'
</pre>

RedisCluster|bool sMove(string $src, string $dst, string $member)

Moves the specified member from the set at srcKey to the set at dstKey.

Parameters

string $src
string $dst
string $member

Return Value

RedisCluster|bool

If the operation is successful, return TRUE. If the srcKey and/or dstKey didn't exist, and/or the member didn't exist in srcKey, FALSE is returned.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->sAdd('key1' , 'set11');
$redisCluster->sAdd('key1' , 'set12');
$redisCluster->sAdd('key1' , 'set13');          // 'key1' => {'set11', 'set12', 'set13'}
$redisCluster->sAdd('key2' , 'set21');
$redisCluster->sAdd('key2' , 'set22');          // 'key2' => {'set21', 'set22'}
$redisCluster->sMove('key1', 'key2', 'set13');  // 'key1' =>  {'set11', 'set12'}
                                         // 'key2' =>  {'set21', 'set22', 'set13'}
</pre>

RedisCluster|array|bool zRange(string $key, mixed $start, mixed $end, array|bool|null $options = null)

Returns a range of elements from the ordered set stored at the specified key, with values in the range [start, end]. start and stop are interpreted as zero-based indices: 0 the first element, 1 the second ... -1 the last element, -2 the penultimate .

..

Parameters

string $key
mixed $start
mixed $end
array|bool|null $options

Return Value

RedisCluster|array|bool

Array containing the values in specified range.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->zAdd('key1', 0, 'val0');
$redisCluster->zAdd('key1', 2, 'val2');
$redisCluster->zAdd('key1', 10, 'val10');
$redisCluster->zRange('key1', 0, -1); // array('val0', 'val2', 'val10')
// with scores
$redisCluster->zRange('key1', 0, -1, true); // array('val0' => 0, 'val2' => 2, 'val10' => 10)
</pre>

RedisCluster|bool|array zRevRange(string $key, string $min, string $max, array|null $options = null)

Returns the elements of the sorted set stored at the specified key in the range [start, end] in reverse order. start and stop are interpretated as zero-based indices: 0 the first element, 1 the second ... -1 the last element, -2 the penultimate .

..

Parameters

string $key
string $min
string $max
array|null $options

Return Value

RedisCluster|bool|array

Array containing the values in specified range.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->zAdd('key', 0, 'val0');
$redisCluster->zAdd('key', 2, 'val2');
$redisCluster->zAdd('key', 10, 'val10');
$redisCluster->zRevRange('key', 0, -1); // array('val10', 'val2', 'val0')

// with scores
$redisCluster->zRevRange('key', 0, -1, true); // array('val10' => 10, 'val2' => 2, 'val0' => 0)
</pre>

RedisCluster|array|false zRangeByScore(string $key, string $start, string $end, array $options = [])

Returns the 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 from the range.

+inf and -inf are also valid limits.

zRevRangeByScore returns the same items in reverse order, when the start and end parameters are swapped.

Parameters

string $key
string $start
string $end
array $options

Two options are available:

  • withscores => TRUE,
  • and limit => array($offset, $count)

Return Value

RedisCluster|array|false

Array containing the values in specified range.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->zAdd('key', 0, 'val0');
$redisCluster->zAdd('key', 2, 'val2');
$redisCluster->zAdd('key', 10, 'val10');
$redisCluster->zRangeByScore('key', 0, 3);
// array('val0', 'val2')
$redisCluster->zRangeByScore('key', 0, 3, array('withscores' => TRUE);
// array('val0' => 0, 'val2' => 2)
$redisCluster->zRangeByScore('key', 0, 3, array('limit' => array(1, 1));
// array('val2' => 2)
$redisCluster->zRangeByScore('key', 0, 3, array('limit' => array(1, 1));
// array('val2')
$redisCluster->zRangeByScore('key', 0, 3, array('withscores' => TRUE, 'limit' => array(1, 1));
// array('val2'=> 2)
</pre>

RedisCluster|bool|array zRevRangeByScore(string $key, string $min, string $max, array|null $options = null)

No description

Parameters

string $key
string $min
string $max
array|null $options

Return Value

RedisCluster|bool|array

Exceptions

RedisClusterException

See also

zRangeByScore()

RedisCluster|array|false zRangeByLex(string $key, string $min, string $max, int $offset = -1, int $count = -1)

Returns a range of members in a sorted set, by lexicographical range

Parameters

string $key

The ZSET you wish to run against.

string $min

The minimum alphanumeric value you wish to get.

string $max

The maximum alphanumeric value you wish to get.

int $offset

Optional argument if you wish to start somewhere other than the first element.

int $count

Optional argument if you wish to limit the number of elements returned.

Return Value

RedisCluster|array|false

Array containing the values in the specified range.

Exceptions

RedisClusterException

Examples

<pre>
foreach (array('a', 'b', 'c', 'd', 'e', 'f', 'g') as $k => $char) {
    $redisCluster->zAdd('key', $k, $char);
}

$redisCluster->zRangeByLex('key', '-', '[c'); // array('a', 'b', 'c')
$redisCluster->zRangeByLex('key', '-', '(c'); // array('a', 'b')
$redisCluster->zRevRangeByLex('key', '(c','-'); // array('b', 'a')
</pre>

RedisCluster|bool|array zRevRangeByLex(string $key, string $min, string $max, array|null $options = null)

No description

Parameters

string $key
string $min
string $max
array|null $options

Return Value

RedisCluster|bool|array

Exceptions

RedisClusterException

See also

zRangeByLex()

RedisCluster|int|false zLexCount(string $key, string $min, string $max)

Count the number of members in a sorted set between a given lexicographical range.

Parameters

string $key
string $min
string $max

Return Value

RedisCluster|int|false

The number of elements in the specified score range.

Exceptions

RedisClusterException

Examples

<pre>
foreach (array('a', 'b', 'c', 'd', 'e', 'f', 'g') as $k => $char) {
    $redisCluster->zAdd('key', $k, $char);
}
$redisCluster->zLexCount('key', '[b', '[f'); // 5
</pre>

RedisCluster|int|false zRemRangeByLex(string $key, string $min, string $max)

Remove all members in a sorted set between the given lexicographical range.

Parameters

string $key

The ZSET you wish to run against.

string $min

The minimum alphanumeric value you wish to get.

string $max

The maximum alphanumeric value you wish to get.

Return Value

RedisCluster|int|false

the number of elements removed.

Exceptions

RedisClusterException

Examples

<pre>
foreach (array('a', 'b', 'c', 'd', 'e', 'f', 'g') as $k => $char) {
    $redisCluster->zAdd('key', $k, $char);
}
$redisCluster->zRemRangeByLex('key', '(b','[d'); // 2 , remove element 'c' and 'd'
$redisCluster->zRange('key',0,-1);// array('a','b','e','f','g')
</pre>

RedisCluster|int|false zunionstore(string $dst, array $keys, array|null $weights = null, string|null $aggregate = null)

Add multiple sorted sets and store the resulting sorted set in a new key

Parameters

string $dst
array $keys
array|null $weights
string|null $aggregate

Either "SUM", "MIN", or "MAX": defines the behaviour to use on duplicate entries during the zUnion.

Return Value

RedisCluster|int|false

The number of values in the new sorted set.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->del('k1');
$redisCluster->del('k2');
$redisCluster->del('k3');
$redisCluster->del('ko1');
$redisCluster->del('ko2');
$redisCluster->del('ko3');

$redisCluster->zAdd('k1', 0, 'val0');
$redisCluster->zAdd('k1', 1, 'val1');

$redisCluster->zAdd('k2', 2, 'val2');
$redisCluster->zAdd('k2', 3, 'val3');

$redisCluster->zunionstore('ko1', array('k1', 'k2')); // 4, 'ko1' => array('val0', 'val1', 'val2', 'val3')

// Weighted zunionstore
$redisCluster->zunionstore('ko2', array('k1', 'k2'), array(1, 1)); // 4, 'ko2' => array('val0', 'val1', 'val2','val3')
$redisCluster->zunionstore('ko3', array('k1', 'k2'), array(5, 1)); // 4, 'ko3' => array('val0', 'val2', 'val3','val1')
</pre>

RedisCluster|int|false zinterstore(string $dst, array $keys, array|null $weights = null, string|null $aggregate = null)

Intersect multiple sorted sets and store the resulting sorted set in a new key

Parameters

string $dst
array $keys
array|null $weights
string|null $aggregate

Either "SUM", "MIN", or "MAX": defines the behaviour to use on duplicate entries during the zInterStore.

Return Value

RedisCluster|int|false

The number of values in the new sorted set.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->del('k1');
$redisCluster->del('k2');
$redisCluster->del('k3');

$redisCluster->del('ko1');
$redisCluster->del('ko2');
$redisCluster->del('ko3');
$redisCluster->del('ko4');

$redisCluster->zAdd('k1', 0, 'val0');
$redisCluster->zAdd('k1', 1, 'val1');
$redisCluster->zAdd('k1', 3, 'val3');

$redisCluster->zAdd('k2', 2, 'val1');
$redisCluster->zAdd('k2', 3, 'val3');

$redisCluster->zInterStore('ko1', array('k1', 'k2'));               // 2, 'ko1' => array('val1', 'val3')
$redisCluster->zInterStore('ko2', array('k1', 'k2'), array(1, 1));  // 2, 'ko2' => array('val1', 'val3')

// Weighted zInterStore
$redisCluster->zInterStore('ko3', array('k1', 'k2'), array(1, 5), 'min'); // 2, 'ko3' => array('val1', 'val3')
$redisCluster->zInterStore('ko4', array('k1', 'k2'), array(1, 5), 'max'); // 2, 'ko4' => array('val3', 'val1')
</pre>

RedisCluster|int|false zRem(string $key, string $value, string ...$other_values)

Deletes a specified member from the ordered set.

Parameters

string $key
string $value
string ...$other_values

Return Value

RedisCluster|int|false

Number of deleted values

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->zAdd('z', 1, 'v1', 2, 'v2', 3, 'v3', 4, 'v4' );  // int(2)
$redisCluster->zRem('z', 'v2', 'v3');                           // int(2)
var_dump( $redisCluster->zRange('z', 0, -1) );
//// Output:
//
// array(2) {
//   [0]=> string(2) "v1"
//   [1]=> string(2) "v4"
// }
</pre>

RedisCluster|array|bool|int|string sort(string $key, array|null $options = null)

Sort

Parameters

string $key
array|null $options

$option array(key => value, ...) - optional, with the following keys and values:

  • 'by' => 'somepattern*',
  • 'limit' => array(0, 1),
  • 'get' => 'some_otherpattern*' or an array of patterns,
  • 'sort' => 'asc' or 'desc',
  • 'alpha' => TRUE,
  • 'store' => 'external-key'

Return Value

RedisCluster|array|bool|int|string

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->del('s');
$redisCluster->sadd('s', 5);
$redisCluster->sadd('s', 4);
$redisCluster->sadd('s', 2);
$redisCluster->sadd('s', 1);
$redisCluster->sadd('s', 3);

var_dump($redisCluster->sort('s')); // 1,2,3,4,5
var_dump($redisCluster->sort('s', array('sort' => 'desc'))); // 5,4,3,2,1
var_dump($redisCluster->sort('s', array('sort' => 'desc', 'store' => 'out'))); // (int)5
</pre>

RedisCluster|int|string|false object(string $subcommand, string $key)

Describes the object pointed to by a key.

The information to retrieve (string) and the key (string). Info can be one of the following:

  • "encoding"
  • "refcount"
  • "idletime"

Parameters

string $subcommand
string $key

Return Value

RedisCluster|int|string|false

for "encoding", int for "refcount" and "idletime", FALSE if the key doesn't exist.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->object("encoding", "l"); // → ziplist
$redisCluster->object("refcount", "l"); // → 1
$redisCluster->object("idletime", "l"); // → 400 (in seconds, with a precision of 10 seconds).
</pre>

void subscribe(array $channels, callable $cb)

Subscribe to channels. Warning: this function will probably change in the future.

Parameters

array $channels

an array of channels to subscribe to

callable $cb

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 Value

void

Any non-null return value in the callback will be returned to the caller.

Exceptions

RedisClusterException

Examples

<pre>
function f($redisCluster, $chan, $msg) {
 switch($chan) {
     case 'chan-1':
         ...
         break;

     case 'chan-2':
                    ...
         break;

     case 'chan-2':
         ...
         break;
     }
}

$redisCluster->subscribe(array('chan-1', 'chan-2', 'chan-3'), 'f'); // subscribe to 3 chans
</pre>

void psubscribe(array $patterns, callable $callback)

Subscribe to channels by pattern

Parameters

array $patterns

The number of elements removed from the set.

callable $callback

Either a string or an array with an object and method. The callback will get four arguments ($redis, $pattern, $channel, $message)

Return Value

void

Any non-null return value in the callback will be returned to the caller.

Exceptions

RedisClusterException

Examples

<pre>
function psubscribe($redisCluster, $pattern, $chan, $msg) {
 echo "Pattern: $pattern\n";
 echo "Channel: $chan\n";
 echo "Payload: $msg\n";
}
</pre>

bool|array unsubscribe(array $channels)

Unsubscribes the client from the given channels, or from all of them if none is given.

Parameters

array $channels

Return Value

bool|array

Exceptions

RedisClusterException

bool|array punsubscribe(string $pattern, string ...$other_patterns)

Unsubscribes the client from the given patterns, or from all of them if none is given.

Parameters

string $pattern
string ...$other_patterns

Return Value

bool|array

Exceptions

RedisClusterException

mixed evalsha(string $script_sha, array $args = [], int $num_keys = 0)

Evaluate a LUA script serverside, from the SHA1 hash of the script instead of the script itself.

In order to run this command Redis will have to have already loaded the script, either by running it or via the SCRIPT LOAD command.

Parameters

string $script_sha
array $args
int $num_keys

Return Value

mixed eval()

Exceptions

RedisClusterException

See also

eval()

Examples

<pre>
$script = 'return 1';
$sha = $redisCluster->script('load', $script);
$redisCluster->evalsha($sha); // Returns 1
</pre>

bool|array scan(null|int|string $iterator, string|array $key_or_address, string|null $pattern = null, int $count = 0)

Scan the keyspace for keys.

Parameters

null|int|string $iterator

&$iterator Iterator, initialized to NULL.

string|array $key_or_address

Node identified by key or host/port array

string|null $pattern

Pattern to match.

int $count

Count of keys per iteration (only a suggestion to Redis).

Return Value

bool|array

This function will return an array of keys or FALSE if there are no more keys.

Exceptions

RedisClusterException

Examples

<pre>
$iterator = null;
while($keys = $redisCluster->scan($iterator)) {
    foreach($keys as $key) {
        echo $key . PHP_EOL;
    }
}
</pre>

array|false sscan(string $key, null|int|string $iterator, string|null $pattern = null, int $count = 0)

Scan a set for members.

Parameters

string $key

The set to search.

null|int|string $iterator

&$iterator LONG (reference) to the iterator as we go.

string|null $pattern

String, optional pattern to match against.

int $count

How many members to return at a time (Redis might return a different amount).

Return Value

array|false

PHPRedis will return an array of keys or FALSE when we're done iterating.

Exceptions

RedisClusterException

Examples

<pre>
$iterator = null;
while ($members = $redisCluster->sscan('set', $iterator)) {
    foreach ($members as $member) {
        echo $member . PHP_EOL;
    }
}
</pre>

RedisCluster|bool|array zscan(string $key, null|int|string $iterator, string|null $pattern = null, int $count = 0)

Scan a sorted set for members, with optional pattern and count.

Parameters

string $key

String, the set to scan.

null|int|string $iterator

Long (reference), initialized to NULL.

string|null $pattern

String (optional), the pattern to match.

int $count

How many keys to return per iteration (Redis might return a different number).

Return Value

RedisCluster|bool|array

PHPRedis will return matching keys from Redis, or FALSE when iteration is complete.

Exceptions

RedisClusterException

Examples

<pre>
$iterator = null;
while ($members = $redis->zscan('zset', $iterator)) {
    foreach ($members as $member => $score) {
        echo $member . ' => ' . $score . PHP_EOL;
    }
}
</pre>

array|bool hscan(string $key, null|int|string $iterator, string|null $pattern = null, int $count = 0)

Scan a HASH value for members, with an optional pattern and count.

Parameters

string $key
null|int|string $iterator
string|null $pattern

Optional pattern to match against.

int $count

How many keys to return in a go (only a sugestion to Redis).

Return Value

array|bool

An array of members that match our pattern.

Exceptions

RedisClusterException

Examples

<pre>
$iterator = null;
while($elements = $redisCluster->hscan('hash', $iterator)) {
   foreach($elements as $key => $value) {
        echo $key . ' => ' . $value . PHP_EOL;
    }
}
</pre>

int getMode()

Detect whether we're in ATOMIC/MULTI/PIPELINE mode.

Return Value

int

Either RedisCluster::ATOMIC, RedisCluster::MULTI or RedisCluster::PIPELINE

Exceptions

RedisClusterException

Examples

$redisCluster->getMode();

string|null getLastError()

The last error message (if any)

Return Value

string|null

A string with the last returned script based error message, or NULL if there is no error

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->eval('this-is-not-lua');
$err = $redisCluster->getLastError();
// "ERR Error compiling script (new function): user_script:1: '=' expected near '-'"
</pre>

bool clearLastError()

Clear the last error message

Return Value

bool true

Examples

<pre>
$redisCluster->set('x', 'a');
$redisCluster->incr('x');
$err = $redisCluster->getLastError();
// "ERR value is not an integer or out of range"
$redisCluster->clearLastError();
$err = $redisCluster->getLastError();
// NULL
</pre>

mixed getOption(int $option)

Get client option

Parameters

int $option parameter

Return Value

mixed

Parameter value.

Examples

// return RedisCluster::SERIALIZER_NONE, RedisCluster::SERIALIZER_PHP, or RedisCluster::SERIALIZER_IGBINARY.
$redisCluster->getOption(RedisCluster::OPT_SERIALIZER);

bool setOption(int $option, mixed $value)

Set client option.

Parameters

int $option parameter
mixed $value

parameter value

Return Value

bool

TRUE on success, FALSE on error.

Examples

<pre>
$redisCluster->setOption(RedisCluster::OPT_SERIALIZER, RedisCluster::SERIALIZER_NONE);        // don't serialize data
$redisCluster->setOption(RedisCluster::OPT_SERIALIZER, RedisCluster::SERIALIZER_PHP);         // use built-in serialize/unserialize
$redisCluster->setOption(RedisCluster::OPT_SERIALIZER, RedisCluster::SERIALIZER_IGBINARY);    // use igBinary serialize/unserialize
$redisCluster->setOption(RedisCluster::OPT_PREFIX, 'myAppName:');                             // use custom prefix on all keys
</pre>

bool|string _prefix(string $key)

A utility method to prefix the key with the prefix setting for phpredis.

Parameters

string $key

The key you wish to prefix

Return Value

bool|string

If a prefix is set up, the key now prefixed. If there is no prefix, the key will be returned unchanged.

Examples

<pre>
$redisCluster->setOption(RedisCluster::OPT_PREFIX, 'my-prefix:');
$redisCluster->_prefix('my-key'); // Will return 'my-prefix:my-key'
</pre>

bool|string _serialize(mixed $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'.

Parameters

mixed $value

The value to be serialized.

Return Value

bool|string

Examples

<pre>
$redisCluster->setOption(RedisCluster::OPT_SERIALIZER, RedisCluster::SERIALIZER_NONE);
$redisCluster->_serialize("foo"); // returns "foo"
$redisCluster->_serialize(Array()); // Returns "Array"
$redisCluster->_serialize(new stdClass()); // Returns "Object"

$redisCluster->setOption(RedisCluster::OPT_SERIALIZER, RedisCluster::SERIALIZER_PHP);
$redisCluster->_serialize("foo"); // Returns 's:3:"foo";'
</pre>

mixed _unserialize(string $value)

A utility method to unserialize data with whatever serializer is set up. If there is no serializer set, the value will be returned unchanged. If there is a serializer set up, and the data passed in is malformed, an exception will be thrown. This can be useful if phpredis is serializing values, and you return something from redis in a LUA script that is serialized.

Parameters

string $value

The value to be unserialized

Return Value

mixed

Examples

<pre>
$redisCluster->setOption(RedisCluster::OPT_SERIALIZER, RedisCluster::SERIALIZER_PHP);
$redisCluster->_unserialize('a:3:{i:0;i:1;i:1;i:2;i:2;i:3;}'); // Will return Array(1,2,3)
</pre>

array _masters()

Return all redis master nodes

Return Value

array

Examples

<pre>
$redisCluster->_masters(); // Will return [[0=>'127.0.0.1','6379'],[0=>'127.0.0.1','6380']]
</pre>

RedisCluster|bool multi(int $value = Redis::MULTI)

Enter and exit transactional mode.

Parameters

int $value

RedisCluster::MULTI|RedisCluster::PIPELINE Defaults to RedisCluster::MULTI. A RedisCluster::MULTI block of commands runs as a single transaction; a RedisCluster::PIPELINE block is simply transmitted faster to the server, but without any guarantee of atomicity. discard cancels a transaction.

Return Value

RedisCluster|bool

returns the RedisCluster instance and enters multi-mode.

Exceptions

RedisClusterException

Examples

<pre>
$ret = $redisCluster->multi()
     ->set('key1', 'val1')
     ->get('key1')
     ->set('key2', 'val2')
     ->get('key2')
     ->exec();

//$ret == array (
//    0 => TRUE,
//    1 => 'val1',
//    2 => TRUE,
//    3 => 'val2');
</pre>

array|false exec()

No description

Return Value

array|false

Exceptions

RedisClusterException

See also

multi()

bool discard()

No description

Return Value

bool

See also

multi()

RedisCluster|bool watch(string $key, string ...$other_keys)

Watches a key for modifications by another client. If the key is modified between WATCH and EXEC, the MULTI/EXEC transaction will fail (return FALSE). unwatch cancels all the watching of all keys by this client.

Parameters

string $key
string ...$other_keys

Return Value

RedisCluster|bool

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->watch('x');
// long code here during the execution of which other clients could well modify `x`
$ret = $redisCluster->multi()
         ->incr('x')
         ->exec();
// $ret = FALSE if x has been modified between the call to WATCH and the call to EXEC.
</pre>

bool unwatch()

No description

Return Value

bool

Exceptions

RedisClusterException

See also

watch()

RedisCluster|bool save(string|array $key_or_address)

Performs a synchronous save at a specific node.

Parameters

string|array $key_or_address

key or [host,port]

Return Value

RedisCluster|bool

TRUE in case of success, FALSE in case of failure. If a save is already running, this command will fail and return FALSE.

Exceptions

RedisClusterException

Examples

$redisCluster->save('x'); //key
$redisCluster->save(['127.0.0.1',6379]); //[host,port]

RedisCluster|bool bgSave(string|array $key_or_address)

Performs a background save at a specific node.

Parameters

string|array $key_or_address

key or [host,port]

Return Value

RedisCluster|bool

TRUE in case of success, FALSE in case of failure. If a save is already running, this command will fail and return FALSE.

Exceptions

RedisClusterException

RedisCluster|bool flushDB(string|array $key_or_address, bool $async = false)

Removes all entries from the current database at a specific node.

Parameters

string|array $key_or_address

key or [host,port]

bool $async

Return Value

RedisCluster|bool

Always TRUE.

Exceptions

RedisClusterException

RedisCluster|bool flushAll(string|array $key_or_address, bool $async = false)

Removes all entries from all databases at a specific node.

Parameters

string|array $key_or_address

key or [host,port]

bool $async

Return Value

RedisCluster|bool

Always TRUE.

Exceptions

RedisClusterException

RedisCluster|int dbSize(string|array $key_or_address)

Returns the current database's size at a specific node.

Parameters

string|array $key_or_address

key or [host,port]

Return Value

RedisCluster|int

DB size, in number of keys.

Exceptions

RedisClusterException

Examples

<pre>
$count = $redisCluster->dbSize('x');
echo "Redis has $count keys\n";
</pre>

RedisCluster|bool bgrewriteaof(string|array $key_or_address)

Starts the background rewrite of AOF (Append-Only File) at a specific node.

Parameters

string|array $key_or_address

key or [host,port]

Return Value

RedisCluster|bool

TRUE in case of success, FALSE in case of failure.

Exceptions

RedisClusterException

Examples

$redisCluster->bgrewriteaof('x');

RedisCluster|int|false lastSave(string|array $key_or_address)

Returns the timestamp of the last disk save at a specific node.

Parameters

string|array $key_or_address

key or [host,port]

Return Value

RedisCluster|int|false timestamp.

Exceptions

RedisClusterException

Examples

$redisCluster->lastSave('x');

RedisCluster|array|false info(string|array $key_or_address, string ...$sections)

Returns an associative array of strings and integers

Parameters

string|array $key_or_address
string ...$sections

SERVER | CLIENTS | MEMORY | PERSISTENCE | STATS | REPLICATION | CPU | CLASTER | KEYSPACE | COMANDSTATS

Returns an associative array of strings and integers, with the following keys:

  • redis_version
  • redis_git_sha1
  • redis_git_dirty
  • redis_build_id
  • redis_mode
  • os
  • arch_bits
  • multiplexing_api
  • atomicvar_api
  • gcc_version
  • process_id
  • run_id
  • tcp_port
  • uptime_in_seconds
  • uptime_in_days
  • hz
  • lru_clock
  • executable
  • config_file
  • connected_clients
  • client_longest_output_list
  • client_biggest_input_buf
  • blocked_clients
  • used_memory
  • used_memory_human
  • used_memory_rss
  • used_memory_rss_human
  • used_memory_peak
  • used_memory_peak_human
  • used_memory_peak_perc
  • used_memory_peak
  • used_memory_overhead
  • used_memory_startup
  • used_memory_dataset
  • used_memory_dataset_perc
  • total_system_memory
  • total_system_memory_human
  • used_memory_lua
  • used_memory_lua_human
  • maxmemory
  • maxmemory_human
  • maxmemory_policy
  • mem_fragmentation_ratio
  • mem_allocator
  • active_defrag_running
  • lazyfree_pending_objects
  • mem_fragmentation_ratio
  • loading
  • rdb_changes_since_last_save
  • rdb_bgsave_in_progress
  • rdb_last_save_time
  • rdb_last_bgsave_status
  • rdb_last_bgsave_time_sec
  • rdb_current_bgsave_time_sec
  • rdb_last_cow_size
  • aof_enabled
  • aof_rewrite_in_progress
  • aof_rewrite_scheduled
  • aof_last_rewrite_time_sec
  • aof_current_rewrite_time_sec
  • aof_last_bgrewrite_status
  • aof_last_write_status
  • aof_last_cow_size
  • changes_since_last_save
  • aof_current_size
  • aof_base_size
  • aof_pending_rewrite
  • aof_buffer_length
  • aof_rewrite_buffer_length
  • aof_pending_bio_fsync
  • aof_delayed_fsync
  • loading_start_time
  • loading_total_bytes
  • loading_loaded_bytes
  • loading_loaded_perc
  • loading_eta_seconds
  • total_connections_received
  • total_commands_processed
  • instantaneous_ops_per_sec
  • total_net_input_bytes
  • total_net_output_bytes
  • instantaneous_input_kbps
  • instantaneous_output_kbps
  • rejected_connections
  • maxclients
  • sync_full
  • sync_partial_ok
  • sync_partial_err
  • expired_keys
  • evicted_keys
  • keyspace_hits
  • keyspace_misses
  • pubsub_channels
  • pubsub_patterns
  • latest_fork_usec
  • migrate_cached_sockets
  • slave_expires_tracked_keys
  • active_defrag_hits
  • active_defrag_misses
  • active_defrag_key_hits
  • active_defrag_key_misses
  • role
  • master_replid
  • master_replid2
  • master_repl_offset
  • second_repl_offset
  • repl_backlog_active
  • repl_backlog_size
  • repl_backlog_first_byte_offset
  • repl_backlog_histlen
  • master_host
  • master_port
  • master_link_status
  • master_last_io_seconds_ago
  • master_sync_in_progress
  • slave_repl_offset
  • slave_priority
  • slave_read_only
  • master_sync_left_bytes
  • master_sync_last_io_seconds_ago
  • master_link_down_since_seconds
  • connected_slaves
  • min-slaves-to-write
  • min-replicas-to-write
  • min_slaves_good_slaves
  • used_cpu_sys
  • used_cpu_user
  • used_cpu_sys_children
  • used_cpu_user_children
  • cluster_enabled

Return Value

RedisCluster|array|false

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->info();

or

$redisCluster->info("COMMANDSTATS"); //Information on the commands that have been run (>=2.6 only)
$redisCluster->info("CPU"); // just CPU information from Redis INFO
</pre>

mixed role(string|array $key_or_address)

Since: redis >= 2.8.12.

No description

Parameters

string|array $key_or_address

key or [host,port]

Return Value

mixed

Returns the role of the instance in the context of replication

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->role(['127.0.0.1',6379]);
// [ 0=>'master',1 => 3129659, 2 => [ ['127.0.0.1','9001','3129242'], ['127.0.0.1','9002','3129543'] ] ]
</pre>

RedisCluster|bool|string randomKey(string|array $key_or_address)

Returns a random key at the specified node

Parameters

string|array $key_or_address

key or [host,port]

Return Value

RedisCluster|bool|string

an existing key in redis.

Exceptions

RedisClusterException

Examples

<pre>
$key = $redisCluster->randomKey('x');
$surprise = $redisCluster->get($key);  // who knows what's in there.
</pre>

RedisCluster|bool|array time(string|array $key_or_address)

Return the specified node server time.

Parameters

string|array $key_or_address

key or [host,port]

Return Value

RedisCluster|bool|array

If successfully, the time will come back as an associative array with element zero being the unix timestamp, and element one being microseconds.

Exceptions

RedisClusterException

Examples

<pre>
var_dump( $redisCluster->time('x') );
//// Output:
//
// array(2) {
//   [0] => string(10) "1342364352"
//   [1] => string(6) "253002"
// }
</pre>

mixed ping(string|array $key_or_address, string|null $message = null)

Check the specified node status

Parameters

string|array $key_or_address

key or [host,port]

string|null $message

Return Value

mixed

STRING: +PONG on success. Throws a RedisClusterException object on connectivity error, as described above.

Exceptions

RedisClusterException

RedisCluster|string|false echo(string|array $key_or_address, string $msg)

Returns message.

Parameters

string|array $key_or_address

key or [host,port]

string $msg

Return Value

RedisCluster|string|false

Exceptions

RedisClusterException

mixed command(mixed ...$extra_args)

Returns Array reply of details about all Redis Cluster commands.

Parameters

mixed ...$extra_args

Return Value

mixed

array | bool

Exceptions

RedisClusterException

mixed rawcommand(string|array $key_or_address, string $command, mixed ...$args)

Send arbitrary things to the redis server at the specified node

Parameters

string|array $key_or_address

key or [host,port]

string $command

Required command to send to the server.

mixed ...$args

Optional variable amount of arguments to send to the server.

Return Value

mixed

Exceptions

RedisClusterException

mixed cluster(string|array $key_or_address, string $command, mixed ...$extra_args)

Since: redis >= 3.0

Executes cluster command

Parameters

string|array $key_or_address

key or [host,port]

string $command

Required command to send to the server.

mixed ...$extra_args

Optional variable amount of arguments to send to the server.

Return Value

mixed

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->cluster(['127.0.0.1',6379],'INFO');
</pre>

array|string|bool client(string|array $key_or_address, string $subcommand, string|null $arg = null)

Allows you to get information of the cluster client

Parameters

string|array $key_or_address

key or [host,port]

string $subcommand

can be: 'LIST', 'KILL', 'GETNAME', or 'SETNAME'

string|null $arg

optional arguments

Return Value

array|string|bool

Exceptions

RedisClusterException

mixed config(string|array $key_or_address, string $subcommand, mixed ...$extra_args)

Get or Set the redis config keys.

Parameters

string|array $key_or_address

key or [host,port]

string $subcommand

either GET or SET

mixed ...$extra_args

Return Value

mixed

Associative array for GET, key -> value

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->config(['127.0.0.1',6379], "GET", "*max-*-entries*");
$redisCluster->config(['127.0.0.1',6379], "SET", "dir", "/var/run/redis/dumps/");
</pre>

mixed pubsub(string|array $key_or_address, string ...$values)

A command allowing you to get information on the Redis pub/sub system.

Parameters

string|array $key_or_address

key or [host,port]

string ...$values

Optional, variant. For the "channels" subcommand, you can pass a string pattern. For "numsub" an array of channel names

Return Value

mixed

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.

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->pubsub(['127.0.0.1',6379], 'channels'); // All channels
$redisCluster->pubsub(['127.0.0.1',6379], 'channels', '*pattern*'); // Just channels matching your pattern
$redisCluster->pubsub(['127.0.0.1',6379], 'numsub', array('chan1', 'chan2')); // Get subscriber counts for
'chan1' and 'chan2'
$redisCluster->pubsub(['127.0.0.1',6379], 'numpat'); // Get the number of pattern subscribers
</pre>

mixed script(string|array $key_or_address, mixed ...$args)

Execute the Redis SCRIPT command to perform various operations on the scripting subsystem.

Parameters

string|array $key_or_address

key or [host,port]

mixed ...$args

Return Value

mixed

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->script(['127.0.0.1',6379], 'load', $script);
$redisCluster->script(['127.0.0.1',6379], 'flush');
$redisCluster->script(['127.0.0.1',6379], 'kill');
$redisCluster->script(['127.0.0.1',6379], 'exists', $script1, [$script2, $script3, ...]);
</pre>

SCRIPT LOAD will return the SHA1 hash of the passed script on success, and FALSE on failure.
SCRIPT FLUSH should always return TRUE
SCRIPT KILL will return true if a script was able to be killed and false if not
SCRIPT EXISTS will return an array with TRUE or FALSE for each passed script

mixed slowlog(string|array $key_or_address, mixed ...$args)

This function is used in order to read and reset the Redis slow queries log.

Parameters

string|array $key_or_address

key or [host,port]

mixed ...$args

Return Value

mixed

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->slowlog(['127.0.0.1',6379],'get','2');
</pre>

RedisCluster|int|false geoadd(string $key, float $lng, float $lat, string $member, mixed ...$other_triples_and_options)

Add one or more geospatial items in the geospatial index represented using a sorted set

Parameters

string $key
float $lng
float $lat
string $member
mixed ...$other_triples_and_options

Return Value

RedisCluster|int|false

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->geoadd('Sicily', 13.361389, 38.115556, 'Palermo'); // int(1)
$redisCluster->geoadd('Sicily', 15.087269, 37.502669, "Catania"); // int(1)
</pre>

RedisCluster|array|false geohash(string $key, string $member, string ...$other_members)

Returns members of a geospatial index as standard geohash strings

Parameters

string $key
string $member
string ...$other_members

Return Value

RedisCluster|array|false

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->geoAdd('Sicily', 13.361389, 38.115556, 'Palermo'); // int(1)
$redisCluster->geoAdd('Sicily', 15.087269, 37.502669, "Catania"); // int(1)
$redisCluster->geohash('Sicily','Palermo','Catania');//['sqc8b49rny0','sqdtr74hyu0']
</pre>

RedisCluster|array|false geopos(string $key, string $member, string ...$other_members)

Returns longitude and latitude of members of a geospatial index

Parameters

string $key
string $member
string ...$other_members

Return Value

RedisCluster|array|false

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->geoAdd('Sicily', 15.087269, 37.502669, "Catania"); // int(1)
$redisCluster->geopos('Sicily','Palermo');//[['13.36138933897018433','38.11555639549629859']]
</pre>

RedisCluster|float|false geodist(string $key, string $src, string $dest, string|null $unit = null)

Returns the distance between two members of a geospatial index

Parameters

string $key
string $src
string $dest
string|null $unit

The unit must be one of the following, and defaults to meters: m for meters. km for kilometers. mi for miles. ft for feet.

Return Value

RedisCluster|float|false

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->geoAdd('Sicily', 13.361389, 38.115556, 'Palermo'); // int(1)
$redisCluster->geoAdd('Sicily', 15.087269, 37.502669, "Catania"); // int(1)
$redisCluster->geodist('Sicily', 'Palermo' ,'Catania'); // float(166274.1516)
$redisCluster->geodist('Sicily', 'Palermo','Catania', 'km'); // float(166.2742)
</pre>

mixed georadius(string $key, float $lng, float $lat, float $radius, string $unit, array $options = [])

Query a sorted set representing a geospatial index to fetch members matching a given maximum distance from a point

Parameters

string $key
float $lng
float $lat
float $radius
string $unit

String can be: "m" for meters; "km" for kilometers , "mi" for miles, or "ft" for feet.

array $options

Return Value

mixed

Exceptions

RedisClusterException

Examples

<pre>
$redisCluster->del('Sicily');
$redisCluster->geoAdd('Sicily', 12.361389, 35.115556, 'Palermo'); // int(1)
$redisCluster->geoAdd('Sicily', 15.087269, 37.502669, "Catania"); // int(1)
$redisCluster->geoAdd('Sicily', 13.3585, 35.330022, "Agrigento"); // int(1)

var_dump( $redisCluster->geoRadius('Sicily',13.3585, 35.330022, 300, 'km', ['WITHDIST' ,'DESC']) );

array(3) {
   [0]=>
  array(2) {
       [0]=>
    string(7) "Catania"
       [1]=>
    string(8) "286.9362"
  }
  [1]=>
  array(2) {
       [0]=>
    string(7) "Palermo"
       [1]=>
    string(7) "93.6874"
  }
  [2]=>
  array(2) {
       [0]=>
    string(9) "Agrigento"
       [1]=>
    string(6) "0.0002"
  }
}
var_dump( $redisCluster->geoRadiusByMember('Sicily','Agrigento', 100, 'km', ['WITHDIST' ,'DESC']) );

* array(2) {
   [0]=>
  array(2) {
       [0]=>
    string(7) "Palermo"
       [1]=>
    string(7) "93.6872"
  }
  [1]=>
  array(2) {
       [0]=>
    string(9) "Agrigento"
       [1]=>
    string(6) "0.0000"
  }
}

<pre>

mixed georadiusbymember(string $key, string $member, float $radius, string $unit, array $options = [])

Query a sorted set representing a geospatial index to fetch members matching a given maximum distance from a member

Parameters

string $key
string $member
float $radius
string $unit
array $options

Return Value

mixed

Exceptions

RedisClusterException

See also

geoRadius

string _compress(string $value)

No description

Parameters

string $value

Return Value

string

string _uncompress(string $value)

No description

Parameters

string $value

Return Value

string

string _pack(mixed $value)

No description

Parameters

mixed $value

Return Value

string

mixed _unpack(string $value)

No description

Parameters

string $value

Return Value

mixed

string|null _redir()

No description

Return Value

string|null

mixed acl(string|array $key_or_address, string $subcmd, string ...$args)

No description

Parameters

string|array $key_or_address
string $subcmd
string ...$args

Return Value

mixed

RedisCluster|array|false waitaof(string|array $key_or_address, int $numlocal, int $numreplicas, int $timeout)

No description

Parameters

string|array $key_or_address
int $numlocal
int $numreplicas
int $timeout

Return Value

RedisCluster|array|false

Redis|string|false lMove(string $src, string $dst, string $wherefrom, string $whereto)

No description

Parameters

string $src
string $dst
string $wherefrom
string $whereto

Return Value

Redis|string|false

Redis|string|false blmove(string $src, string $dst, string $wherefrom, string $whereto, float $timeout)

No description

Parameters

string $src
string $dst
string $wherefrom
string $whereto
float $timeout

Return Value

Redis|string|false

array bzPopMax(string|array $key, string|int $timeout_or_key, mixed ...$extra_args)

No description

Parameters

string|array $key
string|int $timeout_or_key
mixed ...$extra_args

Return Value

array

array bzPopMin(string|array $key, string|int $timeout_or_key, mixed ...$extra_args)

No description

Parameters

string|array $key
string|int $timeout_or_key
mixed ...$extra_args

Return Value

array

RedisCluster|array|null|false bzmpop(float $timeout, array $keys, string $from, int $count = 1)

No description

Parameters

float $timeout
array $keys
string $from
int $count

Return Value

RedisCluster|array|null|false

RedisCluster|array|null|false zmpop(array $keys, string $from, int $count = 1)

No description

Parameters

array $keys
string $from
int $count

Return Value

RedisCluster|array|null|false

RedisCluster|array|null|false blmpop(float $timeout, array $keys, string $from, int $count = 1)

No description

Parameters

float $timeout
array $keys
string $from
int $count

Return Value

RedisCluster|array|null|false

RedisCluster|array|null|false lmpop(array $keys, string $from, int $count = 1)

No description

Parameters

array $keys
string $from
int $count

Return Value

RedisCluster|array|null|false

RedisCluster|bool copy(string $src, string $dst, array|null $options = null)

No description

Parameters

string $src
string $dst
array|null $options

Return Value

RedisCluster|bool

float decrbyfloat(string $key, float $value)

No description

Parameters

string $key
float $value

Return Value

float

mixed eval(string $script, array $args = [], int $num_keys = 0)

No description

Parameters

string $script
array $args
int $num_keys

Return Value

mixed

mixed eval_ro(string $script, array $args = [], int $num_keys = 0)

No description

Parameters

string $script
array $args
int $num_keys

Return Value

mixed

mixed evalsha_ro(string $script_sha, array $args = [], int $num_keys = 0)

No description

Parameters

string $script_sha
array $args
int $num_keys

Return Value

mixed

RedisCluster|int|bool touch(mixed $key, mixed ...$other_keys)

No description

Parameters

mixed $key
mixed ...$other_keys

Return Value

RedisCluster|int|bool

RedisCluster|int|false expiretime(string $key)

No description

Parameters

string $key

Return Value

RedisCluster|int|false

RedisCluster|int|false pexpiretime(string $key)

No description

Parameters

string $key

Return Value

RedisCluster|int|false

mixed georadius_ro(string $key, float $lng, float $lat, float $radius, string $unit, array $options = [])

No description

Parameters

string $key
float $lng
float $lat
float $radius
string $unit
array $options

Return Value

mixed

mixed georadiusbymember_ro(string $key, string $member, float $radius, string $unit, array $options = [])

No description

Parameters

string $key
string $member
float $radius
string $unit
array $options

Return Value

mixed

RedisCluster|array geosearch(string $key, array|string $position, array|int|float $shape, string $unit, array $options = [])

No description

Parameters

string $key
array|string $position
array|int|float $shape
string $unit
array $options

Return Value

RedisCluster|array

RedisCluster|array|int|false geosearchstore(string $dst, string $src, array|string $position, array|int|float $shape, string $unit, array $options = [])

No description

Parameters

string $dst
string $src
array|string $position
array|int|float $shape
string $unit
array $options

Return Value

RedisCluster|array|int|false

mixed getDel(string $key)

No description

Parameters

string $key

Return Value

mixed

RedisCluster|array|false getWithMeta(string $key)

No description

Parameters

string $key

Return Value

RedisCluster|array|false

RedisCluster|string|false getEx(string $key, array $options = [])

No description

Parameters

string $key
array $options

Return Value

RedisCluster|string|false

RedisCluster|string|array|int|false lcs(string $key1, string $key2, array|null $options = null)

No description

Parameters

string $key1
string $key2
array|null $options

Return Value

RedisCluster|string|array|int|false

array|false getTransferredBytes()

No description

Return Value

array|false

void clearTransferredBytes()

No description

Return Value

void

Redis|int|false expiremember(string $key, string $field, int $ttl, string|null $unit = null)

No description

Parameters

string $key
string $field
int $ttl
string|null $unit

Return Value

Redis|int|false

Redis|int|false expirememberat(string $key, string $field, int $timestamp)

No description

Parameters

string $key
string $field
int $timestamp

Return Value

Redis|int|false

RedisCluster|string|array hRandField(string $key, array|null $options = null)

No description

Parameters

string $key
array|null $options

Return Value

RedisCluster|string|array

RedisCluster|int|false hStrLen(string $key, string $field)

No description

Parameters

string $key
string $field

Return Value

RedisCluster|int|false

RedisCluster|array|false hexpire(string $key, int $ttl, array $fields, string|null $mode = null)

No description

Parameters

string $key
int $ttl
array $fields
string|null $mode

Return Value

RedisCluster|array|false

RedisCluster|array|false hpexpire(string $key, int $ttl, array $fields, string|null $mode = null)

No description

Parameters

string $key
int $ttl
array $fields
string|null $mode

Return Value

RedisCluster|array|false

RedisCluster|array|false hexpireat(string $key, int $time, array $fields, string|null $mode = null)

No description

Parameters

string $key
int $time
array $fields
string|null $mode

Return Value

RedisCluster|array|false

RedisCluster|array|false hpexpireat(string $key, int $mstime, array $fields, string|null $mode = null)

No description

Parameters

string $key
int $mstime
array $fields
string|null $mode

Return Value

RedisCluster|array|false

RedisCluster|array|false httl(string $key, array $fields)

No description

Parameters

string $key
array $fields

Return Value

RedisCluster|array|false

RedisCluster|array|false hpttl(string $key, array $fields)

No description

Parameters

string $key
array $fields

Return Value

RedisCluster|array|false

RedisCluster|array|false hexpiretime(string $key, array $fields)

No description

Parameters

string $key
array $fields

Return Value

RedisCluster|array|false

RedisCluster|array|false hpexpiretime(string $key, array $fields)

No description

Parameters

string $key
array $fields

Return Value

RedisCluster|array|false

RedisCluster|array|false hpersist(string $key, array $fields)

No description

Parameters

string $key
array $fields

Return Value

RedisCluster|array|false

Redis|null|bool|int|array lPos(string $key, mixed $value, array|null $options = null)

No description

Parameters

string $key
mixed $value
array|null $options

Return Value

Redis|null|bool|int|array

RedisCluster|int|false sintercard(array $keys, int $limit = -1)

No description

Parameters

array $keys
int $limit

Return Value

RedisCluster|int|false

RedisCluster|array|false sMisMember(string $key, string $member, string ...$other_members)

No description

Parameters

string $key
string $member
string ...$other_members

Return Value

RedisCluster|array|false

RedisCluster|array|bool|int|string sort_ro(string $key, array|null $options = null)

No description

Parameters

string $key
array|null $options

Return Value

RedisCluster|array|bool|int|string

No description

Parameters

array|string $key
string ...$other_keys

Return Value

RedisCluster|int|false

RedisCluster|int|false xack(string $key, string $group, array $ids)

No description

Parameters

string $key
string $group
array $ids

Return Value

RedisCluster|int|false

RedisCluster|string|false xadd(string $key, string $id, array $values, int $maxlen = 0, bool $approx = false)

No description

Parameters

string $key
string $id
array $values
int $maxlen
bool $approx

Return Value

RedisCluster|string|false

RedisCluster|string|array|false xclaim(string $key, string $group, string $consumer, int $min_iddle, array $ids, array $options)

No description

Parameters

string $key
string $group
string $consumer
int $min_iddle
array $ids
array $options

Return Value

RedisCluster|string|array|false

RedisCluster|int|false xdel(string $key, array $ids)

No description

Parameters

string $key
array $ids

Return Value

RedisCluster|int|false

mixed xgroup(string $operation, string|null $key = null, string|null $group = null, string|null $id_or_consumer = null, bool $mkstream = false, int $entries_read = -2)

No description

Parameters

string $operation
string|null $key
string|null $group
string|null $id_or_consumer
bool $mkstream
int $entries_read

Return Value

mixed

RedisCluster|bool|array xautoclaim(string $key, string $group, string $consumer, int $min_idle, string $start, int $count = -1, bool $justid = false)

No description

Parameters

string $key
string $group
string $consumer
int $min_idle
string $start
int $count
bool $justid

Return Value

RedisCluster|bool|array

mixed xinfo(string $operation, string|null $arg1 = null, string|null $arg2 = null, int $count = -1)

No description

Parameters

string $operation
string|null $arg1
string|null $arg2
int $count

Return Value

mixed

RedisCluster|int|false xlen(string $key)

No description

Parameters

string $key

Return Value

RedisCluster|int|false

RedisCluster|array|false xpending(string $key, string $group, string|null $start = null, string|null $end = null, int $count = -1, string|null $consumer = null)

No description

Parameters

string $key
string $group
string|null $start
string|null $end
int $count
string|null $consumer

Return Value

RedisCluster|array|false

RedisCluster|bool|array xrange(string $key, string $start, string $end, int $count = -1)

No description

Parameters

string $key
string $start
string $end
int $count

Return Value

RedisCluster|bool|array

RedisCluster|bool|array xread(array $streams, int $count = -1, int $block = -1)

No description

Parameters

array $streams
int $count
int $block

Return Value

RedisCluster|bool|array

RedisCluster|bool|array xreadgroup(string $group, string $consumer, array $streams, int $count = 1, int $block = 1)

No description

Parameters

string $group
string $consumer
array $streams
int $count
int $block

Return Value

RedisCluster|bool|array

RedisCluster|bool|array xrevrange(string $key, string $start, string $end, int $count = -1)

No description

Parameters

string $key
string $start
string $end
int $count

Return Value

RedisCluster|bool|array

RedisCluster|int|false xtrim(string $key, int $maxlen, bool $approx = false, bool $minid = false, int $limit = -1)

No description

Parameters

string $key
int $maxlen
bool $approx
bool $minid
int $limit

Return Value

RedisCluster|int|false

RedisCluster|int|false zintercard(array $keys, int $limit = -1)

No description

Parameters

array $keys
int $limit

Return Value

RedisCluster|int|false

RedisCluster|bool|array zPopMax(string $key, int|null $value = null)

No description

Parameters

string $key
int|null $value

Return Value

RedisCluster|bool|array

RedisCluster|bool|array zPopMin(string $key, int|null $value = null)

No description

Parameters

string $key
int|null $value

Return Value

RedisCluster|bool|array

RedisCluster|int|false zrangestore(string $dstkey, string $srckey, int $start, int $end, array|bool|null $options = null)

No description

Parameters

string $dstkey
string $srckey
int $start
int $end
array|bool|null $options

Return Value

RedisCluster|int|false

RedisCluster|string|array zRandMember(string $key, array|null $options = null)

No description

Parameters

string $key
array|null $options

Return Value

RedisCluster|string|array

Redis|array|false zMscore(string $key, mixed $member, mixed ...$other_members)

No description

Parameters

string $key
mixed $member
mixed ...$other_members

Return Value

Redis|array|false

RedisCluster|array|false zinter(array $keys, array|null $weights = null, array|null $options = null)

No description

Parameters

array $keys
array|null $weights
array|null $options

Return Value

RedisCluster|array|false

RedisCluster|int|false zdiffstore(string $dst, array $keys)

No description

Parameters

string $dst
array $keys

Return Value

RedisCluster|int|false

RedisCluster|array|false zunion(array $keys, array|null $weights = null, array|null $options = null)

No description

Parameters

array $keys
array|null $weights
array|null $options

Return Value

RedisCluster|array|false

RedisCluster|array|false zdiff(array $keys, array|null $options = null)

No description

Parameters

array $keys
array|null $options

Return Value

RedisCluster|array|false