Back to Phpredis

Redis

docs/Redis.html

6.3.0276.7 KB
Original Source

Redis

class Redis (View source)

Constants

| REDIS_NOT_FOUND |

Returned by \Redis::type() when the key does not exist or has a type we are not familiar with.

| | REDIS_STRING |

Returned by \Redis::type() when the key is a string.

| | REDIS_SET |

Returned by \Redis::type() when the key is a set.

| | REDIS_LIST |

Returned by \Redis::type() when the key is a list.

| | REDIS_ZSET |

Returned by \Redis::type() when the key is a sorted set.

| | REDIS_HASH |

Returned by \Redis::type() when the key is a hash.

| | REDIS_STREAM |

Returned by \Redis::type() when the key is a stream.

| | REDIS_VECTORSET |

Returned by \Redis::type() when the key is a vector set.

| | ATOMIC |

Returned from \Redis::getMode() when we're not in a multi or pipeline transaction.

| | MULTI |

Returned from \Redis::getMode() when we're in a multi transaction.

| | PIPELINE |

Returned from \Redis::getMode() when we're in a pipeline transaction.

| | OPT_SERIALIZER |

Used with \Redis::setOption() to specify the serializer to use

| | OPT_PREFIX |

Used to set an automatic prefix for keys used in commands.

| | OPT_READ_TIMEOUT |

Used to set the read timeout for the connection.

| | OPT_TCP_KEEPALIVE |

Used to enable or disable TCP keepalive on the connection.

| | OPT_COMPRESSION |

Used to set the compression algorithm to use for compressing

| | OPT_REPLY_LITERAL |

Causes PhpRedis to return the actual string in +OK style responses from Redis. If disabled those replies are just converted to boolean true.

| | OPT_COMPRESSION_LEVEL |

Used to specify the compression level to use when compressing data.

| | OPT_NULL_MULTIBULK_AS_NULL |

Tells PhpRedis to return a NULL multi-bulk (*-1\r\n) response as null as opposed to an empty array.

| | OPT_PACK_IGNORE_NUMBERS |

When enabled, this option tells PhpRedis to ignore purely numeric values when packing and unpacking data. This does not include numeric strings.

If you want numeric strings to be ignored, typecast them to an int or float.

The primary purpose of this option is to make it more ergonomic when setting keys that will later be incremented or decremented.

Note: This option incurs a small performance penalty when reading data because we have to see if the data is a string representation of an int or float.

| | SERIALIZER_NONE |

Sets the serializer to none (no serialization).

| | SERIALIZER_PHP |

Sets the serializer to PHP's built-in serialize()/unserialize()

| | SERIALIZER_IGBINARY |

Sets the serializer to igbinary. Note that phpredis must be compiled with ighbinary support to use this serializer.

| | SERIALIZER_MSGPACK |

Sets the serializer to msgpack. Note that phpredis must be compiled with msgpack support to use this serializer.

| | SERIALIZER_JSON |

Sets the serializer to JSON.

| | COMPRESSION_NONE |

Disables compression.

| | COMPRESSION_LZF |

Sets the compression algorithm to LZF. PhpRedis must be compiled with lzf support but this serializer is bundled with the extension.

| | COMPRESSION_ZSTD |

Sets the compression algorithm to ZSTD. PhpRedis must be compiled with zstd support to use this serializer. This is often the best balance between speed and compression ratio.

| | COMPRESSION_ZSTD_DEFAULT |

This constant represents the "default" compression level for ZSTD. If PhpRedis is compiled against a new enough ZSTD the value comes from the library, otherwise we just set it to 3.

| | COMPRESSION_ZSTD_MIN |

The minimum compression level ZSTD supports, which comes from the underlying ZSTD library if new enough. Otherwise we just set it to 1.

| | COMPRESSION_ZSTD_MAX |

The maximum compression level ZSTD supports, which comes from the underlying ZSTD library.

| | COMPRESSION_LZ4 |

Set the compression algorithm to LZ4. PhpRedis must be compiled with lz4 support to use this serializer. This algorithm is generally the fastest but has a lower compression ratio than ZSTD.

| | OPT_SCAN |

Used with \Redis::setOption() to specify scan options.

| | SCAN_RETRY |

When enabled, this option causes PhpRedis to automatically retry SCAN commands when Redis returns a non-zero cursor but no keys. This can happen due to the nature of Redis' scanning algorithm.

| | SCAN_NORETRY |

Then enabled, this option tells PhpRedis to not retry SCAN commands when Redis returns a non-zero cursor but no keys. This means that your code must handle this case itself.

| | SCAN_PREFIX |

Tells PhpRedis to prefix keys returned from SCAN commands with the currently set key prefix.

| | SCAN_NOPREFIX |

Tells PhpRedis to NOT prefix keys returned from SCAN commands with the currently set key prefix.

| | BEFORE |

This is just the string "before" which is used with various list commands to indicate an insertion point.

| | AFTER |

This is just the string "after" which is used with various list commands to indicate an insertion point.

| | LEFT |

This is just the string "left" which is used with various list commands such as LMOVE.

| | RIGHT |

This is just the string "right" which is used with various list commands such as LMOVE.

| | OPT_MAX_RETRIES |

How many times should PhpRedis attempt to reconnect when we are disconnected.

| | OPT_BACKOFF_ALGORITHM |

Used to specify the backoff algorithm to use when reconnecting.

| | BACKOFF_ALGORITHM_DEFAULT |

Default backoff - random delay before the first retry, then constant base ms.

| | BACKOFF_ALGORITHM_CONSTANT |

Constant backoff - always sleep for exactly base ms (capped by cap).

| | BACKOFF_ALGORITHM_UNIFORM |

Uniform backoff - randomly sleep between 0 and base ms for each retry.

| | BACKOFF_ALGORITHM_EXPONENTIAL |

Exponential backoff - doubles the delay every retry (up to 2^10) before cap.

| | BACKOFF_ALGORITHM_FULL_JITTER |

Full jitter - exponential delay but pick a random value between 0 and that delay.

| | BACKOFF_ALGORITHM_EQUAL_JITTER |

Equal jitter - half the exponential delay plus a random amount up to the other half.

| | BACKOFF_ALGORITHM_DECORRELATED_JITTER |

Decorrelated jitter - pick a random delay between base and 3x the previous delay.

| | OPT_BACKOFF_BASE |

Backoff base - minimum delay in milliseconds that algorithms start from.

| | OPT_BACKOFF_CAP |

Backoff cap - maximum delay in milliseconds that any algorithm can reach.

|

Methods

Redis

__construct(array|null $options = null)

Create a new Redis instance. If passed sufficient information in the options array it is also possible to connect to an instance at the same time.

__destruct()

Destructor to clean up the Redis object.

string

_compress(string $value)

Compress a value with the currently configured compressor (Redis::OPT_COMPRESSION) exactly the same way PhpRedis does before sending data to Redis.

string

_uncompress(string $value)

Uncompress the provided argument using the compressor configured via Redis::setOption() (Redis::OPT_COMPRESSION).

string

_prefix(string $key)

Prefix the passed argument with the currently set key prefix as set with Redis::setOption().

string

_serialize(mixed $value)

Serialize the provided value with the currently set serializer as set with Redis::setOption().

mixed

_unserialize(string $value)

Unserialize the passed argument with the currently set serializer as set with Redis::setOption().

string

_pack(mixed $value)

Pack the provided value by first serializing it (if Redis::OPT_SERIALIZER is set) and then compressing the serialized payload (if Redis::OPT_COMPRESSION is set), mirroring exactly what PhpRedis transmits to Redis.

string

_digest(mixed $value)

Compute the XXH3 digest of a PHP value after it has been _packed, producing the same digest Redis' DIGEST command would return for the stored value.

mixed

_unpack(string $value)

Unpack the provided value by first uncompressing it (if Redis::OPT_COMPRESSION is set) and then unserializing it (if Redis::OPT_SERIALIZER is set) to recover the original PHP value.

mixed

acl(string $subcmd, string ...$args)

Execute Redis ACL subcommands.

Redis|int|false

append(string $key, mixed $value)

Append data to a Redis STRING key.

Redis|bool

auth(mixed $credentials)

Authenticate a Redis connection after its been established.

Redis|bool

bgSave()

Execute a save of the Redis database in the background.

Redis|bool

bgrewriteaof()

Asynchronously rewrite Redis' append-only file

Redis|array|false

waitaof(int $numlocal, int $numreplicas, int $timeout)

No description

Redis|int|false

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

Count the number of set bits in a Redis string.

Redis|int|false

bitop(string $operation, string $deskey, string $srckey, string ...$other_keys)

No description

Redis|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 0 or 1 in a string.

Redis|array|null|false

blPop(string|array $key_or_keys, string|float|int $timeout_or_key, mixed ...$extra_args)

Pop an element off the beginning of a Redis list or lists, potentially blocking up to a specified timeout. This method may be called in two distinct ways, of which examples are provided below.

Redis|array|null|false

brPop(string|array $key_or_keys, string|float|int $timeout_or_key, mixed ...$extra_args)

Pop an element off of the end of a Redis list or lists, potentially blocking up to a specified timeout.

Redis|string|false

brpoplpush(string $src, string $dst, int|float $timeout)

Pop an element from the end of a Redis list, pushing it to the beginning of another Redis list, optionally blocking up to a specified timeout.

Redis|array|false

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

POP the maximum scoring element off of one or more sorted sets, blocking up to a specified timeout if no elements are available.

Redis|array|false

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

POP the minimum scoring element off of one or more sorted sets, blocking up to a specified timeout if no elements are available

Redis|array|null|false

bzmpop(float $timeout, array $keys, string $from, int $count = 1)

POP one or more elements from one or more sorted sets, blocking up to a specified amount of time when no elements are available.

Redis|array|null|false

zmpop(array $keys, string $from, int $count = 1)

POP one or more of the highest or lowest scoring elements from one or more sorted sets.

Redis|array|null|false

blmpop(float $timeout, array $keys, string $from, int $count = 1)

Pop one or more elements from one or more Redis LISTs, blocking up to a specified timeout when no elements are available.

Redis|array|null|false

lmpop(array $keys, string $from, int $count = 1)

Pop one or more elements off of one or more Redis LISTs.

bool

clearLastError()

Reset any last error on the connection to NULL

mixed

client(string $opt, mixed ...$args)

Execute Redis CLIENT subcommands.

bool

close()

Closes the connection to Redis

mixed

command(string|null $opt = null, mixed ...$args)

Execute Redis COMMAND subcommands.

mixed

config(string $operation, array|string|null $key_or_settings = null, string|null $value = null)

Execute the Redis CONFIG command in a variety of ways.

bool

connect(string $host, int $port = 6379, float $timeout = 0, string|null $persistent_id = null, int $retry_interval = 0, float $read_timeout = 0, array|null $context = null)

Connect to a Redis server

Redis|bool

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

Make a copy of a key.

Redis|int|false

dbSize()

Return the number of keys in the currently selected Redis database.

Redis|string

debug(string $key)

Execute the Redis DEBUG command. Note that this is disabled by default and can be very dangerous, even allowing you to crash the server. Use with caution

Redis|int|false

decr(string $key, int $by = 1)

Decrement a Redis integer by 1 or a provided value.

Redis|int|false

decrBy(string $key, int $value)

Decrement a redis integer by a value

Redis|int|false

del(array|string $key, string ...$other_keys)

Delete one or more keys from Redis.

Redis|int|false

delex(string $key, array|null $options = null)

Delete a key conditionally based on its value or hash digest

Redis|int|false

delifeq(string $key, mixed $value)

Delete a key if it's equal to the specified value. This command is specific to Valkey >= 9.0

Redis|int|false

delete(array|string $key, string ...$other_keys) deprecated

No description

Redis|bool

discard()

Discard a transaction currently in progress.

Redis|string|false

dump(string $key)

Dump Redis' internal binary representation of a key.

Redis|string|false

echo(string $str)

Have Redis repeat back an arbitrary string to the client.

mixed

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

Execute a LUA script on the redis server.

mixed

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

This is simply the read-only variant of eval, meaning the underlying script may not modify data in redis.

mixed

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

Execute a LUA script on the server but instead of sending the script, send the SHA1 hash of the script.

mixed

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

This is simply the read-only variant of evalsha, meaning the underlying script may not modify data in redis.

Redis|array|false

exec()

Execute either a MULTI or PIPELINE block and return the array of replies.

Redis|int|bool

exists(mixed $key, mixed ...$other_keys)

Test if one or more keys exist.

Redis|bool

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

Sets an expiration in seconds on the key in question. If connected to redis-server >= 7.0.0 you may send an additional "mode" argument which modifies how the command will execute.

Redis|bool

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

Set a key to expire at an exact unix timestamp.

Redis|bool

failover(array|null $to = null, bool $abort = false, int $timeout = 0)

No description

Redis|int|false

expiretime(string $key)

Get the expiration of a given key as a unix timestamp

Redis|int|false

pexpiretime(string $key)

Get the expiration timestamp of a given Redis key but in milliseconds.

mixed

fcall(string $fn, array $keys = [], array $args = [])

Invoke a function.

mixed

fcall_ro(string $fn, array $keys = [], array $args = [])

This is a read-only variant of the FCALL command that cannot execute commands that modify data.

Redis|bool

flushAll(bool|null $sync = null)

Deletes every key in all Redis databases

Redis|bool

flushDB(bool|null $sync = null)

Deletes all the keys of the currently selected database.

Redis|bool|string|array

function(string $operation, mixed ...$args)

Functions is an API for managing code to be executed on the server.

Redis|int|false

geoadd(string $key, float $lng, float $lat, string $member, mixed ...$other_triples_and_options)

Add one or more members to a geospacial sorted set

Redis|float|false

geodist(string $key, string $src, string $dst, string|null $unit = null)

Get the distance between two members of a geospacially encoded sorted set.

Redis|array|false

geohash(string $key, string $member, string ...$other_members)

Retrieve one or more GeoHash encoded strings for members of the set.

Redis|array|false

geopos(string $key, string $member, string ...$other_members)

Return the longitude and latitude for one or more members of a geospacially encoded sorted set.

mixed

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

Retrieve members of a geospacially sorted set that are within a certain radius of a location.

mixed

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

A readonly variant of GEORADIUS that may be executed on replicas.

mixed

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

Similar to GEORADIUS except it uses a member as the center of the query.

mixed

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

This is the read-only variant of GEORADIUSBYMEMBER that can be run on replicas.

array

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

Search a geospacial sorted set for members in various ways.

Redis|array|int|false

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

Search a geospacial sorted set for members within a given area or range, storing the results into a new set.

mixed

get(string $key)

Retrieve a string keys value.

Redis|array|false

getWithMeta(string $key)

Retrieve a value and metadata of key.

mixed

getAuth()

Get the authentication information on the connection, if any.

Redis|int|false

getBit(string $key, int $idx)

Get the bit at a given index in a string key.

Redis|string|bool

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

Get the value of a key and optionally set it's expiration.

int

getDBNum()

Get the database number PhpRedis thinks we're connected to.

Redis|string|bool

getDel(string $key)

Get a key from Redis and delete it in an atomic operation.

string

getHost()

Return the host or Unix socket we are connected to.

string|null

getLastError()

Get the last error returned to us from Redis, if any.

int

getMode()

Returns whether the connection is in ATOMIC, MULTI, or PIPELINE mode

mixed

getOption(int $option)

Retrieve the value of a configuration setting as set by Redis::setOption()

string|null

getPersistentID()

Get the persistent connection ID, if there is one.

int

getPort()

Get the port we are connected to. This number will be zero if we are connected to a unix socket.

string|false

serverName()

Get the server name as reported by the HELLO response.

string|false

serverVersion()

Get the server version as reported by the HELLO response.

Redis|string|false

getRange(string $key, int $start, int $end)

Retrieve a substring of a string by index.

Redis|string|array|int|false

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

Get the longest common subsequence between two string keys.

float

getReadTimeout()

Get the currently set read timeout on the connection.

Redis|string|false

getset(string $key, mixed $value)

Sets a key and returns any previously set value, if the key already existed.

float|false

getTimeout()

Retrieve any set connection timeout

array

getTransferredBytes()

Get the number of bytes sent and received on the socket.

void

clearTransferredBytes()

Reset the number of bytes sent and received on the socket.

Redis|int|false

hDel(string $key, string $field, string ...$other_fields)

Remove one or more fields from a hash.

Redis|bool

hExists(string $key, string $field)

Checks whether a field exists in a hash.

mixed

hGet(string $key, string $member)

No description

Redis|array|false

hGetAll(string $key)

Read every field and value from a hash.

mixed

hGetWithMeta(string $key, string $member)

Retrieve a value and metadata of hash field.

Redis|int|false

hIncrBy(string $key, string $field, int $value)

Increment a hash field's value by an integer

Redis|float|false

hIncrByFloat(string $key, string $field, float $value)

Increment a hash field by a floating point value

Redis|array|false

hKeys(string $key)

Retrieve all of the fields of a hash.

Redis|int|false

hLen(string $key)

Get the number of fields in a hash.

Redis|array|false

hMget(string $key, array $fields)

Get one or more fields from a hash.

Redis|array|false

hgetex(string $key, array $fields, string|array|null $expiry = null)

Get one or more fields of a hash while optionally setting expiration information

Redis|int|false

hsetex(string $key, array $fields, array|null $expiry = null)

Set one or more fields in a hash with optional expiration information.

Redis|array|false

hgetdel(string $key, array $fields)

Get one or more fields and delete them

Redis|bool

hMset(string $key, array $fieldvals)

Add or update one or more hash fields and values

Redis|string|array|false

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

Get one or more random field from a hash.

Redis|int|false

hSet(string $key, mixed ...$fields_and_vals)

Add or update one or more hash fields and values.

Redis|bool

hSetNx(string $key, string $field, mixed $value)

Set a hash field and value, but only if that field does not exist

Redis|int|false

hStrLen(string $key, string $field)

Get the string length of a hash field

Redis|array|false

hVals(string $key)

Get all of the values from a hash.

Redis|array|false

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

Set the expiration on one or more fields in a hash.

Redis|array|false

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

Set the expiration on one or more fields in a hash in milliseconds.

Redis|array|false

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

Set the expiration time on one or more fields of a hash.

Redis|array|false

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

Set the expiration time on one or more fields of a hash in milliseconds.

Redis|array|false

httl(string $key, array $fields)

Get the TTL of one or more fields in a hash

Redis|array|false

hpttl(string $key, array $fields)

Get the millisecond TTL of one or more fields in a hash

Redis|array|false

hexpiretime(string $key, array $fields)

Get the expiration time of one or more fields in a hash

Redis|array|false

hpexpiretime(string $key, array $fields)

Get the expiration time in milliseconds of one or more fields in a hash

Redis|array|false

hpersist(string $key, array $fields)

Persist one or more hash fields

Redis|array|bool

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

Iterate over the fields and values of a hash in an incremental fashion.

Redis|int|false

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

Set an expiration on a key member (KeyDB only).

Redis|int|false

expirememberat(string $key, string $field, int $timestamp)

Set an expiration on a key membert to a specific unix timestamp (KeyDB only).

Redis|int|false

incr(string $key, int $by = 1)

Increment a key's value, optionally by a specific amount.

Redis|int|false

incrBy(string $key, int $value)

Increment a key by a specific integer value

Redis|float|false

incrByFloat(string $key, float $value)

Increment a numeric key by a floating point value.

Redis|array|false

info(string ...$sections)

Retrieve information about the connected redis-server. If no arguments are passed to this function, redis will return every info field. Alternatively you may pass a specific section you want returned (e.g. 'server', or 'memory') to receive only information pertaining to that section.

bool

isConnected()

Check if we are currently connected to a Redis instance.

Redis|list<string>|false

keys(string $pattern)

No description

Redis|int|false

lInsert(string $key, string $pos, mixed $pivot, mixed $value)

No description

Redis|int|false

lLen(string $key)

Retrieve the length of a list.

Redis|string|false

lMove(string $src, string $dst, string $wherefrom, string $whereto)

Move an element from one list into another.

Redis|string|false

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

No description

Redis|bool|string|array

lPop(string $key, int $count = 0)

Pop one or more elements off a list.

Redis|null|bool|int|array

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

Retrieve the index of an element in a list.

Redis|int|false

lPush(string $key, mixed ...$elements)

Prepend one or more elements to a list.

Redis|int|false

rPush(string $key, mixed ...$elements)

Append one or more elements to a list.

Redis|int|false

lPushx(string $key, mixed $value)

Prepend an element to a list but only if the list exists

Redis|int|false

rPushx(string $key, mixed $value)

Append an element to a list but only if the list exists

Redis|bool

lSet(string $key, int $index, mixed $value)

Set a list element at an index to a specific value.

int

lastSave()

Retrieve the last time Redis' database was persisted to disk.

mixed

lindex(string $key, int $index)

Get the element of a list by its index.

Redis|array|false

lrange(string $key, int $start, int $end)

Retrieve elements from a list.

Redis|int|false

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

Remove one or more matching elements from a list.

Redis|bool

ltrim(string $key, int $start, int $end)

Trim a list to a subrange of elements.

Redis|array|false

mget(array $keys)

Get one or more string keys.

Redis|bool

migrate(string $host, int $port, string|array $key, int $dstdb, int $timeout, bool $copy = false, bool $replace = false, mixed $credentials = null)

Proxy for the Redis MIGRATE command.

Redis|bool

move(string $key, int $index)

Move a key to a different database on the same redis instance.

Redis|bool

mset(array $key_values)

Set one or more string keys.

Redis|int|false

msetex(array $key_vals, int|float|array|null $expiry = null)

Set one or more keys and values with optional expiry information.

Redis|bool

msetnx(array $key_values)

Set one or more string keys but only if none of the key exist.

bool|Redis

multi(int $value = Redis::MULTI)

Begin a transaction.

Redis|int|string|false

object(string $subcommand, string $key)

Get encoding and other information about a key.

bool

open(string $host, int $port = 6379, float $timeout = 0, string|null $persistent_id = null, int $retry_interval = 0, float $read_timeout = 0, array|null $context = null) deprecated

No description

bool

pconnect(string $host, int $port = 6379, float $timeout = 0, string|null $persistent_id = null, int $retry_interval = 0, float $read_timeout = 0, array|null $context = null)

Connects to a Redis server creating or reusing a persistent connection.

Redis|bool

persist(string $key)

Remove the expiration from a key.

bool

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

Sets an expiration in milliseconds on a given key. If connected to Redis >= 7.0.0 you can pass an optional mode argument that modifies how the command will execute.

Redis|bool

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

Set a key's expiration to a specific Unix Timestamp in milliseconds. If connected to Redis >= 7.0.0 you can pass an optional 'mode' argument.

Redis|int

pfadd(string $key, array $elements)

Add one or more elements to a Redis HyperLogLog key

Redis|int|false

pfcount(array|string $key_or_keys)

Retrieve the cardinality of a Redis HyperLogLog key.

Redis|bool

pfmerge(string $dst, array $srckeys)

Merge one or more source HyperLogLog sets into a destination set.

Redis|string|bool

ping(string|null $message = null)

PING the redis server with an optional string argument.

bool|Redis

pipeline()

Enter into pipeline mode.

bool

popen(string $host, int $port = 6379, float $timeout = 0, string|null $persistent_id = null, int $retry_interval = 0, float $read_timeout = 0, array|null $context = null) deprecated

No description

Redis|bool

psetex(string $key, int $expire, mixed $value)

Set a key with an expiration time in milliseconds

bool

psubscribe(array $patterns, callable $cb)

Subscribe to one or more glob-style patterns

Redis|int|false

pttl(string $key)

Get a keys time to live in milliseconds.

Redis|int|false

publish(string $channel, string $message)

Publish a message to a pubsub channel

mixed

pubsub(string $command, mixed $arg = null)

Interact with the Redis PubSub subsystem.

Redis|array|bool

punsubscribe(array $patterns)

Unsubscribe from one or more channels by pattern

Redis|array|string|bool

rPop(string $key, int $count = 0)

Pop one or more elements from the end of a list.

Redis|string|false

randomKey()

Return a random key from the current database

mixed

rawcommand(string $command, mixed ...$args)

Execute any arbitrary Redis command by name.

Redis|bool

rename(string $old_name, string $new_name)

Unconditionally rename a key from $old_name to $new_name

Redis|bool

renameNx(string $key_src, string $key_dst)

Renames $key_src to $key_dst but only if newkey does not exist.

Redis|bool

reset()

Reset the state of the connection.

Redis|bool

restore(string $key, int $ttl, string $value, array|null $options = null)

Restore a key by the binary payload generated by the DUMP command.

mixed

role()

Query whether the connected instance is a primary or replica

Redis|string|false

rpoplpush(string $srckey, string $dstkey)

Atomically pop an element off the end of a Redis LIST and push it to the beginning of another.

Redis|int|false

sAdd(string $key, mixed $value, mixed ...$other_values)

Add one or more values to a Redis SET key.

int

sAddArray(string $key, array $values)

Add one or more values to a Redis SET key. This is an alternative to Redis::sadd() but instead of being variadic, takes a single array of values.

Redis|array|false

sDiff(string $key, string ...$other_keys)

Given one or more Redis SETS, this command returns all of the members from the first set that are not in any subsequent set.

Redis|int|false

sDiffStore(string $dst, string $key, string ...$other_keys)

This method performs the same operation as SDIFF except it stores the resulting diff values in a specified destination key.

Redis|array|false

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

Given one or more Redis SET keys, this command will return all of the elements that are in every one.

Redis|int|false

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

Compute the intersection of one or more sets and return the cardinality of the result.

Redis|int|false

sInterStore(array|string $key, string ...$other_keys)

Perform the intersection of one or more Redis SETs, storing the result in a destination key, rather than returning them.

Redis|array|false

sMembers(string $key)

Retrieve every member from a set key.

Redis|array|false

sMisMember(string $key, string $member, string ...$other_members)

Check if one or more values are members of a set.

Redis|bool

sMove(string $src, string $dst, mixed $value)

Pop a member from one set and push it onto another. This command will create the destination set if it does not currently exist.

Redis|string|array|false

sPop(string $key, int $count = 0)

Remove one or more elements from a set.

mixed

sRandMember(string $key, int $count = 0)

Retrieve one or more random members of a set.

Redis|array|false

sUnion(string $key, string ...$other_keys)

Returns the union of one or more Redis SET keys.

Redis|int|false

sUnionStore(string $dst, string $key, string ...$other_keys)

Perform a union of one or more Redis SET keys and store the result in a new set

Redis|bool

save()

Persist the Redis database to disk. This command will block the server until the save is completed. For a nonblocking alternative, see Redis::bgsave().

array|false

scan(null|int|string $iterator, string|null $pattern = null, int $count = 0, string|null $type = null)

Incrementally scan the Redis keyspace, with optional pattern and type matching.

Redis|int|false

scard(string $key)

Retrieve the number of members in a Redis set.

mixed

script(string $command, mixed ...$args)

An administrative command used to interact with LUA scripts stored on the server.

Redis|bool

select(int $db)

Select a specific Redis database.

Redis|string|bool

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

Create or set a Redis STRING key to a value.

Redis|int|false

setBit(string $key, int $idx, bool $value)

Set a specific bit in a Redis string to zero or one

Redis|int|false

setRange(string $key, int $index, string $value)

Update or append to a Redis string at a specific starting index

bool

setOption(int $option, mixed $value)

Set a configurable option on the Redis object.

Redis|bool

setex(string $key, int $expire, mixed $value)

Set a Redis STRING key with a specific expiration in seconds.

Redis|bool

setnx(string $key, mixed $value)

Set a key to a value, but only if that key does not already exist.

Redis|bool

sismember(string $key, mixed $value)

Check whether a given value is the member of a Redis SET.

Redis|bool

slaveof(string|null $host = null, int $port = 6379) deprecated

Turn a redis instance into a replica of another or promote a replica to a primary.

Redis|bool

replicaof(string|null $host = null, int $port = 6379)

Used to turn a Redis instance into a replica of another, or to remove replica status promoting the instance to a primary.

Redis|int|false

touch(array|string $key_or_array, string ...$more_keys)

Update one or more keys last modified metadata.

mixed

slowlog(string $operation, int $length = 0)

Interact with Redis' slowlog functionality in various ways, depending on the value of 'operation'.

mixed

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

Sort the contents of a Redis key in various ways.

mixed

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

This is simply a read-only variant of the sort command

array

sortAsc(string $key, string|null $pattern = null, mixed $get = null, int $offset = -1, int $count = -1, string|null $store = null) deprecated

No description

array

sortAscAlpha(string $key, string|null $pattern = null, mixed $get = null, int $offset = -1, int $count = -1, string|null $store = null) deprecated

No description

array

sortDesc(string $key, string|null $pattern = null, mixed $get = null, int $offset = -1, int $count = -1, string|null $store = null) deprecated

No description

array

sortDescAlpha(string $key, string|null $pattern = null, mixed $get = null, int $offset = -1, int $count = -1, string|null $store = null) deprecated

No description

Redis|int|false

srem(string $key, mixed $value, mixed ...$other_values)

Remove one or more values from a Redis SET key.

array|false

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

Scan the members of a redis SET key.

bool

ssubscribe(array $channels, callable $cb)

Subscribes the client to the specified shard channels.

Redis|int|false

strlen(string $key)

Retrieve the length of a Redis STRING key.

bool

subscribe(array $channels, callable $cb)

Subscribe to one or more Redis pubsub channels.

Redis|array|bool

sunsubscribe(array $channels)

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

Redis|bool

swapdb(int $src, int $dst)

Atomically swap two Redis databases so that all of the keys in the source database will now be in the destination database and vice-versa.

Redis|array

time()

Retrieve the server time from the connected Redis instance.

Redis|int|false

ttl(string $key)

Get the amount of time a Redis key has before it will expire, in seconds.

Redis|int|false

type(string $key)

Get the type of a given Redis key.

Redis|int|false

unlink(array|string $key, string ...$other_keys)

Delete one or more keys from the Redis database. Unlike this operation, the actual deletion is asynchronous, meaning it is safe to delete large keys without fear of Redis blocking for a long period of time.

Redis|array|bool

unsubscribe(array $channels)

Unsubscribe from one or more subscribed channels.

Redis|bool

unwatch()

Remove any previously WATCH'ed keys in a transaction.

Redis|bool

watch(array|string $key, string ...$other_keys)

Watch one or more keys for conditional execution of a transaction.

int|false

wait(int $numreplicas, int $timeout)

Block the client up to the provided timeout until a certain number of replicas have confirmed receiving them.

int|false

xack(string $key, string $group, array $ids)

Acknowledge one or more messages that are pending (have been consumed using XREADGROUP but not yet acknowledged by XACK.)

Redis|string|false

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

Append a message to a stream.

Redis|bool|array

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

This command allows a consumer to claim pending messages that have been idle for a specified period of time.

Redis|array|bool

xclaim(string $key, string $group, string $consumer, int $min_idle, array $ids, array $options)

This method allows a consumer to take ownership of pending stream entries, by ID. Another command that does much the same thing but does not require passing specific IDs is Redis::xAutoClaim.

Redis|int|false

xdel(string $key, array $ids)

Remove one or more specific IDs from a stream.

Relay|array|false

xdelex(string $key, array $ids, string|null $mode = null)

Remove one or more IDs from a stream with extended options.

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)

XGROUP

mixed

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

Retrieve information about a stream key.

Redis|int|false

xlen(string $key)

Get the number of messages in a Redis STREAM key.

Redis|array|false

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

Interact with stream messages that have been consumed by a consumer group but not yet acknowledged with XACK.

Redis|array|bool

xrange(string $key, string $start, string $end, int $count = -1)

Get a range of entries from a STREAM key.

Redis|array|bool

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

Consume one or more unconsumed elements in one or more streams.

Redis|array|bool

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

Read one or more messages using a consumer group.

Redis|array|bool

xrevrange(string $key, string $end, string $start, int $count = -1)

Get a range of entries from a STREAM key in reverse chronological order.

Redis|int|false

vadd(string $key, array $values, mixed $element, array|null $options = null)

Add to a vector set

Redis|array|false

vsim(string $key, mixed $member, array|null $options = null)

Query similarity of a vector by element or scores

Redis|int|false

vcard(string $key)

Get the length of a vector set

Redis|int|false

vdim(string $key)

Get the dimensions of a vector set

Redis|array|false

vinfo(string $key)

Get various bits of information about a vector set

Redis|bool

vismember(string $key, mixed $member)

Check if an element is a member of a vectorset

Redis|array|false

vemb(string $key, mixed $member, bool $raw = false)

Get the embeddings for a specific member

Redis|array|string|false

vrandmember(string $key, int $count = 0)

Get one or more random members from a vector set

Redis|array|false

vrange(string $key, string $min, string $max, int $count = -1)

Retreive a lexographical range of elements from a vector set

Redis|int|false

vrem(string $key, mixed $member)

Remove an element from a vector set

Redis|int|false

vsetattr(string $key, mixed $member, array|string $attributes)

Set the attributes of a vector set element

Redis|array|string|false

vgetattr(string $key, mixed $member, bool $decode = true)

Get the attributes of a vector set element

Redis|array|false

vlinks(string $key, mixed $member, bool $withscores = false)

Get any adajcent values for a member of a vector set.

Redis|int|false

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

Truncate a STREAM key in various ways.

Redis|int|float|false

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

Add one or more elements and scores to a Redis sorted set.

Redis|int|false

zCard(string $key)

Return the number of elements in a sorted set.

Redis|int|false

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

Count the number of members in a sorted set with scores inside a provided range.

Redis|float|false

zIncrBy(string $key, float $value, mixed $member)

Create or increment the score of a member in a Redis sorted set

Redis|int|false

zLexCount(string $key, string $min, string $max)

Count the number of elements in a sorted set whose members fall within the provided lexographical range.

Redis|array|false

zMscore(string $key, mixed $member, mixed ...$other_members)

Retrieve the score of one or more members in a sorted set.

Redis|array|false

zPopMax(string $key, int|null $count = null)

Pop one or more of the highest scoring elements from a sorted set.

Redis|array|false

zPopMin(string $key, int|null $count = null)

Pop one or more of the lowest scoring elements from a sorted set.

Redis|array|false

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

Retrieve a range of elements of a sorted set between a start and end point.

Redis|array|false

zRangeByLex(string $key, string $min, string $max, int $offset = -1, int $count = -1)

Retrieve a range of elements from a sorted set by legographical range.

Redis|array|false

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

Retrieve a range of members from a sorted set by their score.

Redis|int|false

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

This command is similar to ZRANGE except that instead of returning the values directly it will store them in a destination key provided by the user

Redis|string|array

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

Retrieve one or more random members from a Redis sorted set.

Redis|int|false

zRank(string $key, mixed $member)

Get the rank of a member of a sorted set, by score.

Redis|int|false

zRem(mixed $key, mixed $member, mixed ...$other_members)

Remove one or more members from a Redis sorted set.

Redis|int|false

zRemRangeByLex(string $key, string $min, string $max)

Remove zero or more elements from a Redis sorted set by legographical range.

Redis|int|false

zRemRangeByRank(string $key, int $start, int $end)

Remove one or more members of a sorted set by their rank.

Redis|int|false

zRemRangeByScore(string $key, string $start, string $end)

Remove one or more members of a sorted set by their score.

Redis|array|false

zRevRange(string $key, int $start, int $end, mixed $scores = null)

List the members of a Redis sorted set in reverse order

Redis|array|false

zRevRangeByLex(string $key, string $max, string $min, int $offset = -1, int $count = -1)

List members of a Redis sorted set within a legographical range, in reverse order.

Redis|array|false

zRevRangeByScore(string $key, string $max, string $min, array|bool $options = [])

List elements from a Redis sorted set by score, highest to lowest

Redis|int|false

zRevRank(string $key, mixed $member)

Retrieve a member of a sorted set by reverse rank.

Redis|float|false

zScore(string $key, mixed $member)

Get the score of a member of a sorted set.

Redis|array|false

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

Given one or more sorted set key names, return every element that is in the first set but not any of the others.

Redis|int|false

zdiffstore(string $dst, array $keys)

Store the difference of one or more sorted sets in a destination sorted set.

Redis|array|false

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

Compute the intersection of one or more sorted sets and return the members

Redis|int|false

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

Similar to ZINTER but instead of returning the intersected values, this command returns the cardinality of the intersected set.

Redis|int|false

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

Compute the intersection of one or more sorted sets storing the result in a new sorted set.

Redis|array|false

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

Scan the members of a sorted set incrementally, using a cursor

Redis|array|false

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

Retrieve the union of one or more sorted sets

Redis|int|false

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

Perform a union on one or more Redis sets and store the result in a destination sorted set.

Redis|string|false

digest(string $key)

Ask the server for the XXH3 digest of a given key's value

Details

at line 611 Redis __construct(array|null $options = null)

Create a new Redis instance. If passed sufficient information in the options array it is also possible to connect to an instance at the same time.

NOTE : Below is an example options array with various setting

$options = [
   'host' => 'localhost',
   'port' => 6379,
   'readTimeout' => 2.5,
   'connectTimeout' => 2.5,
   'persistent' => true,

   // Valid formats: NULL, ['user', 'pass'], 'pass', or ['pass']
   'auth' => ['phpredis', 'phpredis'],

   // See PHP stream options for valid SSL configuration settings.
   'ssl' => ['verify_peer' => false],

   // How quickly to retry a connection after we time out or it closes.
   // Note that this setting is overridden by 'backoff' strategies.
   'retryInterval' => 100,

    // Which backoff algorithm to use. 'decorrelated jitter' is
    // likely the best one for most solution, but there are many
    // to choose from:
    // REDIS_BACKOFF_ALGORITHM_DEFAULT
    // REDIS_BACKOFF_ALGORITHM_CONSTANT
    // REDIS_BACKOFF_ALGORITHM_UNIFORM
    // REDIS_BACKOFF_ALGORITHM_EXPONENTIAL
    // REDIS_BACKOFF_ALGORITHM_FULL_JITTER
    // REDIS_BACKOFF_ALGORITHM_EQUAL_JITTER
    // REDIS_BACKOFF_ALGORITHM_DECORRELATED_JITTER
    // 'base', and 'cap' are in milliseconds and represent the first
    // delay redis will use when reconnecting, and the maximum delay
    // we will reach while retrying.
   'backoff' => [
       'algorithm' => Redis::BACKOFF_ALGORITHM_DECORRELATED_JITTER,
       'base' => 500,
       'cap' => 750,
   ]
];

Note: If you do wish to connect via the constructor, only 'host' is strictly required, which will cause PhpRedis to connect to that host on Redis' default port (6379).

Parameters

| array|null | $options | |

Return Value

| Redis | |

See also

| Redis::connect | | | https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/ | |

Examples

|

$redis = new Redis(['host' => '127.0.0.1', 'port' => 6380]);

|

at line 620 __destruct()

Destructor to clean up the Redis object.

This method will disconnect from Redis. If the connection is persistento it will be stashed for future reuse.

at line 635 string _compress(string $value)

Compress a value with the currently configured compressor (Redis::OPT_COMPRESSION) exactly the same way PhpRedis does before sending data to Redis.

Parameters

| string | $value |

The value to be compressed

|

Return Value

| string |

The compressed result (or the original value if compression is disabled)

|

See also

| Redis::setOption | |

Examples

|

$redis->_compress('payload');

|

at line 650 string _uncompress(string $value)

Uncompress the provided argument using the compressor configured via Redis::setOption() (Redis::OPT_COMPRESSION).

Parameters

| string | $value |

The compressed value to uncompress.

|

Return Value

| string |

The uncompressed result.

|

See also

| Redis::setOption | |

Examples

|

$redis->_uncompress($redis->_compress('payload'));

|

at line 663 string _prefix(string $key)

Prefix the passed argument with the currently set key prefix as set with Redis::setOption().

Parameters

| string | $key |

The key/string to prefix

|

Return Value

| string |

The prefixed string

|

Examples

|

$redis->_prefix('user:42');

|

at line 678 string _serialize(mixed $value)

Serialize the provided value with the currently set serializer as set with Redis::setOption().

Parameters

| mixed | $value |

The value to serialize

|

Return Value

| string |

The serialized result

|

See also

| Redis::setOption | |

Examples

|

$redis->_serialize(['answer' => 42]);

|

at line 693 mixed _unserialize(string $value)

Unserialize the passed argument with the currently set serializer as set with Redis::setOption().

Parameters

| string | $value |

The value to unserialize

|

Return Value

| mixed |

The unserialized result

|

See also

| Redis::setOption | |

Examples

|

$redis->_unserialize($redis->_serialize(['answer' => 42]));

|

at line 708 string _pack(mixed $value)

Pack the provided value by first serializing it (if Redis::OPT_SERIALIZER is set) and then compressing the serialized payload (if Redis::OPT_COMPRESSION is set), mirroring exactly what PhpRedis transmits to Redis.

Parameters

| mixed | $value |

The value to pack

|

Return Value

| string |

The packed result having been serialized and compressed.

|

Examples

|

$redis->_pack(['count' => 5]);

|

at line 727 string _digest(mixed $value)

Compute the XXH3 digest of a PHP value after it has been _packed, producing the same digest Redis' DIGEST command would return for the stored value.

Parameters

| mixed | $value |

The value to compute the digest for.

|

Return Value

| string |

The computed digest.

|

Exceptions

| RedisException | |

Examples

|

$redis->_digest(['token' => 'abc']);

|

at line 741 mixed _unpack(string $value)

Unpack the provided value by first uncompressing it (if Redis::OPT_COMPRESSION is set) and then unserializing it (if Redis::OPT_SERIALIZER is set) to recover the original PHP value.

Parameters

| string | $value |

The value which has been serialized and compressed.

|

Return Value

| mixed |

The uncompressed and deserialized value.

|

Examples

|

$redis->_unpack($redis->_pack(['count' => 5]));

|

at line 751 mixed acl(string $subcmd, string ...$args)

Execute Redis ACL subcommands.

Parameters

| string | $subcmd | | | string | ...$args | |

Return Value

| mixed | |

See also

| https://redis.io/docs/latest/commands/acl/ | |

Examples

|

$redis->acl('list');

|

at line 767 Redis|int|false append(string $key, mixed $value)

Append data to a Redis STRING key.

Parameters

| string | $key |

The key in question

| | mixed | $value |

The data to append to the key.

|

Return Value

| Redis|int|false |

The new string length of the key or false on failure.

|

See also

| https://redis.io/docs/latest/commands/append/ | |

Examples

|

$redis->set('foo', 'hello);
$redis->append('foo', 'world');

|

at line 785 Redis|bool auth(mixed $credentials)

Authenticate a Redis connection after its been established.

$redis->auth('password'); $redis->auth(['password']); $redis->auth(['username', 'password']);

Parameters

| mixed | $credentials |

A string password, or an array with one or two string elements.

|

Return Value

| Redis|bool |

Whether the AUTH was successful.

|

See also

| https://redis.io/docs/latest/commands/auth/ | |

Examples

|

$redis->auth('secret');

|

at line 798 Redis|bool bgSave()

Execute a save of the Redis database in the background.

Return Value

| Redis|bool |

Whether the command was successful.

|

See also

| https://redis.io/docs/latest/commands/bgsave/ | |

Examples

|

$redis->bgSave();

|

at line 811 Redis|bool bgrewriteaof()

Asynchronously rewrite Redis' append-only file

Return Value

| Redis|bool |

Whether the command was successful.

|

See also

| https://redis.io/docs/latest/commands/bgrewriteaof/ | |

Examples

|

$redis->bgrewriteaof();

|

at line 822 Redis|array|false waitaof(int $numlocal, int $numreplicas, int $timeout)

No description

Parameters

| int | $numlocal | | | int | $numreplicas | | | int | $timeout | |

Return Value

| Redis|array|false | |

See also

| https://redis.io/docs/latest/commands/waitaof/ | |

Examples

|

$redis->waitaof(1, 1, 5000);

|

at line 844 Redis|int|false bitcount(string $key, int $start = 0, int $end = -1, bool $bybit = false)

Count the number of set bits in a Redis string.

Parameters

| string | $key |

The key in question (must be a string key)

| | int | $start |

The index where Redis should start counting. If omitted it defaults to zero, which means the start of the string.

| | int | $end |

The index where Redis should stop counting. If omitted it defaults to -1, meaning the very end of the string.

| | bool | $bybit |

Whether or not Redis should treat $start and $end as bit positions, rather than bytes.

|

Return Value

| Redis|int|false |

The number of bits set in the requested range.

|

See also

| https://redis.io/docs/latest/commands/bitcount/ | |

Examples

|

$redis->bitcount('bitmap', 0, -1);

|

at line 846 Redis|int|false bitop(string $operation, string $deskey, string $srckey, string ...$other_keys)

No description

Parameters

| string | $operation | | | string | $deskey | | | string | $srckey | | | string | ...$other_keys | |

Return Value

| Redis|int|false | |

at line 866 Redis|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 0 or 1 in a string.

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

| Redis|int|false |

The position of the first set or unset bit.

|

See also

| https://redis.io/docs/latest/commands/bitpos/ | |

Examples

|

$redis->bitpos('bitmap', true, 0, -1);

|

at line 886 Redis|array|null|false blPop(string|array $key_or_keys, string|float|int $timeout_or_key, mixed ...$extra_args)

Pop an element off the beginning of a Redis list or lists, potentially blocking up to a specified timeout. This method may be called in two distinct ways, of which examples are provided below.

Parameters

| string|array | $key_or_keys |

This can either be a string key or an array of one or more keys.

| | string|float|int | $timeout_or_key |

If the previous argument was a string key, this can either be an additional key, or the timeout you wish to send to the command.

| | mixed | ...$extra_args | |

Return Value

| Redis|array|null|false |

Can return various things depending on command and data in Redis.

|

See also

| https://redis.io/docs/latest/commands/blpop/ | |

Examples

|

$redis->blPop('list1', 'list2', 'list3', 1.5);
$relay->blPop(['list1', 'list2', 'list3'], 1.5);

|

at line 899 Redis|array|null|false brPop(string|array $key_or_keys, string|float|int $timeout_or_key, mixed ...$extra_args)

Pop an element off of the end of a Redis list or lists, potentially blocking up to a specified timeout.

The calling convention is identical to Redis::blPop() so see that documentation for more details.

Parameters

| string|array | $key_or_keys | | | string|float|int | $timeout_or_key | | | mixed | ...$extra_args | |

Return Value

| Redis|array|null|false | |

See also

| https://redis.io/docs/latest/commands/brpop/ | | | Redis::blPop | |

Examples

|

$redis->brPop(['queue:critical', 'queue:default'], 5);

|

at line 916 Redis|string|false brpoplpush(string $src, string $dst, int|float $timeout)

Pop an element from the end of a Redis list, pushing it to the beginning of another Redis list, optionally blocking up to a specified timeout.

Parameters

| string | $src |

The source list

| | string | $dst |

The destination list

| | int|float | $timeout |

The number of seconds to wait. Note that you must be connected to Redis >= 6.0.0 to send a floating point timeout.

|

Return Value

| Redis|string|false | |

See also

| https://redis.io/docs/latest/commands/brpoplpush/ | |

Examples

|

$redis->brpoplpush('queue:pending', 'queue:processing', 5);

|

at line 942 Redis|array|false bzPopMax(string|array $key, string|int $timeout_or_key, mixed ...$extra_args)

POP the maximum scoring element off of one or more sorted sets, blocking up to a specified timeout if no elements are available.

Following are examples of the two main ways to call this method.

NOTE : We recommend calling this function with an array and a timeout as the other strategy may be deprecated in future versions of PhpRedis

Parameters

| string|array | $key |

Either a string key or an array of one or more keys.

| | string|int | $timeout_or_key |

If the previous argument was an array, this argument must be a timeout value. Otherwise it could also be another key.

| | mixed | ...$extra_args |

Can consist of additional keys, until the last argument which needs to be a timeout.

|

Return Value

| Redis|array|false |

The popped elements.

|

See also

| https://redis.io/docs/latest/commands/bzpopmax/ | |

Examples

|

$redis->bzPopMax('key1', 'key2', 'key3', 1.5);
$redis->bzPopMax(['key1', 'key2', 'key3'], 1.5);

|

at line 957 Redis|array|false bzPopMin(string|array $key, string|int $timeout_or_key, mixed ...$extra_args)

POP the minimum scoring element off of one or more sorted sets, blocking up to a specified timeout if no elements are available

This command is identical in semantics to bzPopMax so please see that method for more information.

Parameters

| string|array | $key | | | string|int | $timeout_or_key | | | mixed | ...$extra_args | |

Return Value

| Redis|array|false | |

See also

| https://redis.io/docs/latest/commands/bzpopmin/ | | | Redis::bzPopMax | |

Examples

|

$redis->bzPopMin(['scores:high', 'scores:low'], 1.5);

|

at line 982 Redis|array|null|false bzmpop(float $timeout, array $keys, string $from, int $count = 1)

POP one or more elements from one or more sorted sets, blocking up to a specified amount of time when no elements are available.

Parameters

| float | $timeout |

How long to block if there are no element available

| | array | $keys |

The sorted sets to pop from

| | string | $from |

The string 'MIN' or 'MAX' (case insensitive) telling Redis whether you wish to pop the lowest or highest scoring members from the set(s).

| | int | $count |

Pop up to how many elements.

|

Return Value

| Redis|array|null|false |

This function will return an array of popped elements, or false depending on whether any elements could be popped within the specified timeout.

NOTE: If Redis::OPT_NULL_MULTIBULK_AS_NULL is set to true via Redis::setOption(), this method will instead return NULL when Redis doesn't pop any elements.

|

See also

| https://redis.io/docs/latest/commands/bzmpop/ | |

Examples

|

$redis->bzmpop(1.5, ['scores:high', 'scores:low'], 'MIN', 2);

|

at line 1000 Redis|array|null|false zmpop(array $keys, string $from, int $count = 1)

POP one or more of the highest or lowest scoring elements from one or more sorted sets.

Parameters

| array | $keys |

One or more sorted sets

| | string | $from |

The string 'MIN' or 'MAX' (case insensitive) telling Redis whether you want to pop the lowest or highest scoring elements.

| | int | $count |

Pop up to how many elements at once.

|

Return Value

| Redis|array|null|false |

An array of popped elements or false if none could be popped.

|

See also

| https://redis.io/docs/latest/commands/zmpop/ | |

Examples

|

$redis->zmpop(['scores:high', 'scores:low'], 'MAX', 2);

|

at line 1021 Redis|array|null|false blmpop(float $timeout, array $keys, string $from, int $count = 1)

Pop one or more elements from one or more Redis LISTs, blocking up to a specified timeout when no elements are available.

Parameters

| float | $timeout |

The number of seconds Redis will block when no elements are available.

| | array | $keys |

One or more Redis LISTs to pop from.

| | string | $from |

The string 'LEFT' or 'RIGHT' (case insensitive), telling Redis whether to pop elements from the beginning or end of the LISTs.

| | int | $count |

Pop up to how many elements at once.

|

Return Value

| Redis|array|null|false |

One or more elements popped from the list(s) or false if all LISTs were empty.

|

See also

| https://redis.io/docs/latest/commands/blmpop/ | |

Examples

|

$redis->blmpop(1.5, ['queue:critical', 'queue:default'], 'LEFT', 2);

|

at line 1040 Redis|array|null|false lmpop(array $keys, string $from, int $count = 1)

Pop one or more elements off of one or more Redis LISTs.

Parameters

| array | $keys |

An array with one or more Redis LIST key names.

| | string | $from |

The string 'LEFT' or 'RIGHT' (case insensitive), telling Redis whether to pop\ elements from the beginning or end of the LISTs.

| | int | $count |

The maximum number of elements to pop at once.

|

Return Value

| Redis|array|null|false |

One or more elements popped from the LIST(s) or false if all the LISTs were empty.

|

See also

| https://redis.io/docs/latest/commands/lmpop/ | |

Examples

|

$redis->lmpop(['queue:critical', 'queue:default'], 'RIGHT', 2);

|

at line 1056 bool clearLastError()

Reset any last error on the connection to NULL

Return Value

| bool |

This should always return true or throw an exception if we're not connected.

|

See also

| Redis::getLastError | |

Examples

|

$redis = new Redis(['host' => 'localhost']);
$redis->set('string', 'this_is_a_string');
$redis->smembers('string');
var_dump($redis->getLastError());
$redis->clearLastError();
var_dump($redis->getLastError());

|

at line 1069 mixed client(string $opt, mixed ...$args)

Execute Redis CLIENT subcommands.

Parameters

| string | $opt |

The CLIENT subcommand to execute.

| | mixed | ...$args |

Additional arguments depending on the subcommand.

|

Return Value

| mixed | |

See also

| https://redis.io/docs/latest/commands/client/ | |

Examples

|

$redis->client('list');

|

at line 1091 bool close()

Closes the connection to Redis

This function will close the connection whether it is persistent or not.

Return Value

| bool |

Whether the connection was successfully closed.

|

Examples

|

$redis = new Redis;
$redis->pconnect('localhost', 6379);
$id1 = $redis->client('id');
$redis->close();

$redis = new Redis;
$redis->pconnect('localhost', 6379);
$id2 = $redis->client('id');

// Will print "id is different"
printf("ID is %s\n", $id1 == $id2 ? 'the same' : 'different');

|

at line 1101 mixed command(string|null $opt = null, mixed ...$args)

Execute Redis COMMAND subcommands.

Parameters

| string|null | $opt | | | mixed | ...$args | |

Return Value

| mixed | |

See also

| https://redis.io/docs/latest/commands/command/ | |

Examples

|

$redis->command('command');

|

at line 1120 mixed config(string $operation, array|string|null $key_or_settings = null, string|null $value = null)

Execute the Redis CONFIG command in a variety of ways.

What the command does in particular depends on the $operation qualifier. Operations that PhpRedis supports are: RESETSTAT, REWRITE, GET, and SET.

Parameters

| string | $operation |

The CONFIG operation to execute (e.g. GET, SET, REWRITE).

| | array|string|null | $key_or_settings |

One or more keys or values.

| | string|null | $value |

The value if this is a CONFIG SET operation.

|

Return Value

| mixed | |

See also

| https://redis.io/docs/latest/commands/config/ | |

Examples

|

$redis->config('GET', 'timeout');
$redis->config('GET', ['timeout', 'databases']);
$redis->config('SET', 'timeout', 30);
$redis->config('SET', ['timeout' => 30, 'loglevel' => 'warning']);

|

at line 1155 bool connect(string $host, int $port = 6379, float $timeout = 0, string|null $persistent_id = null, int $retry_interval = 0, float $read_timeout = 0, array|null $context = null)

Connect to a Redis server

Parameters

| string | $host |

The Redis server hostname or IP address.

| | int | $port |

The Redis server port. Defaults to 6379.

| | float | $timeout |

The connection timeout in seconds. Defaults to 0 (no timeout).

| | string|null | $persistent_id |

If set, a persistent connection will be made with this ID.

| | int | $retry_interval |

The number of milliseconds to wait between connection attempts.

| | float | $read_timeout |

The read timeout in seconds. Defaults to 0 (no timeout).

| | array|null | $context |

An optional stream context to use when connecting. See \Redis::__construct() for more details.

|

Return Value

| bool |

Whether the connection was successful.

|

Exceptions

| RedisException | |

Examples

|

$redis = new \Redis;
try {
    $redis->connect('localhost', 6379, 2.5, null, 100, 2.5);
    $foo = $redis->get('foo');
    printf("foo: %s\n", $foo);
} catch (Exception $ex) {
    fprintf(STDERR, "Error: {$ex->getMessage()}\n");
}

|

at line 1191 Redis|bool copy(string $src, string $dst, array|null $options = null)

Make a copy of a key.

$redis = new Redis(['host' => 'localhost']);

Parameters

| string | $src |

The key to copy

| | string | $dst |

The name of the new key created from the source key.

| | array|null | $options |

An array with modifiers on how COPY should operate.

$options = [
    'REPLACE' => true|false # Whether to replace an existing key.
    'DB' => int # Copy key to specific db.
];

|

Return Value

| Redis|bool |

True if the copy was completed and false if not.

|

See also

| https://redis.io/docs/latest/commands/copy/ | |

Examples

|

$redis->pipeline()
      ->select(1)
      ->del('newkey')
      ->select(0)
      ->del('newkey')
      ->mset(['source1' => 'value1', 'exists' => 'old_value'])
      ->exec();

var_dump($redis->copy('source1', 'newkey'));
var_dump($redis->copy('source1', 'newkey', ['db' => 1]));
var_dump($redis->copy('source1', 'exists'));
var_dump($redis->copy('source1', 'exists', ['REPLACE' => true]));

|

at line 1208 Redis|int|false dbSize()

Return the number of keys in the currently selected Redis database.

Return Value

| Redis|int|false |

The number of keys or false on failure.

|

See also

| https://redis.io/docs/latest/commands/dbsize/ | |

Examples

|

$redis = new Redis(['host' => 'localhost']);
$redis->flushdb();
$redis->set('foo', 'bar');
var_dump($redis->dbsize());
$redis->mset(['a' => 'a', 'b' => 'b', 'c' => 'c', 'd' => 'd']);
var_dump($redis->dbsize());

|

at line 1222 Redis|string debug(string $key)

Execute the Redis DEBUG command. Note that this is disabled by default and can be very dangerous, even allowing you to crash the server. Use with caution

Parameters

| string | $key |

The DEBUG subcommand to execute.

|

Return Value

| Redis|string |

The result of the DEBUG command.

|

at line 1241 Redis|int|false decr(string $key, int $by = 1)

Decrement a Redis integer by 1 or a provided value.

Parameters

| string | $key |

The key to decrement

| | int | $by |

How much to decrement the key. Note that if this value is not sent or is set to 1, PhpRedis will actually invoke the 'DECR' command. If it is any value other than 1 PhpRedis will actually send the DECRBY command.

|

Return Value

| Redis|int|false |

The new value of the key or false on failure.

|

See also

| https://redis.io/docs/latest/commands/decr/ | | | https://redis.io/docs/latest/commands/decrby/ | |

Examples

|

$redis->decr('counter');

| |

$redis->decr('counter', 2);

|

at line 1256 Redis|int|false decrBy(string $key, int $value)

Decrement a redis integer by a value

Parameters

| string | $key |

The integer key to decrement.

| | int | $value |

How much to decrement the key.

|

Return Value

| Redis|int|false |

The new value of the key or false on failure.

|

See also

| https://redis.io/docs/latest/commands/decrby/ | |

Examples

|

$redis->decrby('counter', 1);

| |

$redis->decrby('counter', 2);

|

at line 1276 Redis|int|false del(array|string $key, string ...$other_keys)

Delete one or more keys from Redis.

This method can be called in two distinct ways. The first is to pass a single array of keys to delete, and the second is to pass N arguments, all names of keys. See below for an example of both strategies.

Parameters

| array|string | $key |

Either an array with one or more key names or a string with the name of a key.

| | string | ...$other_keys |

One or more additional keys passed in a variadic fashion.

|

Return Value

| Redis|int|false |

The number of keys that were deleted

|

See also

| https://redis.io/docs/latest/commands/del/ | |

Examples

|

$redis->del('key:0', 'key:1');

| |

$redis->del(['key:2', 'key:3', 'key:4']);

|

at line 1292 Redis|int|false delex(string $key, array|null $options = null)

Delete a key conditionally based on its value or hash digest

Parameters

| string | $key |

The key to delete

| | array|null | $options |

An array with options to modify how DELX works.

|

Return Value

| Redis|int|false |

Returns 1 if the key was deleted, 0 if it was not.

|

See also

| https://redis.io/docs/latest/commands/delex/ | |

Examples

|

$redis->delex('session:42');

|

at line 1308 Redis|int|false delifeq(string $key, mixed $value)

Delete a key if it's equal to the specified value. This command is specific to Valkey >= 9.0

Parameters

| string | $key |

The key to delete

| | mixed | $value |

The value to compare against the key's value.

|

Return Value

| Redis|int|false |

Returns 1 if the key was deleted, 0 if it was not.

|

See also

| https://valkey.io/commands/delifeq/ | |

Examples

|

$redis->delifeq('session:42', 'token');

|

at line 1320 Redis|int|false delete(array|string $key, string ...$other_keys) deprecated

deprecated

| | |

No description

Parameters

| array|string | $key | | | string | ...$other_keys | |

Return Value

| Redis|int|false | |

See also

| https://redis.io/docs/latest/commands/del/ | |

Examples

|

$redis->delete('legacy:key');

|

at line 1335 Redis|bool discard()

Discard a transaction currently in progress.

Return Value

| Redis|bool |

True if we could discard the transaction.

|

See also

| https://redis.io/docs/latest/commands/discard/ | |

Examples

|

$redis->getMode();
$redis->set('foo', 'bar');
$redis->discard();
$redis->getMode();

|

at line 1351 Redis|string|false dump(string $key)

Dump Redis' internal binary representation of a key.

Parameters

| string | $key |

The key to dump.

|

Return Value

| Redis|string|false |

A binary string representing the key's value.

|

See also

| https://redis.io/docs/latest/commands/dump/ | |

Examples

|

$redis->zadd('zset', 0, 'zero', 1, 'one', 2, 'two');
$binary = $redis->dump('zset');
$redis->restore('new-zset', 0, $binary);

|

at line 1364 Redis|string|false echo(string $str)

Have Redis repeat back an arbitrary string to the client.

Parameters

| string | $str |

The string to echo

|

Return Value

| Redis|string|false |

The string sent to Redis or false on failure.

|

See also

| https://redis.io/docs/latest/commands/echo/ | |

Examples

|

$redis->echo('Hello, World');

|

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

Execute a LUA script on the redis server.

Parameters

| string | $script |

A string containing the LUA script

| | array | $args |

An array of arguments to pass to this script

| | int | $num_keys |

How many of the arguments are keys. This is needed as redis distinguishes between key name arguments and other data.

|

Return Value

| mixed |

LUA scripts may return arbitrary data so this method can return strings, arrays, nested arrays, etc.

|

See also

| https://redis.io/docs/latest/commands/eval/ | |

Examples

|

$redis->eval('return redis.call("set", KEYS[1], ARGV[1])', ['counter', 1], 1);

|

at line 1397 mixed eval_ro(string $script_sha, array $args = [], int $num_keys = 0)

This is simply the read-only variant of eval, meaning the underlying script may not modify data in redis.

Parameters

| string | $script_sha | | | array | $args | | | int | $num_keys | |

Return Value

| mixed | |

See also

| Redis::eval_ro | | | https://redis.io/docs/latest/commands/eval_ro/ | |

Examples

|

$redis->eval_ro('return redis.call("get", KEYS[1])', ['counter'], 1);

|

at line 1420 mixed evalsha(string $sha1, array $args = [], int $num_keys = 0)

Execute a LUA script on the server but instead of sending the script, send the SHA1 hash of the script.

Parameters

| string | $sha1 |

The SHA1 hash of the lua code. Note that the script must already exist on the server, either having been loaded with SCRIPT LOAD or having been executed directly with EVAL first.

| | array | $args |

Arguments to send to the script.

| | int | $num_keys |

The number of arguments that are keys

|

Return Value

| mixed |

Returns whatever the specific script does.

|

See also

| https://redis.io/docs/latest/commands/evalsha/ | | | Redis::eval | |

Examples

|

$sha = $redis->script('load', 'return redis.call("incr", KEYS[1])');
$redis->evalsha($sha, ['counter'], 1);

|

at line 1434 mixed evalsha_ro(string $sha1, array $args = [], int $num_keys = 0)

This is simply the read-only variant of evalsha, meaning the underlying script may not modify data in redis.

Parameters

| string | $sha1 | | | array | $args | | | int | $num_keys | |

Return Value

| mixed | |

See also

| Redis::evalsha | | | https://redis.io/docs/latest/commands/evalsha_ro/ | |

Examples

|

$sha = $redis->script('load', 'return redis.call("get", KEYS[1])');
$redis->evalsha_ro($sha, ['counter'], 1);

|

at line 1454 Redis|array|false exec()

Execute either a MULTI or PIPELINE block and return the array of replies.

Return Value

| Redis|array|false |

The array of pipeline'd or multi replies or false on failure.

|

See also

| https://redis.io/docs/latest/commands/exec/ | | | https://redis.io/docs/latest/commands/multi/ | | | Redis::pipeline | | | Redis::multi | |

Examples

|

$res = $redis->multi()
->set('foo', 'bar')
->get('foo')
->del('list')
->rpush('list', 'one', 'two', 'three')
->exec();

|

at line 1470 Redis|int|bool exists(mixed $key, mixed ...$other_keys)

Test if one or more keys exist.

Parameters

| mixed | $key |

Either an array of keys or a string key

| | mixed | ...$other_keys |

If the previous argument was a string, you may send any number of additional keys to test.

|

Return Value

| Redis|int|bool |

The number of keys that do exist and false on failure

|

See also

| https://redis.io/docs/latest/commands/exists/ | |

Examples

|

$redis->exists(['k1', 'k2', 'k3']);

| |

$redis->exists('k4', 'k5', 'notakey');

|

at line 1495 Redis|bool expire(string $key, int $timeout, string|null $mode = null)

Sets an expiration in seconds on the key in question. If connected to redis-server >= 7.0.0 you may send an additional "mode" argument which modifies how the command will execute.

Parameters

| string | $key |

The key to set an expiration on.

| | int | $timeout |

The number of seconds after which key will be automatically deleted.

| | string|null | $mode |

A two character modifier that changes how the command works.

NX - Set expiry only if key has no expiry
XX - Set expiry only if key has an expiry
LT - Set expiry only when new expiry is < current expiry
GT - Set expiry only when new expiry is > current expiry

|

Return Value

| Redis|bool |

True if an expiration was set and false otherwise.

|

See also

| https://redis.io/docs/latest/commands/expire/ | |

Examples

|

$redis->expire('session:42', 60);

|

at line 1525 Redis|bool expireAt(string $key, int $timestamp, string|null $mode = null)

Set a key to expire at an exact unix timestamp.

Parameters

| string | $key |

The key to set an expiration on.

| | int | $timestamp |

The unix timestamp to expire at.

| | string|null | $mode |

An option 'mode' that modifies how the command acts (see Redis::expire).

|

Return Value

| Redis|bool |

True if an expiration was set, false if not.

|

See also

| https://redis.io/docs/latest/commands/expireat/ | | | https://redis.io/docs/latest/commands/expire/ | | | Redis::expire | |

Examples

|

$redis->expireAt('session:42', time() + 300);

|

at line 1527 Redis|bool failover(array|null $to = null, bool $abort = false, int $timeout = 0)

No description

Parameters

| array|null | $to | | | bool | $abort | | | int | $timeout | |

Return Value

| Redis|bool | |

at line 1543 Redis|int|false expiretime(string $key)

Get the expiration of a given key as a unix timestamp

Parameters

| string | $key |

The key to check.

|

Return Value

| Redis|int|false |

The timestamp when the key expires, or -1 if the key has no expiry and -2 if the key doesn't exist.

|

See also

| https://redis.io/docs/latest/commands/expiretime/ | |

Examples

|

$redis->setEx('mykey', 60, 'myval');
$redis->expiretime('mykey');

|

at line 1560 Redis|int|false pexpiretime(string $key)

Get the expiration timestamp of a given Redis key but in milliseconds.

Parameters

| string | $key |

The key to check

|

Return Value

| Redis|int|false |

The expiration timestamp of this key (in milliseconds) or -1 if the key has no expiration, and -2 if it does not exist.

|

See also

| https://redis.io/docs/latest/commands/pexpiretime/ | | | Redis::expiretime | |

Examples

|

$redis->pexpiretime('session:42');

|

at line 1578 mixed fcall(string $fn, array $keys = [], array $args = [])

Invoke a function.

Parameters

| string | $fn |

The name of the function

| | array | $keys |

Optional list of keys

| | array | $args |

Optional list of args

|

Return Value

| mixed |

Function may return arbitrary data so this method can return strings, arrays, nested arrays, etc.

|

See also

| https://redis.io/docs/latest/commands/fcall/ | |

Examples

|

$redis->fcall('mylib.increment', ['counter'], [1]);

|

at line 1596 mixed fcall_ro(string $fn, array $keys = [], array $args = [])

This is a read-only variant of the FCALL command that cannot execute commands that modify data.

Parameters

| string | $fn |

The name of the function

| | array | $keys |

Optional list of keys

| | array | $args |

Optional list of args

|

Return Value

| mixed |

Function may return arbitrary data so this method can return strings, arrays, nested arrays, etc.

|

See also

| https://redis.io/docs/latest/commands/fcall_ro/ | |

Examples

|

$redis->fcall_ro('mylib.peek', ['counter']);

|

at line 1609 Redis|bool flushAll(bool|null $sync = null)

Deletes every key in all Redis databases

Parameters

| bool|null | $sync |

Whether to perform the task in a blocking or non-blocking way.

|

Return Value

| Redis|bool | |

See also

| https://redis.io/docs/latest/commands/flushall/ | |

Examples

|

$redis->flushAll(true);

|

at line 1622 Redis|bool flushDB(bool|null $sync = null)

Deletes all the keys of the currently selected database.

Parameters

| bool|null | $sync |

Whether to perform the task in a blocking or non-blocking way.

|

Return Value

| Redis|bool | |

See also

| https://redis.io/docs/latest/commands/flushdb/ | |

Examples

|

$redis->flushDB(true);

|

at line 1646 Redis|bool|string|array function(string $operation, mixed ...$args)

Functions is an API for managing code to be executed on the server.

Parameters

| string | $operation |

The subcommand you intend to execute. Valid options are as follows 'LOAD' - Create a new library with the given library name and code. 'DELETE' - Delete the given library. 'LIST' - Return general information on all the libraries 'STATS' - Return information about the current function running 'KILL' - Kill the current running function 'FLUSH' - Delete all the libraries 'DUMP' - Return a serialized payload representing the current libraries 'RESTORE' - Restore the libraries represented by the given payload

| | mixed | ...$args |

Additional arguments

|

Return Value

| Redis|bool|string|array |

Depends on subcommand.

|

See also

| https://redis.io/docs/latest/commands/function/ | |

Examples

|

$redis->function('LIST');

|

at line 1667 Redis|int|false geoadd(string $key, float $lng, float $lat, string $member, mixed ...$other_triples_and_options)

Add one or more members to a geospacial sorted set

Parameters

| string | $key |

The sorted set to add data to.

| | float | $lng |

The longitude of the first member

| | float | $lat |

The latitude of the first member.

| | string | $member | | | mixed | ...$other_triples_and_options |

You can continue to pass longitude, latitude, and member arguments to add as many members as you wish. Optionally, the final argument may be a string with options for the command Redis documentation for the options.

|

Return Value

| Redis|int|false |

The number of added elements is returned. If the 'CH' option is specified, the return value is the number of members changed.

|

See also

| https://redis.io/docs/latest/commands/geoadd/ | |

Examples

|

$redis->geoAdd('cities', -121.8374, 39.7284, 'Chico', -122.03218, 37.322, 'Cupertino');

| |

$redis->geoadd('cities', -121.837478, 39.728494, 'Chico', ['XX', 'CH']);

|

at line 1690 Redis|float|false geodist(string $key, string $src, string $dst, string|null $unit = null)

Get the distance between two members of a geospacially encoded sorted set.

Parameters

| string | $key |

The Sorted set to query.

| | string | $src |

The first member.

| | string | $dst |

The second member.

| | string|null | $unit |

Which unit to use when computing distance, defaulting to meters.

M - meters
KM - kilometers
FT - feet
MI - miles

|

Return Value

| Redis|float|false |

The calculated distance in whichever units were specified or false if one or both members did not exist.

|

See also

| https://redis.io/docs/latest/commands/geodist/ | |

Examples

|

$redis->geodist('cities', 'Chico', 'Cupertino', 'mi');

|

at line 1706 Redis|array|false geohash(string $key, string $member, string ...$other_members)

Retrieve one or more GeoHash encoded strings for members of the set.

Parameters

| string | $key |

The key to query

| | string | $member |

The first member to request

| | string | ...$other_members |

One or more additional members to request.

|

Return Value

| Redis|array|false |

An array of GeoHash encoded values.

|

See also

| https://redis.io/docs/latest/commands/geohash/ | | | https://en.wikipedia.org/wiki/Geohash | |

Examples

|

$redis->geohash('cities', 'Chico', 'Cupertino');

|

at line 1721 Redis|array|false geopos(string $key, string $member, string ...$other_members)

Return the longitude and latitude for one or more members of a geospacially encoded sorted set.

Parameters

| string | $key |

The set to query.

| | string | $member |

The first member to query.

| | string | ...$other_members |

One or more members to query.

|

Return Value

| Redis|array|false |

An array of longitude and latitude pairs.

|

See also

| https://redis.io/docs/latest/commands/geopos/ | |

Examples

|

$redis->geopos('cities', 'Seattle', 'New York');

|

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

Retrieve members of a geospacially sorted set that are within a certain radius of a location.

Parameters

| string | $key |

The set to query

| | float | $lng |

The longitude of the location to query.

| | float | $lat |

The latitude of the location to query.

| | float | $radius |

The radius of the area to include.

| | string | $unit |

The unit of the provided radius (defaults to 'meters). See Redis::geodist for possible units.

| | array | $options |

An array of options that modifies how the command behaves.

$options = [
    'WITHCOORD', # Return members and their coordinates.
    'WITHDIST', # Return members and their distances from the center.
    'WITHHASH', # Return members GeoHash string.
    'ASC' | 'DESC', # The sort order of returned members

    # Limit to N returned members. Optionally a two element array may be
    # passed as the `LIMIT` argument, and the `ANY` argument.
    'COUNT' => [<int>], or [<int>, <bool>]

    # Instead of returning members, store them in the specified key.
    'STORE' => <string>

    # Store the distances in the specified key
    'STOREDIST' => <string>
];

|

Return Value

| mixed |

This command can return various things, depending on the options passed.

|

See also

| https://redis.io/docs/latest/commands/georadius/ | |

Examples

|

$redis->georadius('cities', 47.608013, -122.335167, 1000, 'km');

|

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

A readonly variant of GEORADIUS that may be executed on replicas.

Parameters

| string | $key | | | float | $lng | | | float | $lat | | | float | $radius | | | string | $unit | | | array | $options | |

Return Value

| mixed | |

See also

| Redis::georadius | | | https://redis.io/docs/latest/commands/georadius_ro/ | |

Examples

|

$redis->georadius_ro('cities', -122.335167, 47.608013, 100, 'km');

|

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

Similar to GEORADIUS except it uses a member as the center of the query.

Parameters

| string | $key |

The key to query.

| | string | $member |

The member to treat as the center of the query.

| | float | $radius |

The radius from the member to include.

| | string | $unit |

The unit of the provided radius See Redis::geodist for possible units.

| | array | $options |

An array with various options to modify the command's behavior. See Redis::georadius for options.

|

Return Value

| mixed |

This command can return various things depending on options.

|

See also

| https://redis.io/docs/latest/commands/georadiusbymember/ | |

Examples

|

$redis->georadiusbymember('cities', 'Seattle', 200, 'mi');

|

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

This is the read-only variant of GEORADIUSBYMEMBER that can be run on replicas.

Parameters

| string | $key | | | string | $member | | | float | $radius | | | string | $unit | | | array | $options | |

Return Value

| mixed | |

See also

| https://redis.io/docs/latest/commands/georadiusbymember_ro/ | |

Examples

|

$redis->georadiusbymember_ro('cities', 'Seattle', 200, 'mi');

|

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

Search a geospacial sorted set for members in various ways.

Parameters

| string | $key |

The set to query.

| | array|string | $position |

Either a two element array with longitude and latitude, or a string representing a member of the set.

| | array|int|float | $shape |

Either a number representine the radius of a circle to search, or a two element array representing the width and height of a box to search.

| | string | $unit |

The unit of our shape. See Redis::geodist for possible units.

| | array | $options |

Redis::georadius for options. Note that the STORE options are not allowed for this command.

|

Return Value

| array | |

See also

| https://redis.io/docs/latest/commands/geosearch/ | |

Examples

|

$redis->geosearch('cities', 'Seattle', 50, 'km', ['WITHDIST']);

|

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

Search a geospacial sorted set for members within a given area or range, storing the results into a new set.

Parameters

| string | $dst |

The destination where results will be stored.

| | string | $src |

The key to query.

| | array|string | $position |

Either a two element array with longitude and latitude, or a string representing a member of the set.

| | array|int|float | $shape |

Either a number representine the radius of a circle to search, or a two element array representing the width and height of a box to search.

| | string | $unit |

The unit of our shape. See Redis::geodist for possible units.

| | array | $options |

$options = [
    'ASC' | 'DESC', # The sort order of returned members
    'WITHDIST' # Also store distances.

    # Limit to N returned members. Optionally a two element array may be
    # passed as the `LIMIT` argument, and the `ANY` argument.
    'COUNT' => [<int>], or [<int>, <bool>]
];

|

Return Value

| Redis|array|int|false | |

See also

| https://redis.io/docs/latest/commands/geosearchstore/ | |

Examples

|

$redis->geosearchstore('west:cities', 'cities', 'Seattle', 50, 'km', ['DESC']);

|

at line 1865 mixed get(string $key)

Retrieve a string keys value.

Parameters

| string | $key |

The key to query

|

Return Value

| mixed |

The keys value or false if it did not exist.

|

See also

| https://redis.io/docs/latest/commands/get/ | |

Examples

|

$redis->get('foo');

|

at line 1875 Redis|array|false getWithMeta(string $key)

Retrieve a value and metadata of key.

Parameters

| string | $key |

The key to query

|

Return Value

| Redis|array|false | |

Examples

|

$redis->getWithMeta('foo');

|

at line 1888 mixed getAuth()

Get the authentication information on the connection, if any.

Return Value

| mixed |

The authentication information used to authenticate the connection.

|

See also

| Redis::auth | |

Examples

|

$redis->getAuth();

|

at line 1900 Redis|int|false getBit(string $key, int $idx)

Get the bit at a given index in a string key.

Parameters

| string | $key |

The key to query.

| | int | $idx |

The Nth bit that we want to query.

|

Return Value

| Redis|int|false | |

See also

| https://redis.io/docs/latest/commands/getbit/ | |

Examples

|

$redis->getbit('bitmap', 1337);

|

at line 1923 Redis|string|bool getEx(string $key, array $options = [])

Get the value of a key and optionally set it's expiration.

Parameters

| string | $key |

The key to query

| | array | $options |

Options to modify how the command works.

$options = [
    'EX' => <seconds> # Expire in N seconds
    'PX' => <milliseconds> # Expire in N milliseconds
    'EXAT' => <timestamp> # Expire at a unix timestamp (in seconds)
    'PXAT' => <mstimestamp> # Expire at a unix timestamp (in milliseconds);
    'PERSIST' # Remove any configured expiration on the key.
];

|

Return Value

| Redis|string|bool |

The key's value or false if it didn't exist.

|

See also

| https://redis.io/docs/latest/commands/getex/ | |

Examples

|

$redis->getEx('mykey', ['EX' => 60]);

|

at line 1939 int getDBNum()

Get the database number PhpRedis thinks we're connected to.

This value is updated internally in PhpRedis each time Redis::select is called.

Return Value

| int |

The database we're connected to.

|

See also

| Redis::select | | | https://redis.io/docs/latest/commands/select/ | |

Examples

|

$redis->getDBNum();

|

at line 1951 Redis|string|bool getDel(string $key)

Get a key from Redis and delete it in an atomic operation.

Parameters

| string | $key |

The key to get/delete.

|

Return Value

| Redis|string|bool |

The value of the key or false if it didn't exist.

|

See also

| https://redis.io/docs/latest/commands/getdel/ | |

Examples

|

$redis->getdel('token:123');

|

at line 1962 string getHost()

Return the host or Unix socket we are connected to.

Return Value

| string |

The host or Unix socket.

|

Examples

|

$redis->getHost();

|

at line 1973 string|null getLastError()

Get the last error returned to us from Redis, if any.

Return Value

| string|null |

The error string or NULL if there is none.

|

Examples

|

$redis->getLastError();

|

at line 1984 int getMode()

Returns whether the connection is in ATOMIC, MULTI, or PIPELINE mode

Return Value

| int |

The mode we're in.

|

Examples

|

$redis->getMode();

|

at line 1997 mixed getOption(int $option)

Retrieve the value of a configuration setting as set by Redis::setOption()

Parameters

| int | $option | |

Return Value

| mixed |

The setting itself or false on failure

|

See also

| Redis::setOption | for a detailed list of options and their values. |

Examples

|

$redis->getOption(Redis::OPT_PREFIX);

|

at line 2008 string|null getPersistentID()

Get the persistent connection ID, if there is one.

Return Value

| string|null |

The ID or NULL if we don't have one.

|

Examples

|

$redis->getPersistentID();

|

at line 2019 int getPort()

Get the port we are connected to. This number will be zero if we are connected to a unix socket.

Return Value

| int |

The port.

|

Examples

|

$redis->getPort();

|

at line 2030 string|false serverName()

Get the server name as reported by the HELLO response.

Return Value

| string|false | |

Examples

|

$redis->serverName();

|

at line 2041 string|false serverVersion()

Get the server version as reported by the HELLO response.

Return Value

| string|false | |

Examples

|

$redis->serverVersion();

|

at line 2058 Redis|string|false getRange(string $key, int $start, int $end)

Retrieve a substring of a string by index.

Parameters

| string | $key |

The string to query.

| | int | $start |

The zero-based starting index.

| | int | $end |

The zero-based ending index.

|

Return Value

| Redis|string|false |

The substring or false on failure.

|

See also

| https://redis.io/docs/latest/commands/getrange/ | |

Examples

|

$redis->set('silly-word', 'Supercalifragilisticexpialidocious');
echo $redis->getRange('silly-word', 0, 4) . "\n";

|

at line 2091 Redis|string|array|int|false lcs(string $key1, string $key2, array|null $options = null)

Get the longest common subsequence between two string keys.

Parameters

| string | $key1 |

The first key to check

| | string | $key2 |

The second key to check

| | array|null | $options |

An optional array of modifiers for the command.

$options = [
    'MINMATCHLEN' => int # Exclude matching substrings that are less than this value

    'WITHMATCHLEN' => bool # Whether each match should also include its length.

    'LEN' # Return the length of the longest subsequence

    'IDX' # Each returned match will include the indexes where the
                           # match occurs in each string.
];

NOTE: 'LEN' cannot be used with 'IDX'.

|

Return Value

| Redis|string|array|int|false |

Various reply types depending on options.

|

See also

| https://redis.io/docs/latest/commands/lcs/ | |

Examples

|

$redis->set('seq1', 'gtaggcccgcacggtctttaatgtatccctgtttaccatgccatacctgagcgcatacgc');
$redis->set('seq2', 'aactcggcgcgagtaccaggccaaggtcgttccagagcaaagactcgtgccccgctgagc');
echo $redis->lcs('seq1', 'seq2') . "\n";

|

at line 2102 float getReadTimeout()

Get the currently set read timeout on the connection.

Return Value

| float |

The timeout.

|

Examples

|

$redis->getReadTimeout();

|

at line 2118 Redis|string|false getset(string $key, mixed $value)

Sets a key and returns any previously set value, if the key already existed.

Parameters

| string | $key |

The key to set.

| | mixed | $value |

The value to set the key to.

|

Return Value

| Redis|string|false |

The old value of the key or false if it didn't exist.

|

See also

| https://redis.io/docs/latest/commands/getset/ | |

Examples

|

$redis->getset('captain', 'Pike');
$redis->getset('captain', 'Kirk');

|

at line 2129 float|false getTimeout()

Retrieve any set connection timeout

Return Value

| float|false |

The currently set timeout or false on failure (e.g. we aren't connected).

|

Examples

|

$redis->getTimeout();

|

at line 2140 array getTransferredBytes()

Get the number of bytes sent and received on the socket.

Return Value

| array |

An array in the form [$sent_bytes, $received_bytes]

|

Examples

|

$redis->getTransferredBytes();

|

at line 2151 void clearTransferredBytes()

Reset the number of bytes sent and received on the socket.

Return Value

| void | |

Examples

|

$redis->clearTransferredBytes();

|

at line 2166 Redis|int|false hDel(string $key, string $field, string ...$other_fields)

Remove one or more fields from a hash.

Parameters

| string | $key |

The hash key in question.

| | string | $field |

The first field to remove

| | string | ...$other_fields |

One or more additional fields to remove.

|

Return Value

| Redis|int|false |

The number of fields actually removed.

|

See also

| https://redis.io/docs/latest/commands/hdel/ | |

Examples

|

$redis->hDel('communication', 'Alice', 'Bob');

|

at line 2180 Redis|bool hExists(string $key, string $field)

Checks whether a field exists in a hash.

Parameters

| string | $key |

The hash to query.

| | string | $field |

The field to check

|

Return Value

| Redis|bool |

True if it exists, false if not.

|

See also

| https://redis.io/docs/latest/commands/hexists/ | |

Examples

|

$redis->hExists('communication', 'Alice');

|

at line 2182 mixed hGet(string $key, string $member)

No description

Parameters

| string | $key | | | string | $member | |

Return Value

| mixed | |

at line 2195 Redis|array|false hGetAll(string $key)

Read every field and value from a hash.

Parameters

| string | $key |

The hash to query.

|

Return Value

| Redis|array|false |

All fields and values or false if the key didn't exist.

|

See also

| https://redis.io/docs/latest/commands/hgetall/ | |

Examples

|

$redis->hgetall('myhash');

|

at line 2206 mixed hGetWithMeta(string $key, string $member)

Retrieve a value and metadata of hash field.

Parameters

| string | $key |

The key to query

| | string | $member |

The key to query

|

Return Value

| mixed | |

Examples

|

$redis->hgetWithMeta('foo', 'field');

|

at line 2224 Redis|int|false hIncrBy(string $key, string $field, int $value)

Increment a hash field's value by an integer

Parameters

| string | $key |

The hash to modify

| | string | $field |

The field to increment

| | int | $value |

How much to increment the value.

|

Return Value

| Redis|int|false |

The new value of the field.

|

See also

| https://redis.io/docs/latest/commands/hincrby/ | |

Examples

|

$redis->hMSet('player:1', ['name' => 'Alice', 'score' => 0]);
$redis->hincrby('player:1', 'score', 10);

|

at line 2239 Redis|float|false hIncrByFloat(string $key, string $field, float $value)

Increment a hash field by a floating point value

Parameters

| string | $key |

The hash with the field to increment.

| | string | $field |

The field to increment.

| | float | $value | |

Return Value

| Redis|float|false |

The field value after incremented.

|

See also

| https://redis.io/docs/latest/commands/hincrbyfloat/ | |

Examples

|

$redis->hincrbyfloat('numbers', 'tau', 2 * 3.1415926);

|

at line 2252 Redis|array|false hKeys(string $key)

Retrieve all of the fields of a hash.

Parameters

| string | $key |

The hash to query.

|

Return Value

| Redis|array|false |

The fields in the hash or false if the hash doesn't exist.

|

See also

| https://redis.io/docs/latest/commands/hkeys/ | |

Examples

|

$redis->hkeys('myhash');

|

at line 2265 Redis|int|false hLen(string $key)

Get the number of fields in a hash.

Parameters

| string | $key |

The hash to check.

|

Return Value

| Redis|int|false |

The number of fields or false if the key didn't exist.

|

See also

| https://redis.io/docs/latest/commands/hlen/ | |

Examples

|

$redis->hlen('myhash');

|

at line 2279 Redis|array|false hMget(string $key, array $fields)

Get one or more fields from a hash.

Parameters

| string | $key |

The hash to query.

| | array | $fields |

One or more fields to query in the hash.

|

Return Value

| Redis|array|false |

The fields and values or false if the key didn't exist.

|

See also

| https://redis.io/docs/latest/commands/hmget/ | |

Examples

|

$redis->hMGet('player:1', ['name', 'score']);

|

at line 2297 Redis|array|false hgetex(string $key, array $fields, string|array|null $expiry = null)

Get one or more fields of a hash while optionally setting expiration information

Parameters

| string | $key |

The hash to query.

| | array | $fields |

One or more fields to query in the hash.

| | string|array|null | $expiry |

Info about the expiration

|

Return Value

| Redis|array|false |

The fields and values or false if the key didn't exist.

|

See also

| https://redis.io/docs/latest/commands/hgetex/ | |

Examples

|

$redis->hgetex('profiles', ['name', 'email'], ['EX' => 60]);

|

at line 2314 Redis|int|false hsetex(string $key, array $fields, array|null $expiry = null)

Set one or more fields in a hash with optional expiration information.

Parameters

| string | $key |

The hash to create/update.

| | array | $fields |

An array with fields values.

| | array|null | $expiry |

Info about the expiration

|

Return Value

| Redis|int|false |

One if fields were set zero if not.

|

See also

| https://redis.io/docs/latest/commands/hsetex/ | |

Examples

|

$redis->hsetex('profiles', ['token' => 'abc123'], ['EX' => 60]);

|

at line 2330 Redis|array|false hgetdel(string $key, array $fields)

Get one or more fields and delete them

Parameters

| string | $key |

The hash in question

| | array | $fields |

One or more fields

|

Return Value

| Redis|array|false |

The field and values or false on failure

|

See also

| https://redis.io/docs/latest/commands/hgetdel/ | |

Examples

|

$redis->hgetdel('profiles', ['token']);

|

at line 2344 Redis|bool hMset(string $key, array $fieldvals)

Add or update one or more hash fields and values

Parameters

| string | $key |

The hash to create/update

| | array | $fieldvals |

An associative array with fields and their values.

|

Return Value

| Redis|bool |

True if the operation was successful

|

See also

| https://redis.io/docs/latest/commands/hmset/ | |

Examples

|

$redis->hmset('updates', ['status' => 'starting', 'elapsed' => 0]);

|

at line 2366 Redis|string|array|false hRandField(string $key, array|null $options = null)

Get one or more random field from a hash.

Parameters

| string | $key |

The hash to query.

| | array|null | $options |

An array of options to modify how the command behaves.

$options = [
    'COUNT' => int # An optional number of fields to return.
    'WITHVALUES' => bool # Also return the field values.
];

|

Return Value

| Redis|string|array|false |

One or more random fields (and possibly values).

|

See also

| https://redis.io/docs/latest/commands/hrandfield/ | |

Examples

|

$redis->hrandfield('settings');

| |

$redis->hrandfield('settings', ['count' => 2, 'withvalues' => true]);

|

at line 2382 Redis|int|false hSet(string $key, mixed ...$fields_and_vals)

Add or update one or more hash fields and values.

Parameters

| string | $key |

The hash to create/update.

| | mixed | ...$fields_and_vals |

Argument pairs of fields and values. Alternatively, an associative array with the fields and their values.

|

Return Value

| Redis|int|false |

The number of fields that were added, or false on failure.

|

See also

| https://redis.io/docs/latest/commands/hset/ | |

Examples

|

$redis->hSet('player:1', 'name', 'Kim', 'score', 78);

| |

$redis->hSet('player:1', ['name' => 'Kim', 'score' => 78]);

|

at line 2398 Redis|bool hSetNx(string $key, string $field, mixed $value)

Set a hash field and value, but only if that field does not exist

Parameters

| string | $key |

The hash to update.

| | string | $field |

The value to set.

| | mixed | $value | |

Return Value

| Redis|bool |

True if the field was set and false if not.

|

See also

| https://redis.io/docs/latest/commands/hsetnx/ | |

Examples

|

$redis->hsetnx('player:1', 'lock', 'enabled');
$redis->hsetnx('player:1', 'lock', 'enabled');

|

at line 2416 Redis|int|false hStrLen(string $key, string $field)

Get the string length of a hash field

Parameters

| string | $key |

The hash to query.

| | string | $field |

The field to query.

|

Return Value

| Redis|int|false |

The string length of the field or false.

|

See also

| https://redis.io/docs/latest/commands/hstrlen/ | |

Examples

|

$redis = new Redis(['host' => 'localhost']);
$redis->del('hash');
$redis->hmset('hash', ['50bytes' => str_repeat('a', 50)]);
$redis->hstrlen('hash', '50bytes');

|

at line 2429 Redis|array|false hVals(string $key)

Get all of the values from a hash.

Parameters

| string | $key |

The hash to query.

|

Return Value

| Redis|array|false |

The values from the hash.

|

See also

| https://redis.io/docs/latest/commands/hvals/ | |

Examples

|

$redis->hvals('player:1');

|

at line 2447 Redis|array|false hexpire(string $key, int $ttl, array $fields, string|null $mode = NULL)

Set the expiration on one or more fields in a hash.

Parameters

| string | $key |

The hash to update.

| | int | $ttl |

The time to live in seconds.

| | array | $fields |

The fields to set the expiration on.

| | string|null | $mode |

An optional mode (NX, XX, ETC)

|

Return Value

| Redis|array|false | |

See also

| https://redis.io/docs/latest/commands/hexpire/ | |

Examples

|

$redis->hexpire('profiles', 300, ['token'], 'NX');

|

at line 2466 Redis|array|false hpexpire(string $key, int $ttl, array $fields, string|null $mode = NULL)

Set the expiration on one or more fields in a hash in milliseconds.

Parameters

| string | $key |

The hash to update.

| | int | $ttl |

The time to live in milliseconds.

| | array | $fields |

The fields to set the expiration on.

| | string|null | $mode |

An optional mode (NX, XX, ETC)

|

Return Value

| Redis|array|false | |

See also

| https://redis.io/docs/latest/commands/hexpire/ | |

Examples

|

$redis->hpexpire('profiles', 1500, ['token']);

|

at line 2485 Redis|array|false hexpireat(string $key, int $time, array $fields, string|null $mode = NULL)

Set the expiration time on one or more fields of a hash.

Parameters

| string | $key |

The hash to update.

| | int | $time |

The time to live in seconds.

| | array | $fields |

The fields to set the expiration on.

| | string|null | $mode |

An optional mode (NX, XX, ETC)

|

Return Value

| Redis|array|false | |

See also

| https://redis.io/docs/latest/commands/hexpire/ | |

Examples

|

$redis->hexpireat('profiles', time() + 600, ['token']);

|

at line 2504 Redis|array|false hpexpireat(string $key, int $mstime, array $fields, string|null $mode = NULL)

Set the expiration time on one or more fields of a hash in milliseconds.

Parameters

| string | $key |

The hash to update.

| | int | $mstime |

The time to live in milliseconds.

| | array | $fields |

The fields to set the expiration on.

| | string|null | $mode |

An optional mode (NX, XX, ETC)

|

Return Value

| Redis|array|false | |

See also

| https://redis.io/docs/latest/commands/hexpire/ | |

Examples

|

$redis->hpexpireat('profiles', (int) (microtime(true) * 1000) + 60000, ['token']);

|

at line 2521 Redis|array|false httl(string $key, array $fields)

Get the TTL of one or more fields in a hash

Parameters

| string | $key |

The hash to query.

| | array | $fields |

The fields to query.

|

Return Value

| Redis|array|false | |

See also

| https://redis.io/docs/latest/commands/httl/ | |

Examples

|

$redis->httl('profiles', ['token']);

|

at line 2537 Redis|array|false hpttl(string $key, array $fields)

Get the millisecond TTL of one or more fields in a hash

Parameters

| string | $key |

The hash to query.

| | array | $fields |

The fields to query.

|

Return Value

| Redis|array|false | |

See also

| https://redis.io/docs/latest/commands/hpttl/ | |

Examples

|

$redis->hpttl('profiles', ['token']);

|

at line 2553 Redis|array|false hexpiretime(string $key, array $fields)

Get the expiration time of one or more fields in a hash

Parameters

| string | $key |

The hash to query.

| | array | $fields |

The fields to query.

|

Return Value

| Redis|array|false | |

See also

| https://redis.io/docs/latest/commands/hexpiretime/ | |

Examples

|

$redis->hexpiretime('profiles', ['token']);

|

at line 2569 Redis|array|false hpexpiretime(string $key, array $fields)

Get the expiration time in milliseconds of one or more fields in a hash

Parameters

| string | $key |

The hash to query.

| | array | $fields |

The fields to query.

|

Return Value

| Redis|array|false | |

See also

| https://redis.io/docs/latest/commands/hpexpiretime/ | |

Examples

|

$redis->hpexpiretime('profiles', ['token']);

|

at line 2585 Redis|array|false hpersist(string $key, array $fields)

Persist one or more hash fields

Parameters

| string | $key |

The hash to query.

| | array | $fields |

The fields to query.

|

Return Value

| Redis|array|false | |

See also

| https://redis.io/docs/latest/commands/hpersist/ | |

Examples

|

$redis->hpersist('profiles', ['token']);

|

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

Iterate over the fields and values of a hash in an incremental fashion.

Parameters

| string | $key |

The hash to query.

| | null|int|string | $iterator |

The scan iterator, which should be initialized to NULL before the first call. This value will be updated after every call to hscan, until it reaches zero meaning the scan is complete.

| | string|null | $pattern |

An optional glob-style pattern to filter fields with.

| | int | $count |

An optional hint to Redis about how many fields and values to return per HSCAN.

|

Return Value

| Redis|array|bool |

An array with a subset of fields and values.

|

See also

| https://redis.io/docs/latest/commands/hscan/ | | | https://redis.io/docs/latest/commands/scan/ | |

Examples

|

$redis = new Redis(['host' => 'localhost']);

$redis->del('big-hash');

for ($i = 0; $i < 1000; $i++) {
    $fields["field:$i"] = "value:$i";
}

$redis->hmset('big-hash', $fields);

$it = null;

do {
    // Scan the hash but limit it to fields that match '*:1?3'
    $fields = $redis->hscan('big-hash', $it, '*:1?3');

    foreach ($fields as $field => $value) {
        echo "[$field] => $value\n";
    }
} while ($it != 0);

|

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

Set an expiration on a key member (KeyDB only).

Parameters

| string | $key |

The key to expire

| | string | $field |

The field to expire

| | int | $ttl | | | string|null | $unit |

The unit of the ttl (s, or ms).

|

Return Value

| Redis|int|false | |

See also

| https://docs.keydb.dev/docs/commands/#expiremember | | | https://redis.io/docs/latest/commands/expiremember/ | |

Examples

|

$redis->expiremember('profiles', 'token', 60);

|

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

Set an expiration on a key membert to a specific unix timestamp (KeyDB only).

Parameters

| string | $key |

The key to expire

| | string | $field |

The field to expire

| | int | $timestamp |

The unix timestamp to expire at.

|

Return Value

| Redis|int|false | |

See also

| https://docs.keydb.dev/docs/commands/#expirememberat | | | https://redis.io/docs/latest/commands/expirememberat/ | |

Examples

|

$redis->expirememberat('profiles', 'token', time() + 300);

|

at line 2672 Redis|int|false incr(string $key, int $by = 1)

Increment a key's value, optionally by a specific amount.

Parameters

| string | $key |

The key to increment

| | int | $by |

An optional amount to increment by.

|

Return Value

| Redis|int|false |

The new value of the key after incremented.

|

See also

| https://redis.io/docs/latest/commands/incr/ | | | https://redis.io/docs/latest/commands/incrby/ | |

Examples

|

$redis->incr('mycounter');

| |

$redis->incr('mycounter', 10);

|

at line 2689 Redis|int|false incrBy(string $key, int $value)

Increment a key by a specific integer value

Parameters

| string | $key |

The key to increment.

| | int | $value |

The amount to increment.

|

Return Value

| Redis|int|false | |

See also

| https://redis.io/docs/latest/commands/incrby/ | |

Examples

|

$redis->set('primes', 2);
$redis->incrby('primes', 1);
$redis->incrby('primes', 2);
$redis->incrby('primes', 2);
$redis->incrby('primes', 4);

|

at line 2705 Redis|float|false incrByFloat(string $key, float $value)

Increment a numeric key by a floating point value.

Parameters

| string | $key |

The key to increment

| | float | $value |

How much to increment (or decrement) the value.

|

Return Value

| Redis|float|false |

The new value of the key or false if the key didn't contain a string.

|

See also

| https://redis.io/docs/latest/commands/incrbyfloat/ | |

Examples

|

$redis->incrbyfloat('tau', 3.1415926);
$redis->incrbyfloat('tau', 3.1415926);

|

at line 2725 Redis|array|false info(string ...$sections)

Retrieve information about the connected redis-server. If no arguments are passed to this function, redis will return every info field. Alternatively you may pass a specific section you want returned (e.g. 'server', or 'memory') to receive only information pertaining to that section.

If connected to Redis server >= 7.0.0 you may pass multiple optional sections.

Parameters

| string | ...$sections |

Optional section(s) you wish Redis server to return.

|

Return Value

| Redis|array|false | |

See also

| https://redis.io/docs/latest/commands/info/ | |

Examples

|

$redis->info('server', 'stats');

|

at line 2736 bool isConnected()

Check if we are currently connected to a Redis instance.

Return Value

| bool |

True if we are, false if not

|

Examples

|

$redis->isConnected();

|

at line 2748 Redis|list&lt;string&gt;|false keys(string $pattern)

No description

Parameters

| string | $pattern | |

Return Value

| Redis|list<string>|false | |

See also

| https://redis.io/docs/latest/commands/keys/ | |

Examples

|

$redis->keys('session:*');

|

at line 2759 Redis|int|false lInsert(string $key, string $pos, mixed $pivot, mixed $value)

No description

Parameters

| string | $key | | | string | $pos | | | mixed | $pivot | | | mixed | $value | |

Return Value

| Redis|int|false | |

See also

| https://redis.io/docs/latest/commands/linsert/ | |

Examples

|

$redis->lInsert('letters', Redis::AFTER, 'b', 'beta');

|

at line 2774 Redis|int|false lLen(string $key)

Retrieve the length of a list.

Parameters

| string | $key |

The list

|

Return Value

| Redis|int|false |

The number of elements in the list or false on failure.

|

See also

| https://redis.io/docs/latest/commands/llen/ | |

Examples

|

$redis->lLen('queue');

|

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

Move an element from one list into another.

Parameters

| string | $src |

The source list.

| | string | $dst |

The destination list

| | string | $wherefrom |

Where in the source list to retrieve the element. This can be either

  • Redis::LEFT, or Redis::RIGHT.

| | string | $whereto |

Where in the destination list to put the element. This can be either

  • Redis::LEFT, or Redis::RIGHT.

|

Return Value

| Redis|string|false |

The element removed from the source list.

|

See also

| https://redis.io/docs/latest/commands/lmove/ | |

Examples

|

$redis->rPush('numbers', 'one', 'two', 'three');
$redis->lMove('numbers', 'odds', Redis::LEFT, Redis::LEFT);

|

at line 2816 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 | |

at line 2832 Redis|bool|string|array lPop(string $key, int $count = 0)

Pop one or more elements off a list.

Parameters

| string | $key |

The list to pop from.

| | int | $count |

Optional number of elements to remove. By default one element is popped.

|

Return Value

| Redis|bool|string|array |

Will return the element(s) popped from the list or false/NULL if none was removed.

|

See also

| https://redis.io/docs/latest/commands/lpop/ | |

Examples

|

$redis->lpop('mylist');

| |

$redis->lpop('mylist', 4);

|

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

Retrieve the index of an element in a list.

Parameters

| string | $key |

The list to query.

| | mixed | $value |

The value to search for.

| | array|null | $options |

Options to configure how the command operates

$options = [
    # How many matches to return. By default a single match is returned.
    # If count is set to zero, it means unlimited.
    'COUNT' => <num-matches>

    # Specify which match you want returned. `RANK` 1 means "the first match"
    # 2 means the second, and so on. If passed as a negative number the
    # RANK is computed right to left, so a `RANK` of -1 means "the last match".
    'RANK' => <rank>

    # This argument allows you to limit how many elements Redis will search before
    # returning. This is useful to prevent Redis searching very long lists while
    # blocking the client.
    'MAXLEN => <max-len>
];

|

Return Value

| Redis|null|bool|int|array |

Returns one or more of the matching indexes, or null/false if none were found.

|

See also

| https://redis.io/docs/latest/commands/lpos/ | |

Examples

|

$redis->lPos('queue', 'job-42');

|

at line 2880 Redis|int|false lPush(string $key, mixed ...$elements)

Prepend one or more elements to a list.

Parameters

| string | $key |

The list to prepend.

| | mixed | ...$elements |

One or more elements to prepend.

|

Return Value

| Redis|int|false |

The new length of the list after prepending.

|

See also

| https://redis.io/docs/latest/commands/lpush/ | |

Examples

|

$redis->lPush('mylist', 'cat', 'bear', 'aligator');

|

at line 2894 Redis|int|false rPush(string $key, mixed ...$elements)

Append one or more elements to a list.

Parameters

| string | $key |

The list to append to.

| | mixed | ...$elements |

one or more elements to append.

|

Return Value

| Redis|int|false |

The new length of the list

|

See also

| https://redis.io/docs/latest/commands/rpush/ | |

Examples

|

$redis->rPush('mylist', 'xray', 'yankee', 'zebra');

|

at line 2910 Redis|int|false lPushx(string $key, mixed $value)

Prepend an element to a list but only if the list exists

Parameters

| string | $key |

The key to prepend to.

| | mixed | $value |

The value to prepend.

|

Return Value

| Redis|int|false |

The new length of the list.

|

See also

| https://redis.io/docs/latest/commands/lpushx/ | |

Examples

|

$redis->lPushx('queue', 'job-42');

|

at line 2926 Redis|int|false rPushx(string $key, mixed $value)

Append an element to a list but only if the list exists

Parameters

| string | $key |

The key to prepend to.

| | mixed | $value |

The value to prepend.

|

Return Value

| Redis|int|false |

The new length of the list.

|

See also

| https://redis.io/docs/latest/commands/rpushx/ | |

Examples

|

$redis->rPushx('queue', 'job-99');

|

at line 2943 Redis|bool lSet(string $key, int $index, mixed $value)

Set a list element at an index to a specific value.

Parameters

| string | $key |

The list to modify.

| | int | $index |

The position of the element to change.

| | mixed | $value |

The new value.

|

Return Value

| Redis|bool |

True if the list was modified.

|

See also

| https://redis.io/docs/latest/commands/lset/ | |

Examples

|

$redis->lSet('queue', 0, 'job-42');

|

at line 2956 int lastSave()

Retrieve the last time Redis' database was persisted to disk.

Return Value

| int |

The unix timestamp of the last save time

|

See also

| https://redis.io/docs/latest/commands/lastsave/ | |

Examples

|

$redis->lastSave();

|

at line 2971 mixed lindex(string $key, int $index)

Get the element of a list by its index.

Parameters

| string | $key |

The key to query

| | int | $index |

The index to check.

|

Return Value

| mixed |

The index or NULL/false if the element was not found.

|

See also

| https://redis.io/docs/latest/commands/lindex/ | |

Examples

|

$redis->lindex('queue', 0);

|

at line 2989 Redis|array|false lrange(string $key, int $start, int $end)

Retrieve elements from a list.

Parameters

| string | $key |

The list to query.

| | int | $start |

The beginning index to retrieve. This number can be negative meaning start from the end of the list.

| | int | $end |

The end index to retrieve. This can also be negative to start from the end of the list.

|

Return Value

| Redis|array|false |

The range of elements between the indexes.

|

See also

| https://redis.io/docs/latest/commands/lrange/ | |

Examples

|

$redis->lrange('mylist', 0, -1); // the whole list

| |

$redis->lrange('mylist', -2, -1); // the last two elements in the list.

|

at line 3006 Redis|int|false lrem(string $key, mixed $value, int $count = 0)

Remove one or more matching elements from a list.

Parameters

| string | $key |

The list to truncate.

| | mixed | $value |

The value to remove.

| | int | $count |

How many elements matching the value to remove.

|

Return Value

| Redis|int|false |

The number of elements removed.

|

See also

| https://redis.io/docs/latest/commands/lrem/ | |

Examples

|

$redis->lrem('queue', 0, 'expired-job');

|

at line 3021 Redis|bool ltrim(string $key, int $start, int $end)

Trim a list to a subrange of elements.

Parameters

| string | $key |

The list to trim

| | int | $start |

The starting index to keep

| | int | $end |

The ending index to keep.

|

Return Value

| Redis|bool |

true if the list was trimmed.

|

See also

| https://redis.io/docs/latest/commands/ltrim/ | |

Examples

|

$redis->ltrim('mylist', 0, 3); // Keep the first four elements

|

at line 3033 Redis|array|false mget(array $keys)

Get one or more string keys.

Parameters

| array | $keys |

The keys to retrieve

|

Return Value

| Redis|array|false |

an array of keys with their values.

|

See also

| https://redis.io/docs/latest/commands/mget/ | |

Examples

|

$redis->mget(['key1', 'key2']);

|

at line 3061 Redis|bool migrate(string $host, int $port, string|array $key, int $dstdb, int $timeout, bool $copy = false, bool $replace = false, mixed $credentials = null)

Proxy for the Redis MIGRATE command.

Parameters

| string | $host |

The destination redis host.

| | int | $port |

The destination redis port.

| | string|array | $key |

The key or array of keys to migrate.

| | int | $dstdb |

The destination database index.

| | int | $timeout |

The timeout for the operation in milliseconds.

| | bool | $copy |

Whether to copy the key(s) or move them.

| | bool | $replace |

Whether to replace existing keys on the destination.

| | mixed | $credentials |

Optional credentials for authenticating to the destination server.

|

Return Value

| Redis|bool | |

See also

| https://redis.io/docs/latest/commands/migrate/ | |

Examples

|

$redis->connect('localhost', 6379);
$redis->set('foo', '6379_key');

// Move the key to localhost:9999 with a 5 second timeout
var_dump($redis->migrate('localhost', 9999, 'foo', 0, 5000));

|

at line 3077 Redis|bool move(string $key, int $index)

Move a key to a different database on the same redis instance.

Parameters

| string | $key |

The key to move

| | int | $index | |

Return Value

| Redis|bool |

True if the key was moved

|

See also

| https://redis.io/docs/latest/commands/move/ | |

Examples

|

$redis->move('cart:42', 1);

|

at line 3089 Redis|bool mset(array $key_values)

Set one or more string keys.

Parameters

| array | $key_values |

An array with keys and their values.

|

Return Value

| Redis|bool |

True if the keys could be set.

|

See also

| https://redis.io/docs/latest/commands/mset/ | |

Examples

|

$redis->mSet(['foo' => 'bar', 'baz' => 'bop']);

|

at line 3102 Redis|int|false msetex(array $key_vals, int|float|array|null $expiry = null)

Set one or more keys and values with optional expiry information.

Parameters

| array | $key_vals |

An array of keys with their values.

| | int|float|array|null | $expiry |

An optional array with expiry information.

|

Return Value

| Redis|int|false |

1 if all keys were set, 0 if none were.

|

See also

| https://redis.io/commands/msetex | |

Examples

|

$redis->msetex(['foo' => 'bar', 'baz' => 'bop'], ['EX' => 60]);

|

at line 3115 Redis|bool msetnx(array $key_values)

Set one or more string keys but only if none of the key exist.

Parameters

| array | $key_values |

An array of keys with their values.

|

Return Value

| Redis|bool |

True if the keys were set and false if not.

|

See also

| https://redis.io/docs/latest/commands/msetnx/ | |

Examples

|

$redis->msetnx(['foo' => 'bar', 'baz' => 'bop']);

|

at line 3133 bool|Redis multi(int $value = Redis::MULTI)

Begin a transaction.

Parameters

| int | $value |

The type of transaction to start. This can either be Redis::MULTI or `Redis::PIPELINE'.

|

Return Value

| bool|Redis |

True if the transaction could be started.

|

See also

| https://redis.io/docs/latest/commands/multi/ | |

Examples

|

$redis->multi();
$redis->set('foo', 'bar');
$redis->get('foo');
$redis->exec();

|

at line 3149 Redis|int|string|false object(string $subcommand, string $key)

Get encoding and other information about a key.

Parameters

| string | $subcommand |

The subcommand to execute. This can be either 'encoding', 'freq', or 'idle'.

| | string | $key |

The key to query.

|

Return Value

| Redis|int|string|false |

The requested information about the key.

|

Examples

|

$redis->del('list1');
$redis->rPush('list1', 'a', 'b', 'c');
echo $redis->object('encoding', 'list1');

|

at line 3159 bool open(string $host, int $port = 6379, float $timeout = 0, string|null $persistent_id = null, int $retry_interval = 0, float $read_timeout = 0, array|null $context = null) deprecated

deprecated

| | |

No description

Parameters

| string | $host | | | int | $port | | | float | $timeout | | | string|null | $persistent_id | | | int | $retry_interval | | | float | $read_timeout | | | array|null | $context | |

Return Value

| bool | |

Examples

|

$redis->open('127.0.0.1', 6379);

|

at line 3184 bool pconnect(string $host, int $port = 6379, float $timeout = 0, string|null $persistent_id = null, int $retry_interval = 0, float $read_timeout = 0, array|null $context = null)

Connects to a Redis server creating or reusing a persistent connection.

Parameters

| string | $host |

The Redis server hostname.

| | int | $port |

The Redis server port.

| | float | $timeout |

Connection timeout in seconds.

| | string|null | $persistent_id |

An optional persistent ID to use for the connection.

| | int | $retry_interval |

The number of microseconds to wait before retrying a connection.

| | float | $read_timeout |

Read timeout in seconds.

| | array|null | $context |

An optional stream context array.

|

Return Value

| bool |

True if the connection was successful.

|

Exceptions

| RedisException | |

Examples

|

try {
    $redis = new Redis();
    $redis->pconnect('localhost', 6379);
} catch (Exception $ex) {
   echo "Could not connect to Redis: ", $ex->getMessage(), "\n";
}

|

at line 3199 Redis|bool persist(string $key)

Remove the expiration from a key.

Parameters

| string | $key |

The key to operate against.

|

Return Value

| Redis|bool |

True if a timeout was removed and false if it was not or the key didn't exist.

|

See also

| https://redis.io/docs/latest/commands/persist/ | |

Examples

|

$redis->persist('session:42');

|

at line 3219 bool pexpire(string $key, int $timeout, string|null $mode = null)

Sets an expiration in milliseconds on a given key. If connected to Redis >= 7.0.0 you can pass an optional mode argument that modifies how the command will execute.

Parameters

| string | $key |

The key to set an expiration on.

| | int | $timeout |

The number of milliseconds after which key will be automatically deleted.

| | string|null | $mode |

A two character modifier that changes how the command works.

|

Return Value

| bool |

True if an expiry was set on the key, and false otherwise.

|

See also

| Redis::expire | for a description of the mode argument. | | https://redis.io/docs/latest/commands/pexpire/ | |

Examples

|

$redis->pexpire('session:42', 5000);

|

at line 3239 Redis|bool pexpireAt(string $key, int $timestamp, string|null $mode = null)

Set a key's expiration to a specific Unix Timestamp in milliseconds. If connected to Redis >= 7.0.0 you can pass an optional 'mode' argument.

Parameters

| string | $key | | | int | $timestamp | | | string|null | $mode | |

Return Value

| Redis|bool | |

See also

| Redis::expire | For a description of the mode argument. | | https://redis.io/docs/latest/commands/pexpireat/ | @param string $key The key to set an expiration on. @param int $timestamp The unix timestamp to expire at. @param string|null $mode A two character modifier that changes how the command works. @return Redis|bool True if an expiration was set on the key, false otherwise. |

Examples

|

$redis->pexpireAt('session:42', (int) (microtime(true) * 1000) + 60000);

|

at line 3256 Redis|int pfadd(string $key, array $elements)

Add one or more elements to a Redis HyperLogLog key

Parameters

| string | $key |

The key in question.

| | array | $elements |

One or more elements to add.

|

Return Value

| Redis|int |

Returns 1 if the set was altered, and zero if not.

|

See also

| https://redis.io/docs/latest/commands/pfadd/ | |

Examples

|

$redis->pfadd('visitors', ['alice', 'bob']);

|

at line 3271 Redis|int|false pfcount(array|string $key_or_keys)

Retrieve the cardinality of a Redis HyperLogLog key.

Parameters

| array|string | $key_or_keys |

Either one key or an array of keys

|

Return Value

| Redis|int|false |

The estimated cardinality of the set.

|

See also

| https://redis.io/docs/latest/commands/pfcount/ | |

Examples

|

$redis->pfcount(['visitors:today', 'visitors:yesterday']);

|

at line 3287 Redis|bool pfmerge(string $dst, array $srckeys)

Merge one or more source HyperLogLog sets into a destination set.

Parameters

| string | $dst |

The destination key.

| | array | $srckeys |

One or more source keys.

|

Return Value

| Redis|bool |

Always returns true.

|

See also

| https://redis.io/docs/latest/commands/pfmerge/ | |

Examples

|

$redis->pfmerge('visitors:all', ['visitors:today', 'visitors:yesterday']);

|

at line 3302 Redis|string|bool ping(string|null $message = null)

PING the redis server with an optional string argument.

Parameters

| string|null | $message |

An optional string message that Redis will reply with, if passed.

|

Return Value

| Redis|string|bool |

If passed no message, this command will simply return true. If a message is passed, it will return the message.

|

See also

| https://redis.io/docs/latest/commands/ping/ | |

Examples

|

$redis->ping();

| |

$redis->ping('beep boop');

|

at line 3322 bool|Redis pipeline()

Enter into pipeline mode.

Pipeline mode is the highest performance way to send many commands to Redis as they are aggregated into one stream of commands and then all sent at once when the user calls Redis::exec().

NOTE: That this is shorthand for Redis::multi(Redis::PIPELINE)

Return Value

| bool|Redis |

The redis object is returned, to facilitate method chaining.

|

Examples

|

$redis->pipeline()
->set('foo', 'bar')
->del('mylist')
->rpush('mylist', 'a', 'b', 'c')
->exec();

|

at line 3332 bool popen(string $host, int $port = 6379, float $timeout = 0, string|null $persistent_id = null, int $retry_interval = 0, float $read_timeout = 0, array|null $context = null) deprecated

deprecated

| | |

No description

Parameters

| string | $host | | | int | $port | | | float | $timeout | | | string|null | $persistent_id | | | int | $retry_interval | | | float | $read_timeout | | | array|null | $context | |

Return Value

| bool | |

Examples

|

$redis->popen('127.0.0.1', 6379, 0.0, 'cache');

|

at line 3347 Redis|bool psetex(string $key, int $expire, mixed $value)

Set a key with an expiration time in milliseconds

Parameters

| string | $key |

The key to set

| | int | $expire |

The TTL to set, in milliseconds.

| | mixed | $value |

The value to set the key to.

|

Return Value

| Redis|bool |

True if the key could be set.

|

See also

| https://redis.io/docs/latest/commands/psetex/ | |

Examples

|

$redis->psetex('mykey', 1000, 'myval');

|

at line 3369 bool psubscribe(array $patterns, callable $cb)

Subscribe to one or more glob-style patterns

Parameters

| array | $patterns |

One or more patterns to subscribe to.

| | callable | $cb |

A callback with the following prototype:

function ($redis, $channel, $message) { }

|

Return Value

| bool |

True if we were subscribed.

|

See also

| https://redis.io/docs/latest/commands/psubscribe/ | |

Examples

|

$redis->psubscribe(['user:*'], function (Redis $client, string $pattern, string $channel, string $message): void {
    printf('[%s] %s' . PHP_EOL, $channel, $message);
});

|

at line 3386 Redis|int|false pttl(string $key)

Get a keys time to live in milliseconds.

Parameters

| string | $key |

The key to check.

|

Return Value

| Redis|int|false |

The key's TTL or one of two special values if it has none.

-1 - The key has no TTL.
-2 - The key did not exist.

|

See also

| https://redis.io/docs/latest/commands/pttl/ | |

Examples

|

$redis->pttl('ttl-key');

|

at line 3402 Redis|int|false publish(string $channel, string $message)

Publish a message to a pubsub channel

Parameters

| string | $channel |

The channel to publish to.

| | string | $message |

The message itself.

|

Return Value

| Redis|int|false |

The number of subscribed clients to the given channel.

|

See also

| https://redis.io/docs/latest/commands/publish/ | |

Examples

|

$redis->publish('updates', 'build complete');

|

at line 3416 mixed pubsub(string $command, mixed $arg = null)

Interact with the Redis PubSub subsystem.

Parameters

| string | $command |

The PubSub command to execute. This can be one of:

| | mixed | $arg |

An optional argument to the command.

|

Return Value

| mixed |

Can return any number of things depending on the command executed.

|

See also

| https://redis.io/docs/latest/commands/pubsub/ | |

Examples

|

$redis->pubsub('channels');

|

at line 3433 Redis|array|bool punsubscribe(array $patterns)

Unsubscribe from one or more channels by pattern

Parameters

| array | $patterns |

One or more glob-style patterns of channel names.

|

Return Value

| Redis|array|bool |

The array of subscribed patterns or false on failure.

|

See also

| https://redis.io/docs/latest/commands/punsubscribe/ | | | https://redis.io/docs/latest/commands/subscribe/ | | | Redis::subscribe | |

Examples

|

$redis->punsubscribe(['user:*', 'room:*']);

|

at line 3449 Redis|array|string|bool rPop(string $key, int $count = 0)

Pop one or more elements from the end of a list.

Parameters

| string | $key |

A redis LIST key name.

| | int | $count |

The maximum number of elements to pop at once. NOTE: The count argument requires Redis >= 6.2.0

|

Return Value

| Redis|array|string|bool |

One or more popped elements or false if all were empty.

|

See also

| https://redis.io/docs/latest/commands/rpop/ | |

Examples

|

$redis->rPop('mylist');

| |

$redis->rPop('mylist', 4);

|

at line 3462 Redis|string|false randomKey()

Return a random key from the current database

Return Value

| Redis|string|false |

A random key name or false if no keys exist

|

See also

| https://redis.io/docs/latest/commands/randomkey/ | |

Examples

|

$redis->randomKey();

|

at line 3476 mixed rawcommand(string $command, mixed ...$args)

Execute any arbitrary Redis command by name.

Parameters

| string | $command |

The command to execute

| | mixed | ...$args |

One or more arguments to pass to the command.

|

Return Value

| mixed |

Can return any number of things depending on command executed.

|

Examples

|

$redis->rawCommand('del', 'mystring', 'mylist');

| |

$redis->rawCommand('set', 'mystring', 'myvalue');

| |

$redis->rawCommand('rpush', 'mylist', 'one', 'two', 'three');

|

at line 3492 Redis|bool rename(string $old_name, string $new_name)

Unconditionally rename a key from $old_name to $new_name

Parameters

| string | $old_name |

The original name of the key

| | string | $new_name |

The new name for the key

|

Return Value

| Redis|bool |

True if the key was renamed or false if not.

|

See also

| https://redis.io/docs/latest/commands/rename/ | |

Examples

|

$redis->rename('config:pending', 'config:active');

|

at line 3511 Redis|bool renameNx(string $key_src, string $key_dst)

Renames $key_src to $key_dst but only if newkey does not exist.

Parameters

| string | $key_src |

The source key name

| | string | $key_dst |

The destination key name.

|

Return Value

| Redis|bool |

True if the key was renamed, false if not.

|

See also

| https://redis.io/docs/latest/commands/renamenx/ | |

Examples

|

$redis->set('src', 'src_key');
$redis->set('existing-dst', 'i_exist');

$redis->renamenx('src', 'dst');
$redis->renamenx('dst', 'existing-dst');

|

at line 3524 Redis|bool reset()

Reset the state of the connection.

Return Value

| Redis|bool |

Should always return true unless there is an error.

|

See also

| https://redis.io/docs/latest/commands/reset/ | |

Examples

|

$redis->reset();

|

at line 3562 Redis|bool restore(string $key, int $ttl, string $value, array|null $options = null)

Restore a key by the binary payload generated by the DUMP command.

Parameters

| string | $key |

The name of the key you wish to create.

| | int | $ttl |

What Redis should set the key's TTL (in milliseconds) to once it is created. Zero means no TTL at all.

| | string | $value |

The serialized binary value of the string (generated by DUMP).

| | array|null | $options |

An array of additional options that modifies how the command operates.

$options = [
    'ABSTTL' # If this is present, the `$ttl` provided by the user should
                      # be an absolute timestamp, in milliseconds()

    'REPLACE' # This flag instructs Redis to store the key even if a key with
                      # that name already exists.

    'IDLETIME' => int # Tells Redis to set the keys internal 'idletime' value to a
                      # specific number (see the Redis command OBJECT for more info).
    'FREQ' => int # Tells Redis to set the keys internal 'FREQ' value to a specific
                      # number (this relates to Redis' LFU eviction algorithm).
];

|

Return Value

| Redis|bool |

True if the key was stored, false if not.

|

See also

| https://redis.io/docs/latest/commands/restore/ | | | https://redis.io/docs/latest/commands/dump/ | | | Redis::dump | |

Examples

|

$redis->sAdd('captains', 'Janeway', 'Picard', 'Sisko', 'Kirk', 'Archer');
$serialized = $redis->dump('captains');

$redis->restore('captains-backup', 0, $serialized);

|

at line 3576 mixed role()

Query whether the connected instance is a primary or replica

Return Value

| mixed |

Will return an array with the role of the connected instance unless there is an error.

|

See also

| https://redis.io/docs/latest/commands/role/ | |

Examples

|

$redis->role();

|

at line 3598 Redis|string|false rpoplpush(string $srckey, string $dstkey)

Atomically pop an element off the end of a Redis LIST and push it to the beginning of another.

Parameters

| string | $srckey |

The source key to pop from.

| | string | $dstkey |

The destination key to push to.

|

Return Value

| Redis|string|false |

The popped element or false if the source key was empty.

|

See also

| https://redis.io/docs/latest/commands/rpoplpush/ | |

Examples

|

$redis->pipeline()
      ->del('list1', 'list2')
      ->rpush('list1', 'list1-1', 'list1-2')
      ->rpush('list2', 'list2-1', 'list2-2')
      ->exec();

$redis->rpoplpush('list2', 'list1');

|

at line 3617 Redis|int|false sAdd(string $key, mixed $value, mixed ...$other_values)

Add one or more values to a Redis SET key.

Parameters

| string | $key |

The key name

| | mixed | $value |

A value to add to the set.

| | mixed | ...$other_values |

One or more additional values to add

|

Return Value

| Redis|int|false |

The number of values added to the set.

|

See also

| https://redis.io/docs/latest/commands/sadd/ | |

Examples

|

$redis->del('myset');

$redis->sadd('myset', 'foo', 'bar', 'baz');
$redis->sadd('myset', 'foo', 'new');

|

at line 3637 int sAddArray(string $key, array $values)

Add one or more values to a Redis SET key. This is an alternative to Redis::sadd() but instead of being variadic, takes a single array of values.

Parameters

| string | $key |

The set to add values to.

| | array | $values |

One or more members to add to the set.

|

Return Value

| int |

The number of members added to the set.

|

See also

| https://redis.io/docs/latest/commands/sadd/ | | | \Redis::sadd() | |

Examples

|

$redis->del('myset');

$redis->sAddArray('myset', ['foo', 'bar', 'baz']);
$redis->sAddArray('myset', ['foo', 'new']);

|

at line 3661 Redis|array|false sDiff(string $key, string ...$other_keys)

Given one or more Redis SETS, this command returns all of the members from the first set that are not in any subsequent set.

Parameters

| string | $key |

The first set

| | string | ...$other_keys |

One or more additional sets

|

Return Value

| Redis|array|false |

Returns the elements from keys 2..N that don't exist in the first sorted set, or false on failure.

|

See also

| https://redis.io/docs/latest/commands/sdiff/ | |

Examples

|

$redis->pipeline()
      ->del('set1', 'set2', 'set3')
      ->sadd('set1', 'apple', 'banana', 'carrot', 'date')
      ->sadd('set2', 'carrot')
      ->sadd('set3', 'apple', 'carrot', 'eggplant')
      ->exec();

$redis->sdiff('set1', 'set2', 'set3');

|

at line 3680 Redis|int|false sDiffStore(string $dst, string $key, string ...$other_keys)

This method performs the same operation as SDIFF except it stores the resulting diff values in a specified destination key.

Parameters

| string | $dst |

The key where to store the result

| | string | $key |

The first key to perform the DIFF on

| | string | ...$other_keys |

One or more additional keys.

|

Return Value

| Redis|int|false |

The number of values stored in the destination set or false on failure.

|

See also

| https://redis.io/docs/latest/commands/sdiffstore/ | | | \Redis::sdiff() | |

Examples

|

$redis->sDiffStore('diff:set', 'set:all', 'set:archived');

|

at line 3701 Redis|array|false sInter(array|string $key, string ...$other_keys)

Given one or more Redis SET keys, this command will return all of the elements that are in every one.

Parameters

| array|string | $key |

The first SET key to intersect.

| | string | ...$other_keys |

One or more Redis SET keys.

|

Return Value

| Redis|array|false | |

See also

| https://redis.io/docs/latest/commands/sinter/ | |

Examples

|

$redis->pipeline()
      ->del('alice_likes', 'bob_likes', 'bill_likes')
      ->sadd('alice_likes', 'asparagus', 'broccoli', 'carrot', 'potato')
      ->sadd('bob_likes', 'asparagus', 'carrot', 'potato')
      ->sadd('bill_likes', 'broccoli', 'potato')
      ->exec();

var_dump($redis->sinter('alice_likes', 'bob_likes', 'bill_likes'));

|

at line 3721 Redis|int|false sintercard(array $keys, int $limit = -1)

Compute the intersection of one or more sets and return the cardinality of the result.

Parameters

| array | $keys |

One or more set key names.

| | int | $limit |

A maximum cardinality to return. This is useful to put an upper bound on the amount of work Redis will do.

|

Return Value

| Redis|int|false | The |

See also

| https://redis.io/docs/latest/commands/sintercard/ | |

Examples

|

$redis->sAdd('set1', 'apple', 'pear', 'banana', 'carrot');
$redis->sAdd('set2', 'apple', 'banana');
$redis->sAdd('set3', 'pear', 'banana');

$redis->sInterCard(['set1', 'set2', 'set3']);

|

at line 3742 Redis|int|false sInterStore(array|string $key, string ...$other_keys)

Perform the intersection of one or more Redis SETs, storing the result in a destination key, rather than returning them.

Parameters

| array|string | $key |

Either a string key, or an array of keys (with at least two elements, consisting of the destination key name and one or more source keys names.

| | string | ...$other_keys |

If the first argument was a string, subsequent arguments should be source key names.

|

Return Value

| Redis|int|false |

The number of values stored in the destination key or false on failure.

|

See also

| https://redis.io/docs/latest/commands/sinterstore/ | | | \Redis::sinter() | |

Examples

|

$redis->sInterStore(['dst', 'src1', 'src2', 'src3']);
$redis->sInterStore('dst', 'src1', 'src'2', 'src3');

|

at line 3757 Redis|array|false sMembers(string $key)

Retrieve every member from a set key.

Parameters

| string | $key |

The set name.

|

Return Value

| Redis|array|false |

Every element in the set or false on failure.

|

See also

| https://redis.io/docs/latest/commands/smembers/ | |

Examples

|

$redis->sAdd('tng-crew', ...['Picard', 'Riker', 'Data', 'Worf', 'La Forge', 'Troi', 'Crusher', 'Broccoli']);
$redis->sMembers('tng-crew');

|

at line 3777 Redis|array|false sMisMember(string $key, string $member, string ...$other_members)

Check if one or more values are members of a set.

Parameters

| string | $key |

The set to query.

| | string | $member |

The first value to test if exists in the set.

| | string | ...$other_members |

Any number of additional values to check.

|

Return Value

| Redis|array|false |

An array of integers representing whether each passed value was a member of the set.

|

See also

| https://redis.io/docs/latest/commands/smismember/ | | | https://redis.io/docs/latest/commands/smember/ | | | \Redis::smember() | |

Examples

|

$redis->sAdd('ds9-crew', ...["Sisko", "Kira", "Dax", "Worf", "Bashir", "O'Brien"]);
$members = $redis->sMIsMember('ds9-crew', ...['Sisko', 'Picard', 'Data', 'Worf']);

|

at line 3797 Redis|bool sMove(string $src, string $dst, mixed $value)

Pop a member from one set and push it onto another. This command will create the destination set if it does not currently exist.

Parameters

| string | $src |

The source set.

| | string | $dst |

The destination set.

| | mixed | $value |

The member you wish to move.

|

Return Value

| Redis|bool |

True if the member was moved, and false if it wasn't in the set.

|

See also

| https://redis.io/docs/latest/commands/smove/ | |

Examples

|

$redis->sAdd('numbers', 'zero', 'one', 'two', 'three', 'four');
$redis->sMove('numbers', 'evens', 'zero');
$redis->sMove('numbers', 'evens', 'two');
$redis->sMove('numbers', 'evens', 'four');

|

at line 3813 Redis|string|array|false sPop(string $key, int $count = 0)

Remove one or more elements from a set.

Parameters

| string | $key |

The set in question.

| | int | $count |

An optional number of members to pop. This defaults to removing one element.

|

Return Value

| Redis|string|array|false | |

See also

| https://redis.io/docs/latest/commands/spop/ | |

Examples

|

$redis->del('numbers', 'evens');
$redis->sAdd('numbers', 'zero', 'one', 'two', 'three', 'four');
$redis->sPop('numbers');

|

at line 3836 mixed sRandMember(string $key, int $count = 0)

Retrieve one or more random members of a set.

Parameters

| string | $key |

The set to query.

| | int | $count |

An optional count of members to return.

If this value is positive, Redis will return up to the requested number but with unique elements that will never repeat. This means you may receive fewer then $count replies.

If the number is negative, Redis will return the exact number requested but the result may contain duplicate elements.

|

Return Value

| mixed |

One or more random members or false on failure.

|

See also

| https://redis.io/docs/latest/commands/srandmember/ | |

Examples

|

$redis->sRandMember('myset');

| |

$redis->sRandMember('myset', 10);

| |

$redis->sRandMember('myset', -10);

|

at line 3850 Redis|array|false sUnion(string $key, string ...$other_keys)

Returns the union of one or more Redis SET keys.

Parameters

| string | $key |

The first SET to do a union with

| | string | ...$other_keys |

One or more subsequent keys

|

Return Value

| Redis|array|false |

The union of the one or more input sets or false on failure.

|

See also

| https://redis.io/docs/latest/commands/sunion/ | |

Examples

|

$redis->sunion('set1', 'set2');

|

at line 3869 Redis|int|false sUnionStore(string $dst, string $key, string ...$other_keys)

Perform a union of one or more Redis SET keys and store the result in a new set

Parameters

| string | $dst |

The destination key

| | string | $key |

The first source key

| | string | ...$other_keys |

One or more additional source keys

|

Return Value

| Redis|int|false |

The number of elements stored in the destination SET or false on failure.

|

See also

| https://redis.io/docs/latest/commands/sunionstore/ | | | \Redis::sunion() | |

Examples

|

$redis->sUnionStore('union:set', 'set:a', 'set:b');

|

at line 3884 Redis|bool save()

Persist the Redis database to disk. This command will block the server until the save is completed. For a nonblocking alternative, see Redis::bgsave().

Return Value

| Redis|bool |

Returns true unless an error occurs.

|

See also

| https://redis.io/docs/latest/commands/save/ | | | \Redis::bgsave() | |

Examples

|

$redis->save();

|

at line 3944 array|false scan(null|int|string $iterator, string|null $pattern = null, int $count = 0, string|null $type = null)

Incrementally scan the Redis keyspace, with optional pattern and type matching.

A note about Redis::SCAN_NORETRY and Redis::SCAN_RETRY.

For convenience, PhpRedis can retry SCAN commands itself when Redis returns an empty array of keys with a nonzero iterator. This can happen when matching against a pattern that very few keys match inside a key space with a great many keys. The following example demonstrates how to use Redis::scan() with the option disabled and enabled.

Parameters

| null|int|string | $iterator |

The cursor returned by Redis for every subsequent call to SCAN. On the initial invocation of the call, it should be initialized by the caller to NULL. Each time SCAN is invoked, the iterator will be updated to a new number, until finally Redis will set the value to zero, indicating that the scan is complete.

| | string|null | $pattern |

An optional glob-style pattern for matching key names. If passed as NULL, it is the equivalent of sending '*' (match every key).

| | int | $count |

A hint to redis that tells it how many keys to return in a single call to SCAN. The larger the number, the longer Redis may block clients while iterating the key space.

| | string|null | $type |

An optional argument to specify which key types to scan (e.g. 'STRING', 'LIST', 'SET')

|

Return Value

| array|false |

An array of keys, or false if no keys were returned for this invocation of scan. Note that it is possible for Redis to return zero keys before having scanned the entire key space, so the caller should instead continue to SCAN until the iterator reference is returned to zero.

|

See also

| https://redis.io/docs/latest/commands/scan/ | | | Redis::setOption | |

Examples

|

$redis = new Redis(['host' => 'localhost']);

$redis->setOption(Redis::OPT_SCAN, Redis::SCAN_NORETRY);

$it = null;

do {
    $keys = $redis->scan($it, '*zorg*');
    foreach ($keys as $key) {
        echo "KEY: $key\n";
    }
} while ($it != 0);

$redis->setOption(Redis::OPT_SCAN, Redis::SCAN_RETRY);

$it = null;

// When Redis::SCAN_RETRY is enabled, we can use simpler logic, as we will never receive an
// empty array of keys when the iterator is nonzero.
while ($keys = $redis->scan($it, '*zorg*')) {
    foreach ($keys as $key) {
        echo "KEY: $key\n";
    }
}

|

at line 3957 Redis|int|false scard(string $key)

Retrieve the number of members in a Redis set.

Parameters

| string | $key |

The set to get the cardinality of.

|

Return Value

| Redis|int|false |

The cardinality of the set or false on failure.

|

See also

| https://redis.io/docs/latest/commands/scard/ | |

Examples

|

$redis->scard('set');

|

at line 3972 mixed script(string $command, mixed ...$args)

An administrative command used to interact with LUA scripts stored on the server.

Parameters

| string | $command |

The script suboperation to execute.

| | mixed | ...$args |

One or more additional argument

|

Return Value

| mixed |

This command returns various things depending on the specific operation executed.

|

See also

| https://redis.io/docs/latest/commands/script/ | |

Examples

|

$redis->script('load', 'return 1');

| |

$redis->script('exists', sha1('return 1'));

|

at line 3985 Redis|bool select(int $db)

Select a specific Redis database.

Parameters

| int | $db |

The database to select. Note that by default Redis has 16 databases (0-15).

|

Return Value

| Redis|bool |

true on success and false on failure

|

See also

| https://redis.io/docs/latest/commands/select/ | |

Examples

|

$redis->select(1);

|

at line 4016 Redis|string|bool set(string $key, mixed $value, mixed $options = null)

Create or set a Redis STRING key to a value.

Parameters

| string | $key |

The key name to set.

| | mixed | $value |

The value to set the key to.

| | mixed | $options |

Either an array with options for how to perform the set or an integer with an expiration. If an expiration is set PhpRedis will actually send the SETEX command.

OPTION DESCRIPTION


['EX' => 60] expire 60 seconds. ['PX' => 6000] expire in 6000 milliseconds. ['EXAT' => time() + 10] expire in 10 seconds. ['PXAT' => time()*1000 + 1000] expire in 1 second. ['KEEPTTL' => true] Redis will not update the key's current TTL. ['XX'] Only set the key if it already exists. ['NX'] Only set the key if it doesn't exist. ['GET'] Instead of returning +OK return the previous value of the key or NULL if the key didn't exist.

|

Return Value

| Redis|string|bool |

True if the key was set or false on failure.

|

See also

| https://redis.io/docs/latest/commands/set/ | | | https://redis.io/docs/latest/commands/setex/ | |

Examples

|

$redis->set('key', 'value');

| |

$redis->set('key', 'expires_in_60_seconds', 60);

|

at line 4032 Redis|int|false setBit(string $key, int $idx, bool $value)

Set a specific bit in a Redis string to zero or one

Parameters

| string | $key |

The Redis STRING key to modify

| | int | $idx | | | bool | $value |

Whether to set the bit to zero or one.

|

Return Value

| Redis|int|false |

The original value of the bit or false on failure.

|

See also

| https://redis.io/docs/latest/commands/setbit/ | |

Examples

|

$redis->set('foo', 'bar');
$redis->setbit('foo', 7, 1);

|

at line 4049 Redis|int|false setRange(string $key, int $index, string $value)

Update or append to a Redis string at a specific starting index

Parameters

| string | $key |

The key to update

| | int | $index |

Where to insert the provided value

| | string | $value |

The value to copy into the string.

|

Return Value

| Redis|int|false |

The new length of the string or false on failure

|

See also

| https://redis.io/docs/latest/commands/setrange/ | |

Examples

|

$redis->set('message', 'Hello World');
$redis->setRange('message', 6, 'Redis');

|

at line 4084 bool setOption(int $option, mixed $value)

Set a configurable option on the Redis object.

Following are a list of options you can set:

OPTIONTYPEDESCRIPTION
OPT_MAX_RETRIESintThe maximum number of times Redis will attempt to reconnect if it gets disconnected, before throwing an exception.
OPT_SCANenumRedis::OPT_SCAN_RETRY, or Redis::OPT_SCAN_NORETRY. Whether PhpRedis should automatically SCAN again when zero keys but a nonzero iterator are returned.
OPT_SERIALIZERenumSet the automatic data serializer.
Redis::SERIALIZER_NONE
Redis::SERIALIZER_PHP
Redis::SERIALIZER_IGBINARY
Redis::SERIALIZER_MSGPACK, Redis::SERIALIZER_JSON
OPT_PREFIXstringA string PhpRedis will use to prefix every key we read or write.
OPT_READ_TIMEOUTfloatHow long PhpRedis will block for a response from Redis before throwing a 'read error on connection' exception.
OPT_TCP_KEEPALIVEboolSet or disable TCP_KEEPALIVE on the connection.
OPT_COMPRESSIONenumSet the compression algorithm
Redis::COMPRESSION_NONE
Redis::COMPRESSION_LZF
Redis::COMPRESSION_LZ4
Redis::COMPRESSION_ZSTD
OPT_REPLY_LITERALboolIf set to true, PhpRedis will return the literal string Redis returns for LINE replies (e.g. '+OK'), rather than true.
OPT_COMPRESSION_LEVELintSet a specific compression level if Redis is compressing data.
OPT_NULL_MULTIBULK_AS_NULLboolCauses PhpRedis to return NULL rather than false for NULL MULTIBULK replies
OPT_BACKOFF_ALGORITHMenumThe exponential backoff strategy to use.
OPT_BACKOFF_BASEintThe minimum delay between retries when backing off.
OPT_BACKOFF_CAPintThe maximum delay between replies when backing off.

Parameters

| int | $option |

The option constant.

| | mixed | $value |

The option value.

|

Return Value

| bool |

true if the setting was updated, false if not.

|

See also

| Redis::getOption | | | Redis::__construct | for details about backoff strategies. |

Examples

|

$redis->setOption(Redis::OPT_PREFIX, 'app:');

|

at line 4099 Redis|bool setex(string $key, int $expire, mixed $value)

Set a Redis STRING key with a specific expiration in seconds.

Parameters

| string | $key |

The name of the key to set.

| | int | $expire |

The key's expiration in seconds.

| | mixed | $value |

The value to set the key.

|

Return Value

| Redis|bool |

True on success or false on failure.

|

See also

| https://redis.io/docs/latest/commands/setex/ | |

Examples

|

$redis->setex('60s-ttl', 60, 'some-value');

|

at line 4114 Redis|bool setnx(string $key, mixed $value)

Set a key to a value, but only if that key does not already exist.

Parameters

| string | $key |

The key name to set.

| | mixed | $value |

What to set the key to.

|

Return Value

| Redis|bool |

Returns true if the key was set and false otherwise.

|

See also

| https://redis.io/docs/latest/commands/setnx/ | |

Examples

|

$redis->setnx('existing-key', 'existing-value');

| |

$redis->setnx('new-key', 'new-value');

|

at line 4128 Redis|bool sismember(string $key, mixed $value)

Check whether a given value is the member of a Redis SET.

Parameters

| string | $key |

The redis set to check.

| | mixed | $value |

The value to test.

|

Return Value

| Redis|bool |

True if the member exists and false if not.

|

See also

| https://redis.io/docs/latest/commands/sismember/ | |

Examples

|

$redis->sismember('myset', 'mem1', 'mem2');

|

at line 4148 Redis|bool slaveof(string|null $host = null, int $port = 6379) deprecated

deprecated

| | |

Turn a redis instance into a replica of another or promote a replica to a primary.

This method and the corresponding command in Redis has been marked deprecated and users should instead use Redis::replicaof() if connecting to redis-server

= 5.0.0.

Parameters

| string|null | $host | | | int | $port | |

Return Value

| Redis|bool | |

See also

| https://redis.io/docs/latest/commands/slaveof/ | | | https://redis.io/docs/latest/commands/replicaof/ | | | Redis::replicaof | |

Examples

|

$redis->slaveof('10.0.0.5', 6380);

|

at line 4174 Redis|bool replicaof(string|null $host = null, int $port = 6379)

Used to turn a Redis instance into a replica of another, or to remove replica status promoting the instance to a primary.

Parameters

| string|null | $host |

The host of the primary to start replicating.

| | int | $port |

The port of the primary to start replicating.

|

Return Value

| Redis|bool |

Success if we were successfully able to start replicating a primary or were able to promote the replicat to a primary.

|

See also

| https://redis.io/docs/latest/commands/replicaof/ | | | https://redis.io/docs/latest/commands/slaveof/ | | | Redis::slaveof | |

Examples

|

$redis = new Redis(['host' => 'localhost']);

// Attempt to become a replica of a Redis instance at 127.0.0.1:9999
$redis->replicaof('127.0.0.1', 9999);

// When passed no arguments, PhpRedis will deliver the command `REPLICAOF NO ONE`
// attempting to promote the instance to a primary.
$redis->replicaof();

|

at line 4192 Redis|int|false touch(array|string $key_or_array, string ...$more_keys)

Update one or more keys last modified metadata.

Parameters

| array|string | $key_or_array |

Either the first key or if passed as the only argument an array of keys.

| | string | ...$more_keys |

One or more keys to send to the command.

|

Return Value

| Redis|int|false |

This command returns the number of keys that exist and had their last modified time reset

|

See also

| https://redis.io/docs/latest/commands/touch/ | |

Examples

|

$redis->touch('cache:1', 'cache:2');

|

at line 4220 mixed slowlog(string $operation, int $length = 0)

Interact with Redis' slowlog functionality in various ways, depending on the value of 'operation'.

Parameters

| string | $operation |

The operation you wish to perform. This can be one of the following values: 'GET' - Retrieve the Redis slowlog as an array. 'LEN' - Retrieve the length of the slowlog. 'RESET' - Remove all slowlog entries.

| | int | $length |

This optional argument can be passed when operation is 'get' and will specify how many elements to retrieve. If omitted Redis will send up to a default number of entries, which is configurable.

Note: With Redis >= 7.0.0 you can send -1 to mean "all".

|

Return Value

| mixed | |

See also

| https://redis.io/docs/latest/commands/slowlog/ | |

Examples

|

$redis->slowlog('get', -1); // Retrieve all slowlog entries.

| |

$redis->slowlog('len'); // Retrieve slowlog length.

| |

$redis->slowlog('reset'); // Reset the slowlog.

|

at line 4249 mixed sort(string $key, array|null $options = null)

Sort the contents of a Redis key in various ways.

Parameters

| string | $key |

The key you wish to sort

| | array|null | $options |

Various options controlling how you would like the data sorted. See blow for a detailed description of this options array.

|

Return Value

| mixed |

This command can either return an array with the sorted data or the number of elements placed in a destination set when using the STORE option.

|

See also

| https://redis.io/docs/latest/commands/sort/ | |

Examples

|

$options = [
    'SORT' => 'ASC'|| 'DESC' // Sort in descending or descending order.
    'ALPHA' => true || false // Whether to sort alphanumerically.
    'LIMIT' => [0, 10] // Return a subset of the data at offset, count
    'BY' => 'weight_*' // For each element in the key, read data from the
                                 external key weight_* and sort based on that value.
    'GET' => 'weight_*' // For each element in the source key, retrieve the
                                 data from key weight_* and return that in the result
                                 rather than the source keys' element. This can
                                 be used in combination with 'BY'
];

|

at line 4261 mixed sort_ro(string $key, array|null $options = null)

This is simply a read-only variant of the sort command

Parameters

| string | $key | | | array|null | $options | |

Return Value

| mixed | |

See also

| Redis::sort | | | https://redis.io/docs/latest/commands/sort_ro/ | |

Examples

|

$redis->sort_ro('numbers', ['LIMIT' => [0, 5]]);

|

at line 4272 array sortAsc(string $key, string|null $pattern = null, mixed $get = null, int $offset = -1, int $count = -1, string|null $store = null) deprecated

deprecated

| | |

No description

Parameters

| string | $key | | | string|null | $pattern | | | mixed | $get | | | int | $offset | | | int | $count | | | string|null | $store | |

Return Value

| array | |

See also

| https://redis.io/docs/latest/commands/sort/ | |

Examples

|

$redis->sortAsc('numbers');

|

at line 4283 array sortAscAlpha(string $key, string|null $pattern = null, mixed $get = null, int $offset = -1, int $count = -1, string|null $store = null) deprecated

deprecated

| | |

No description

Parameters

| string | $key | | | string|null | $pattern | | | mixed | $get | | | int | $offset | | | int | $count | | | string|null | $store | |

Return Value

| array | |

See also

| https://redis.io/docs/latest/commands/sort/ | |

Examples

|

$redis->sortAscAlpha('tags');

|

at line 4294 array sortDesc(string $key, string|null $pattern = null, mixed $get = null, int $offset = -1, int $count = -1, string|null $store = null) deprecated

deprecated

| | |

No description

Parameters

| string | $key | | | string|null | $pattern | | | mixed | $get | | | int | $offset | | | int | $count | | | string|null | $store | |

Return Value

| array | |

See also

| https://redis.io/docs/latest/commands/sort/ | |

Examples

|

$redis->sortDesc('numbers');

|

at line 4305 array sortDescAlpha(string $key, string|null $pattern = null, mixed $get = null, int $offset = -1, int $count = -1, string|null $store = null) deprecated

deprecated

| | |

No description

Parameters

| string | $key | | | string|null | $pattern | | | mixed | $get | | | int | $offset | | | int | $count | | | string|null | $store | |

Return Value

| array | |

See also

| https://redis.io/docs/latest/commands/sort/ | |

Examples

|

$redis->sortDescAlpha('tags');

|

at line 4320 Redis|int|false srem(string $key, mixed $value, mixed ...$other_values)

Remove one or more values from a Redis SET key.

Parameters

| string | $key |

The Redis SET key in question.

| | mixed | $value |

The first value to remove.

| | mixed | ...$other_values |

One or more additional values to remove.

|

Return Value

| Redis|int|false |

The number of values removed from the set or false on failure.

|

See also

| https://redis.io/docs/latest/commands/srem/ | |

Examples

|

$redis->sRem('set1', 'mem1', 'mem2', 'not-in-set');

|

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

Scan the members of a redis SET key.

Parameters

| string | $key |

The Redis SET key in question.

| | null|int|string | $iterator |

A reference to an iterator which should be initialized to NULL that PhpRedis will update with the value returned from Redis after each subsequent call to SSCAN. Once this cursor is zero you know all members have been traversed.

| | string|null | $pattern |

An optional glob style pattern to match against, so Redis only returns the subset of members matching this pattern.

| | int | $count |

A hint to Redis as to how many members it should scan in one command before returning members for that iteration.

|

Return Value

| array|false | |

See also

| https://redis.io/docs/latest/commands/sscan/ | | | https://redis.io/docs/latest/commands/scan/ | | | Redis::setOption | |

Examples

|

$redis->del('myset');
for ($i = 0; $i < 10000; $i++) {
    $redis->sAdd('myset', "member:$i");
}
$redis->sadd('myset', 'foofoo');

$redis->setOption(Redis::OPT_SCAN, Redis::SCAN_NORETRY);

$scanned = 0;
$it = null;

// Without Redis::SCAN_RETRY we may receive empty results and
// a nonzero iterator.
do {
    // Scan members containing '5'
    $members = $redis->sscan('myset', $it, '*5*');
    foreach ($members as $member) {
         echo "NORETRY: $member\n";
         $scanned++;
    }
} while ($it != 0);
echo "TOTAL: $scanned\n";

$redis->setOption(Redis::OPT_SCAN, Redis::SCAN_RETRY);

$scanned = 0;
$it = null;

// With Redis::SCAN_RETRY PhpRedis will never return an empty array
// when the cursor is non-zero
while (($members = $redis->sscan('myset', $it, '*5*'))) {
    foreach ($members as $member) {
        echo "RETRY: $member\n";
        $scanned++;
    }
}

|

at line 4408 bool ssubscribe(array $channels, callable $cb)

Subscribes the client to the specified shard channels.

Parameters

| array | $channels |

One or more channel names.

| | callable | $cb |

The callback PhpRedis will invoke when we receive a message from one of the subscribed channels.

|

Return Value

| bool |

True on success, false on faiilure. Note that this command will block the client in a subscribe loop, waiting for messages to arrive.

|

See also

| https://redis.io/docs/latest/commands/ssubscribe/ | |

Examples

|

$redis = new Redis(['host' => 'localhost']);

$redis->ssubscribe(['channel-1', 'channel-2'], function ($redis, $channel, $message) {
    echo "[$channel]: $message\n";

    // Unsubscribe from the message channel when we read 'quit'
    if ($message == 'quit') {
        echo "Unsubscribing from '$channel'\n";
        $redis->sunsubscribe([$channel]);
    }
});

// Once we read 'quit' from both channel-1 and channel-2 the subscribe loop will be
// broken and this command will execute.
echo "Subscribe loop ended\n";

|

at line 4422 Redis|int|false strlen(string $key)

Retrieve the length of a Redis STRING key.

Parameters

| string | $key |

The key we want the length of.

|

Return Value

| Redis|int|false |

The length of the string key if it exists, zero if it does not, and false on failure.

|

See also

| https://redis.io/docs/latest/commands/strlen/ | |

Examples

|

$redis->strlen('mykey');

|

at line 4453 bool subscribe(array $channels, callable $cb)

Subscribe to one or more Redis pubsub channels.

Parameters

| array | $channels |

One or more channel names.

| | callable | $cb |

The callback PhpRedis will invoke when we receive a message from one of the subscribed channels.

|

Return Value

| bool |

True on success, false on faiilure. Note that this command will block the client in a subscribe loop, waiting for messages to arrive.

|

See also

| https://redis.io/docs/latest/commands/subscribe/ | |

Examples

|

$redis = new Redis(['host' => 'localhost']);

$redis->subscribe(['channel-1', 'channel-2'], function ($redis, $channel, $message) {
    echo "[$channel]: $message\n";

    // Unsubscribe from the message channel when we read 'quit'
    if ($message == 'quit') {
        echo "Unsubscribing from '$channel'\n";
        $redis->unsubscribe([$channel]);
    }
});

// Once we read 'quit' from both channel-1 and channel-2 the subscribe loop will be
// broken and this command will execute.
echo "Subscribe loop ended\n";

|

at line 4477 Redis|array|bool sunsubscribe(array $channels)

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

Parameters

| array | $channels |

One or more channels to unsubscribe from.

|

Return Value

| Redis|array|bool |

The array of unsubscribed channels.

|

See also

| https://redis.io/docs/latest/commands/sunsubscribe/ | | | Redis::ssubscribe | |

Examples

|

$redis->ssubscribe(['channel-1', 'channel-2'], function ($redis, $channel, $message) {
    if ($message == 'quit') {
        echo "$channel => 'quit' detected, unsubscribing!\n";
        $redis->sunsubscribe([$channel]);
    } else {
        echo "$channel => $message\n";
    }
});

echo "We've unsubscribed from both channels, exiting\n";

|

at line 4500 Redis|bool swapdb(int $src, int $dst)

Atomically swap two Redis databases so that all of the keys in the source database will now be in the destination database and vice-versa.

Note: This command simply swaps Redis' internal pointer to the database and is therefore very fast, regardless of the size of the underlying databases.

Parameters

| int | $src |

The source database number

| | int | $dst |

The destination database number

|

Return Value

| Redis|bool |

Success if the databases could be swapped and false on failure.

|

See also

| https://redis.io/docs/latest/commands/swapdb/ | | | Redis::del | |

Examples

|

$redis->select(0);
$redis->set('db0-key', 'db0-value');
$redis->swapdb(0, 1);
$redis->get('db0-key');

|

at line 4512 Redis|array time()

Retrieve the server time from the connected Redis instance.

Return Value

| Redis|array |

A two element array consisting of a Unix Timestamp and the number of microseconds elapsed since the second.

|

See also

| https://redis.io/docs/latest/commands/time/ | |

Examples

|

$redis->time();

|

at line 4526 Redis|int|false ttl(string $key)

Get the amount of time a Redis key has before it will expire, in seconds.

Parameters

| string | $key |

The Key we want the TTL for.

|

Return Value

| Redis|int|false |

(a) The number of seconds until the key expires, or -1 if the key has no expiration, and -2 if the key does not exist. In the event of an error, this command will return false.

|

See also

| https://redis.io/docs/latest/commands/ttl/ | |

Examples

|

$redis->ttl('mykey');

|

at line 4552 Redis|int|false type(string $key)

Get the type of a given Redis key.

Parameters

| string | $key |

The key to check

|

Return Value

| Redis|int|false |

The Redis type constant or false on failure.

The Redis class defines several type constants that correspond with Redis key types.

Redis::REDIS_NOT_FOUND
Redis::REDIS_STRING
Redis::REDIS_SET
Redis::REDIS_LIST
Redis::REDIS_ZSET
Redis::REDIS_HASH
Redis::REDIS_STREAM
Redis::REDIS_VECTORSET

|

See also

| https://redis.io/docs/latest/commands/type/ | |

Examples

|

foreach ($redis->keys('*') as $key) {
    echo "$key => " . $redis->type($key) . "\n";
}

|

Delete one or more keys from the Redis database. Unlike this operation, the actual deletion is asynchronous, meaning it is safe to delete large keys without fear of Redis blocking for a long period of time.

Parameters

| array|string | $key |

Either an array with one or more keys or a string with the first key to delete.

| | string | ...$other_keys |

If the first argument passed to this method was a string you may pass any number of additional key names.

|

Return Value

| Redis|int|false |

The number of keys deleted or false on failure.

|

See also

| https://redis.io/docs/latest/commands/unlink/ | | | https://redis.io/docs/latest/commands/del/ | | | Redis::del | |

Examples

|

$redis->unlink('key1', 'key2', 'key3');

| |

$redis->unlink(['key1', 'key2', 'key3']);

|

at line 4596 Redis|array|bool unsubscribe(array $channels)

Unsubscribe from one or more subscribed channels.

Parameters

| array | $channels |

One or more channels to unsubscribe from.

|

Return Value

| Redis|array|bool |

The array of unsubscribed channels.

|

See also

| https://redis.io/docs/latest/commands/unsubscribe/ | | | Redis::subscribe | |

Examples

|

$redis->subscribe(['channel-1', 'channel-2'], function ($redis, $channel, $message) {
    if ($message == 'quit') {
        echo "$channel => 'quit' detected, unsubscribing!\n";
        $redis->unsubscribe([$channel]);
    } else {
        echo "$channel => $message\n";
    }
});

echo "We've unsubscribed from both channels, exiting\n";

|

at line 4611 Redis|bool unwatch()

Remove any previously WATCH'ed keys in a transaction.

Return Value

| Redis|bool |

True on success and false on failure.

|

See also

| https://redis.io/docs/latest/commands/unwatch/ | | | https://redis.io/docs/latest/commands/unwatch/ | | | Redis::watch | |

Examples

|

$redis->unwatch();

|

at line 4651 Redis|bool watch(array|string $key, string ...$other_keys)

Watch one or more keys for conditional execution of a transaction.

Parameters

| array|string | $key |

Either an array with one or more key names, or a string key name

| | string | ...$other_keys |

If the first argument was passed as a string, any number of additional string key names may be passed variadically.

|

Return Value

| Redis|bool | |

See also

| https://redis.io/docs/latest/commands/watch/ | | | https://redis.io/docs/latest/commands/unwatch/ | |

Examples

|

$redis1 = new Redis(['host' => 'localhost']);
$redis2 = new Redis(['host' => 'localhost']);

// Start watching 'incr-key'
$redis1->watch('incr-key');

// Retrieve its value.
$val = $redis1->get('incr-key');

// A second client modifies 'incr-key' after we read it.
$redis2->set('incr-key', 0);

// Because another client changed the value of 'incr-key' after we read it, this
// is no longer a proper increment operation, but because we are `WATCH`ing the
// key, this transaction will fail and we can try again.
//
// If were to comment out the above `$redis2->set('incr-key', 0)` line the
// transaction would succeed.
$redis1->multi();
$redis1->set('incr-key', $val + 1);
$res = $redis1->exec();

// bool(false)
var_dump($res);

|

at line 4668 int|false wait(int $numreplicas, int $timeout)

Block the client up to the provided timeout until a certain number of replicas have confirmed receiving them.

Parameters

| int | $numreplicas |

The number of replicas we want to confirm write operations

| | int | $timeout |

How long to wait (zero meaning forever).

|

Return Value

| int|false |

The number of replicas that have confirmed or false on failure.

|

See also

| https://redis.io/docs/latest/commands/wait/ | |

Examples

|

$redis->wait(1, 1000);

|

at line 4709 int|false xack(string $key, string $group, array $ids)

Acknowledge one or more messages that are pending (have been consumed using XREADGROUP but not yet acknowledged by XACK.)

Parameters

| string | $key |

The stream to query.

| | string | $group |

The consumer group to use.

| | array | $ids |

An array of stream entry IDs.

|

Return Value

| int|false |

The number of acknowledged messages

|

See also

| https://redis.io/docs/latest/commands/xack/ | | | https://redis.io/docs/latest/commands/xreadgroup/ | | | Redis::xack | |

Examples

|

$redis->xAdd('ships', '*', ['name' => 'Enterprise']);
$redis->xAdd('ships', '*', ['name' => 'Defiant']);

$redis->xGroup('CREATE', 'ships', 'Federation', '0-0');

// Consume a single message with the consumer group 'Federation'
$ship = $redis->xReadGroup('Federation', 'Picard', ['ships' => '>'], 1);

/* Retrieve the ID of the message we read.
assert(isset($ship['ships']));
$id = key($ship['ships']);

// The message we just read is now pending.
$res = $redis->xPending('ships', 'Federation'));
var_dump($res);

// We can tell Redis we were able to process the message by using XACK
$res = $redis->xAck('ships', 'Federation', [$id]);
assert($res === 1);

// The message should no longer be pending.
$res = $redis->xPending('ships', 'Federation');
var_dump($res);

|

at line 4732 Redis|string|false xadd(string $key, string $id, array $values, int $maxlen = 0, bool $approx = false, bool $nomkstream = false)

Append a message to a stream.

Parameters

| string | $key |

The stream name.

| | string | $id |

The ID for the message we want to add. This can be the special value '' which means Redis will generate the ID that appends the message to the end of the stream. It can also be a value in the form - which will generate an ID that appends to the end of entries with the same value (if any exist).

| | array | $values | | | int | $maxlen |

If specified Redis will append the new message but trim any number of the oldest messages in the stream until the length is <= $maxlen.

| | bool | $approx |

Used in conjunction with $maxlen, this flag tells Redis to trim the stream but in a more efficient way, meaning the trimming may not be exactly to $maxlen values.

| | bool | $nomkstream |

If passed as TRUE, the stream must exist for Redis to append the message.

|

Return Value

| Redis|string|false | |

See also

| https://redis.io/docs/latest/commands/xadd/ | |

Examples

|

$redis->xAdd('ds9-season-1', '1-1', ['title' => 'Emissary Part 1']);

| |

$redis->xAdd('ds9-season-1', '1-2', ['title' => 'A Man Alone']);

|

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

This command allows a consumer to claim pending messages that have been idle for a specified period of time.

Its purpose is to provide a mechanism for picking up messages that may have had a failed consumer.

Parameters

| string | $key |

The stream to check.

| | string | $group |

The consumer group to query.

| | string | $consumer |

Which consumer to check.

| | int | $min_idle |

The minimum time in milliseconds for the message to have been pending.

| | string | $start |

The minimum message id to check.

| | int | $count |

An optional limit on how many messages are returned.

| | bool | $justid |

If the client only wants message IDs and not all of their data.

|

Return Value

| Redis|bool|array |

An array of pending IDs or false if there are none, or on failure.

|

See also

| https://redis.io/docs/latest/commands/xautoclaim/ | | | https://redis.io/docs/latest/commands/xclaim/ | | | https://redis.io/docs/data-types/streams-tutorial/ | |

Examples

|

$redis->xGroup('CREATE', 'ships', 'combatants', '0-0', true);

$redis->xAdd('ships', '1424-74205', ['name' => 'Defiant']);

// Consume the ['name' => 'Defiant'] message
$msgs = $redis->xReadGroup('combatants', "Jem'Hadar", ['ships' => '>'], 1);

// The "Jem'Hadar" consumer has the message presently
$pending = $redis->xPending('ships', 'combatants');
var_dump($pending);

// Assume control of the pending message with a different consumer.
$res = $redis->xAutoClaim('ships', 'combatants', 'Sisko', 0, '0-0');

// Now the 'Sisko' consumer owns the message
$pending = $redis->xPending('ships', 'combatants');
var_dump($pending);

|

at line 4828 Redis|array|bool xclaim(string $key, string $group, string $consumer, int $min_idle, array $ids, array $options)

This method allows a consumer to take ownership of pending stream entries, by ID. Another command that does much the same thing but does not require passing specific IDs is Redis::xAutoClaim.

Parameters

| string | $key |

The stream we wish to claim messages for.

| | string | $group |

Our consumer group.

| | string | $consumer |

Our consumer.

| | int | $min_idle |

The minimum idle-time in milliseconds a message must have for ownership to be transferred.

| | array | $ids | | | array | $options |

An options array that modifies how the command operates.

# Following is an options array describing every option you can pass. Note that
# 'IDLE', and 'TIME' are mutually exclusive.
$options = [
    'IDLE' => 3 # Set the idle time of the message to a 3. By default
                                # the idle time is set to zero.
    'TIME' => 1000*time() # Same as IDLE except it takes a unix timestamp in
                                # milliseconds.
    'RETRYCOUNT' => 0 # Set the retry counter to zero. By default XCLAIM
                                # doesn't modify the counter.
    'FORCE' # Creates the pending message entry even if IDs are
                                # not already
                                # in the PEL with another client.
    'JUSTID' # Return only an array of IDs rather than the messages
                                # themselves.
];

|

Return Value

| Redis|array|bool |

An array of claimed messages or false on failure.

|

See also

| https://redis.io/docs/latest/commands/xclaim/ | | | https://redis.io/docs/latest/commands/xautoclaim./ | |

Examples

|

$redis->xGroup('CREATE', 'ships', 'combatants', '0-0', true);

$redis->xAdd('ships', '1424-74205', ['name' => 'Defiant']);

// Consume the ['name' => 'Defiant'] message
$msgs = $redis->xReadGroup('combatants', "Jem'Hadar", ['ships' => '>'], 1);

// The "Jem'Hadar" consumer has the message presently
$pending = $redis->xPending('ships', 'combatants');
var_dump($pending);

assert($pending && isset($pending[1]));

// Claim the message by ID.
$claimed = $redis->xClaim('ships', 'combatants', 'Sisko', 0, [$pending[1]], ['JUSTID']);
var_dump($claimed);

// Now the 'Sisko' consumer owns the message
$pending = $redis->xPending('ships', 'combatants');
var_dump($pending);

|

at line 4842 Redis|int|false xdel(string $key, array $ids)

Remove one or more specific IDs from a stream.

Parameters

| string | $key |

The stream to modify.

| | array | $ids |

One or more message IDs to remove.

|

Return Value

| Redis|int|false |

The number of messages removed or false on failure.

|

See also

| https://redis.io/docs/latest/commands/xdel/ | |

Examples

|

$redis->xDel('stream', ['1-1', '2-1', '3-1']);

|

at line 4861 Relay|array|false xdelex(string $key, array $ids, string|null $mode = null)

Remove one or more IDs from a stream with extended options.

Parameters

| string | $key |

The stream to modify.

| | array | $ids |

One or more message IDs to remove.

| | string|null | $mode |

An optional mode argument. Valid modes are as follows: KEEPREF | DELREF | ACKED

|

Return Value

| Relay|array|false |

An array corresponding to IDs. 1 if the id was deleted and 0 if not.

|

See also

| https://redis.io/docs/latest/commands/xdelex/ | |

Examples

|

$redis->xadd('s', '*', ['field' => 'value1']);
$redis->xdelex('s', ['1-0'], 'KEEPREF');

|

at line 4902 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)

XGROUP

Perform various operation on consumer groups for a particular Redis STREAM. What the command does is primarily based on which operation is passed.

Parameters

| string | $operation |

The subcommand you intend to execute. Valid options are as follows 'HELP' - Redis will return information about the command Requires: none 'CREATE' - Create a consumer group. Requires: Key, group, consumer. 'SETID' - Set the ID of an existing consumer group for the stream. Requires: Key, group, id. 'CREATECONSUMER' - Create a new consumer group for the stream. You must also pass key, group, and the consumer name you wish to create. Requires: Key, group, consumer. 'DELCONSUMER' - Delete a consumer from group attached to the stream. Requires: Key, group, consumer. 'DESTROY' - Delete a consumer group from a stream. Requires: Key, group.

| | string|null | $key |

The STREAM we're operating on.

| | string|null | $group |

The consumer group we want to create/modify/delete.

| | string|null | $id_or_consumer |

The STREAM id (e.g. '$') or consumer group. See the operation section for information about which to send.

| | bool | $mkstream |

This flag may be sent in combination with the 'CREATE' operation, and cause Redis to also create the STREAM if it doesn't currently exist.

| | int | $entries_read |

Allows you to set Redis' 'entries-read' STREAM value. This argument is only relevant to the 'CREATE' and 'SETID' operations. Note: Requires Redis >= 7.0.0.

|

Return Value

| mixed |

This command return various results depending on the operation performed.

|

See also

| https://redis.io/docs/latest/commands/xgroup/ | |

Examples

|

$redis->xgroup('CREATE', 'mystream', 'workers', '$');

|

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

Retrieve information about a stream key.

Parameters

| string | $operation |

The specific info operation to perform.

| | string|null | $arg1 |

The first argument (depends on operation)

| | string|null | $arg2 |

The second argument

| | int | $count |

The COUNT argument to XINFO STREAM

|

Return Value

| mixed |

This command can return different things depending on the operation being called.

|

See also

| https://redis.io/docs/latest/commands/xinfo/ | |

Examples

|

$redis->xInfo('CONSUMERS', 'stream');

| |

$redis->xInfo('GROUPS', 'stream');

| |

$redis->xInfo('STREAM', 'stream');

|

at line 4935 Redis|int|false xlen(string $key)

Get the number of messages in a Redis STREAM key.

Parameters

| string | $key |

The Stream to check.

|

Return Value

| Redis|int|false |

The number of messages or false on failure.

|

See also

| https://redis.io/docs/latest/commands/xlen/ | |

Examples

|

$redis->xLen('stream');

|

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

Interact with stream messages that have been consumed by a consumer group but not yet acknowledged with XACK.

Parameters

| string | $key |

The stream to inspect.

| | string | $group |

The user group we want to see pending messages from.

| | string|null | $start |

The minimum ID to consider.

| | string|null | $end |

The maximum ID to consider.

| | int | $count |

Optional maximum number of messages to return.

| | string|null | $consumer |

If provided, limit the returned messages to a specific consumer.

|

Return Value

| Redis|array|false |

The pending messages belonging to the stream or false on failure.

|

See also

| https://redis.io/docs/latest/commands/xpending/ | | | https://redis.io/docs/latest/commands/xreadgroup/ | |

Examples

|

$redis->xpending('mystream', 'workers', '-', '+', 10);

|

at line 4974 Redis|array|bool xrange(string $key, string $start, string $end, int $count = -1)

Get a range of entries from a STREAM key.

Parameters

| string | $key |

The stream key name to list.

| | string | $start |

The minimum ID to return.

| | string | $end |

The maximum ID to return.

| | int | $count |

An optional maximum number of entries to return.

|

Return Value

| Redis|array|bool |

The entries in the stream within the requested range or false on failure.

|

See also

| https://redis.io/docs/latest/commands/xrange/ | |

Examples

|

$redis->xRange('stream', '0-1', '0-2');

| |

$redis->xRange('stream', '-', '+');

|

at line 4998 Redis|array|bool xread(array $streams, int $count = -1, int $block = -1)

Consume one or more unconsumed elements in one or more streams.

Parameters

| array | $streams |

An associative array with stream name keys and minimum id values.

| | int | $count |

An optional limit to how many entries are returned per stream

| | int | $block |

An optional maximum number of milliseconds to block the caller if no data is available on any of the provided streams.

|

Return Value

| Redis|array|bool |

An array of read elements or false if there aren't any.

|

See also

| https://redis.io/docs/latest/commands/xread/ | |

Examples

|

$redis->xAdd('s03', '3-1', ['title' => 'The Search, Part I']);
$redis->xAdd('s03', '3-2', ['title' => 'The Search, Part II']);
$redis->xAdd('s03', '3-3', ['title' => 'The House Of Quark']);
$redis->xAdd('s04', '4-1', ['title' => 'The Way of the Warrior']);
$redis->xAdd('s04', '4-3', ['title' => 'The Visitor']);
$redis->xAdd('s04', '4-4', ['title' => 'Hippocratic Oath']);

$redis->xRead(['s03' => '3-2', 's04' => '4-1']);

|

at line 5033 Redis|array|bool xreadgroup(string $group, string $consumer, array $streams, int $count = 1, int $block = 1)

Read one or more messages using a consumer group.

Parameters

| string | $group |

The consumer group to use.

| | string | $consumer |

The consumer to use.

| | array | $streams |

An array of stream names and message IDs

| | int | $count |

Optional maximum number of messages to return

| | int | $block |

How long to block if there are no messages available.

|

Return Value

| Redis|array|bool |

Zero or more unread messages or false on failure.

|

See also

| https://redis.io/docs/latest/commands/xreadgroup/ | |

Examples

|

$redis->xGroup('CREATE', 'episodes', 'ds9', '0-0', true);

$redis->xAdd('episodes', '1-1', ['title' => 'Emissary: Part 1']);
$redis->xAdd('episodes', '1-2', ['title' => 'A Man Alone']);

$messages = $redis->xReadGroup('ds9', 'sisko', ['episodes' => '>']);

// After having read the two messages, add another
$redis->xAdd('episodes', '1-3', ['title' => 'Emissary: Part 2']);

// Acknowledge the first two read messages
foreach ($messages as $stream => $stream_messages) {
    $ids = array_keys($stream_messages);
    $redis->xAck('stream', 'ds9', $ids);
}

// We can now pick up where we left off, and will only get the final message
$msgs = $redis->xReadGroup('ds9', 'sisko', ['episodes' => '>']);

|

at line 5051 Redis|array|bool xrevrange(string $key, string $end, string $start, int $count = -1)

Get a range of entries from a STREAM key in reverse chronological order.

Parameters

| string | $key |

The stream key to query.

| | string | $end |

The maximum message ID to include.

| | string | $start |

The minimum message ID to include.

| | int | $count |

An optional maximum number of messages to include.

|

Return Value

| Redis|array|bool |

The entries within the requested range, from newest to oldest.

|

See also

| https://redis.io/docs/latest/commands/xrevrange/ | | | https://redis.io/docs/latest/commands/xrange/ | |

Examples

|

$redis->xRevRange('stream', '0-2', '0-1');

| |

$redis->xRevRange('stream', '+', '-');

|

at line 5069 Redis|int|false vadd(string $key, array $values, mixed $element, array|null $options = null)

Add to a vector set

Parameters

| string | $key |

The vector set to add to.

| | array | $values |

A non-empty array of floating point values

| | mixed | $element |

The element to add to the vector set.

| | array|null | $options |

An optional options array

|

Return Value

| Redis|int|false |

One if the key was added zero if not.

|

See also

| https://redis.io/docs/latest/commands/vadd/ | |

Examples

|

$redis->vadd('embeddings', [0.12, 0.04, 0.88], 'doc:1');

|

at line 5091 Redis|array|false vsim(string $key, mixed $member, array|null $options = null)

Query similarity of a vector by element or scores

Parameters

| string | $key |

The vector set to query.

| | mixed | $member |

Either an element or array of scores. PhpRedis will attempt to infer which it is, but since there can be some ambiguity here due to serialization you can also explicitly specify ELE, VALUES, or FP32 in the options array.

| | array|null | $options |

An optional options array

|

Return Value

| Redis|array|false |

An array of elements and their similarity scores, or false on failure.

|

See also

| https://redis.io/docs/latest/commands/vsim/ | |

Examples

|

$redis->vsim('embeddings', 'doc:1', ['COUNT' => 3]);

|

at line 5106 Redis|int|false vcard(string $key)

Get the length of a vector set

Parameters

| string | $key |

The vector set to query.

|

Return Value

| Redis|int|false |

The number of elements in the vector set or false on failure.

|

See also

| https://redis.io/docs/latest/commands/vcard/ | |

Examples

|

$redis->vcard('embeddings');

|

at line 5121 Redis|int|false vdim(string $key)

Get the dimensions of a vector set

Parameters

| string | $key |

The vector set to query.

|

Return Value

| Redis|int|false |

The number of dimensions in the vector set or false on failure.

|

See also

| https://redis.io/docs/latest/commands/vdim/ | |

Examples

|

$redis->vdim('embeddings');

|

at line 5136 Redis|array|false vinfo(string $key)

Get various bits of information about a vector set

Parameters

| string | $key |

The vector set to query.

|

Return Value

| Redis|array|false |

An array of information about the vector set or false on failure.

|

See also

| https://redis.io/docs/latest/commands/vinfo/ | |

Examples

|

$redis->vinfo('embeddings');

|

at line 5152 Redis|bool vismember(string $key, mixed $member)

Check if an element is a member of a vectorset

Parameters

| string | $key |

The vector set to query.

| | mixed | $member |

The member to check for.

|

Return Value

| Redis|bool |

true if the member exists, false if it does not.

|

See also

| https://redis.io/docs/latest/commands/vismember/ | |

Examples

|

$redis->vismember('embeddings', 'doc:1');

|

at line 5169 Redis|array|false vemb(string $key, mixed $member, bool $raw = false)

Get the embeddings for a specific member

Parameters

| string | $key |

The vector set to query.

| | mixed | $member |

The member to query.

| | bool | $raw |

If set to true, the raw embeddings will be returned

|

Return Value

| Redis|array|false |

An array of embeddings for the member or false on failure.

|

See also

| https://redis.io/docs/latest/commands/vemb/ | |

Examples

|

$redis->vemb('embeddings', 'doc:1');

|

at line 5183 Redis|array|string|false vrandmember(string $key, int $count = 0)

Get one or more random members from a vector set

Parameters

| string | $key |

The vector set to query.

| | int | $count |

The number of random members to return.

|

Return Value

| Redis|array|string|false | |

See also

| https://redis.io/docs/latest/commands/vrandmember/ | |

Examples

|

$redis->vrandmember('embeddings', 2);

|

at line 5201 Redis|array|false vrange(string $key, string $min, string $max, int $count = -1)

Retreive a lexographical range of elements from a vector set

Parameters

| string | $key |

The vector set to query.

| | string | $min |

The minimum element to return.

| | string | $max |

The maximum element to return.

| | int | $count |

An optional maximum number of elements to return.

|

Return Value

| Redis|array|false |

An array of elements in the requested range or false on failure.

|

See also

| https://redis.io/docs/latest/commands/vrange/ | |

Examples

|

$redis->vrange('embeddings', '-', '+', 5);

|

at line 5217 Redis|int|false vrem(string $key, mixed $member)

Remove an element from a vector set

Parameters

| string | $key |

The vector set to remove from.

| | mixed | $member |

The member to remove.

|

Return Value

| Redis|int|false |

1 if the member was removed, 0 if it was not.

|

See also

| https://redis.io/docs/latest/commands/vrem/ | |

Examples

|

$redis->vrem('embeddings', 'doc:1');

|

at line 5236 Redis|int|false vsetattr(string $key, mixed $member, array|string $attributes)

Set the attributes of a vector set element

Parameters

| string | $key |

The vector set to modify.

| | mixed | $member |

The member to modify.

| | array|string | $attributes |

The attributes to set. This should either be a json encoded string or an array which will be json encoded.

|

Return Value

| Redis|int|false |

1 if the attributes were set, 0 if they were not.

|

See also

| https://redis.io/docs/latest/commands/vsetattr/ | |

Examples

|

$redis->vsetattr('embeddings', 'doc:1', ['topic' => 'tech']);

|

at line 5253 Redis|array|string|false vgetattr(string $key, mixed $member, bool $decode = true)

Get the attributes of a vector set element

Parameters

| string | $key |

The vector set to query.

| | mixed | $member |

The member to query.

| | bool | $decode |

Whether to automatically deserialize any returned json.

|

Return Value

| Redis|array|string|false |

An array of attributes for the member or false on failure.

|

See also

| https://redis.io/docs/latest/commands/vgetattr/ | |

Examples

|

$redis->vgetattr('embeddings', 'doc:1');

|

Get any adajcent values for a member of a vector set.

Parameters

| string | $key |

The vector set to query.

| | mixed | $member |

The member to query.

| | bool | $withscores |

If set to true, the scores of the adjacent values will be returned.

|

Return Value

| Redis|array|false |

An array of adjacent values and their scores, or false on failure.

|

See also

| https://redis.io/docs/latest/commands/vlinks/ | |

Examples

|

$redis->vlinks('embeddings', 'doc:1', true);

|

at line 5292 Redis|int|false xtrim(string $key, string $threshold, bool $approx = false, bool $minid = false, int $limit = -1)

Truncate a STREAM key in various ways.

Parameters

| string | $key |

The STREAM key to trim.

| | string | $threshold |

This can either be a maximum length, or a minimum id. MAXLEN - An integer describing the maximum desired length of the stream after the command. MINID - An ID that will become the new minimum ID in the stream, as Redis will trim all messages older than this ID.

| | bool | $approx |

Whether redis is allowed to do an approximate trimming of the stream. This is more efficient for Redis given how streams are stored internally.

| | bool | $minid |

When set to true, users should pass a minimum ID to the $threshold argument.

| | int | $limit |

An optional upper bound on how many entries to trim during the command.

|

Return Value

| Redis|int|false |

The number of entries deleted from the stream.

|

See also

| https://redis.io/docs/latest/commands/xtrim/ | |

Examples

|

$redis->xTrim('stream', 3);

| |

$redis->xTrim('stream', '2-1', false, true);

|

at line 5333 Redis|int|float|false zAdd(string $key, array|float $score_or_options, mixed ...$more_scores_and_mems)

Add one or more elements and scores to a Redis sorted set.

Parameters

| string | $key |

The sorted set in question.

| | array|float | $score_or_options |

Either the score for the first element, or an array of options.

$options = [
     'NX', # Only update elements that already exist
     'NX', # Only add new elements but don't update existing ones.

     'LT' # Only update existing elements if the new score is
                 # less than the existing one.
     'GT' # Only update existing elements if the new score is
                 # greater than the existing one.

     'CH' # Instead of returning the number of elements added,
                 # Redis will return the number Of elements that were
                 # changed in the operation.

     'INCR' # Instead of setting each element to the provide score,
                 # increment the element by the
                 # provided score, much like ZINCRBY. When this option
                 # is passed, you may only send a single score and member.
 ];

Note: 'GX', 'LT', and 'NX' cannot be passed together, and PhpRedis will send whichever one is last in the options array.

| | mixed | ...$more_scores_and_mems |

A variadic number of additional scores and members.

|

Return Value

| Redis|int|float|false |

The return value varies depending on the options passed.

Following is information about the options that may be passed as the second argument:

|

See also

| https://redis.io/docs/latest/commands/zadd/ | |

Examples

|

$redis->zadd('zs', 1, 'first', 2, 'second', 3, 'third');
$redis->zAdd('zs', ['XX'], 8, 'second', 99, 'new-element');

|

at line 5346 Redis|int|false zCard(string $key)

Return the number of elements in a sorted set.

Parameters

| string | $key |

The sorted set to retrieve cardinality from.

|

Return Value

| Redis|int|false |

The number of elements in the set or false on failure

|

See also

| https://redis.io/docs/latest/commands/zcard/ | |

Examples

|

$redis->zCard('zs');

|

at line 5365 Redis|int|false zCount(string $key, int|string $start, int|string $end)

Count the number of members in a sorted set with scores inside a provided range.

Parameters

| string | $key |

The sorted set to check.

| | int|string | $start |

The minimum score to include in the count

| | int|string | $end |

The maximum score to include in the count

NOTE: In addition to a floating point score you may pass the special values of '-inf' and '+inf' meaning negative and positive infinity, respectively.

|

Return Value

| Redis|int|false | |

See also

| https://redis.io/docs/latest/commands/zcount/ | |

Examples

|

$redis->zCount('fruit-rankings', '0', '+inf');
$redis->zCount('fruit-rankings', 50, 60);
$redis->zCount('fruit-rankings', '-inf', 0);

|

at line 5381 Redis|float|false zIncrBy(string $key, float $value, mixed $member)

Create or increment the score of a member in a Redis sorted set

Parameters

| string | $key |

The sorted set in question.

| | float | $value |

How much to increment the score.

| | mixed | $member | |

Return Value

| Redis|float|false |

The new score of the member or false on failure.

|

See also

| https://redis.io/docs/latest/commands/zincrby/ | |

Examples

|

$redis->zIncrBy('zs', 5.0, 'bananas');
$redis->zIncrBy('zs', 2.0, 'eggplants');

|

at line 5399 Redis|int|false zLexCount(string $key, string $min, string $max)

Count the number of elements in a sorted set whose members fall within the provided lexographical range.

Parameters

| string | $key |

The sorted set to check.

| | string | $min |

The minimum matching lexographical string

| | string | $max |

The maximum matching lexographical string

|

Return Value

| Redis|int|false |

The number of members that fall within the range or false on failure.

|

See also

| https://redis.io/docs/latest/commands/zlexcount/ | |

Examples

|

$redis->zAdd('captains', 0, 'Janeway', 0, 'Kirk', 0, 'Picard', 0, 'Sisko', 0, 'Archer');
$redis->zLexCount('captains', '[A', '[S');

|

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

Retrieve the score of one or more members in a sorted set.

Parameters

| string | $key |

The sorted set

| | mixed | $member |

The first member to return the score from

| | mixed | ...$other_members |

One or more additional members to return the scores of.

|

Return Value

| Redis|array|false |

An array of the scores of the requested elements.

|

See also

| https://redis.io/docs/latest/commands/zmscore/ | |

Examples

|

$redis->zAdd('zs', 0, 'zero', 1, 'one', 2, 'two', 3, 'three');

$redis->zMScore('zs', 'zero', 'two');
$redis->zMScore('zs', 'one', 'not-a-member');

|

at line 5436 Redis|array|false zPopMax(string $key, int|null $count = null)

Pop one or more of the highest scoring elements from a sorted set.

Parameters

| string | $key |

The sorted set to pop elements from.

| | int|null | $count |

An optional count of elements to pop.

|

Return Value

| Redis|array|false |

All of the popped elements with scores or false on failure

|

See also

| https://redis.io/docs/latest/commands/zpopmax/ | |

Examples

|

$redis->zAdd('zs', 0, 'zero', 1, 'one', 2, 'two', 3, 'three');

$redis->zPopMax('zs');
$redis->zPopMax('zs', 2);.

|

at line 5454 Redis|array|false zPopMin(string $key, int|null $count = null)

Pop one or more of the lowest scoring elements from a sorted set.

Parameters

| string | $key |

The sorted set to pop elements from.

| | int|null | $count |

An optional count of elements to pop.

|

Return Value

| Redis|array|false |

The popped elements with their scores or false on failure.

|

See also

| https://redis.io/docs/latest/commands/zpopmin/ | |

Examples

|

$redis->zAdd('zs', 0, 'zero', 1, 'one', 2, 'two', 3, 'three');

$redis->zPopMin('zs');
$redis->zPopMin('zs', 2);

|

at line 5490 Redis|array|false zRange(string $key, string|int $start, string|int $end, array|bool|null $options = null)

Retrieve a range of elements of a sorted set between a start and end point.

How the command works in particular is greatly affected by the options that are passed in.

Parameters

| string | $key |

The sorted set in question.

| | string|int | $start |

The starting index we want to return.

| | string|int | $end |

The final index we want to return.

| | array|bool|null | $options |

This value may either be an array of options to pass to the command, or for historical purposes a boolean which controls just the 'WITHSCORES' option.

$options = [
    'WITHSCORES' => true, # Return both scores and members.
    'LIMIT' => [10, 10], # Start at offset 10 and return 10 elements.
    'REV' # Return the elements in reverse order
    'BYSCORE', # Treat `start` and `end` as scores instead
    'BYLEX' # Treat `start` and `end` as lexicographical values.
];

Note: BYLEX and BYSCORE are mutually exclusive.

|

Return Value

| Redis|array|false |

An array with matching elements or false on failure.

|

See also

| https://redis.io/docs/latest/commands/zrange/ | |

Examples

|

$redis->zRange('zset', 0, -1);
$redis->zRange('zset', '-inf', 'inf', ['byscore']);

|

at line 5512 Redis|array|false zRangeByLex(string $key, string $min, string $max, int $offset = -1, int $count = -1)

Retrieve a range of elements from a sorted set by legographical range.

Parameters

| string | $key |

The sorted set to retrieve elements from

| | string | $min |

The minimum legographical value to return

| | string | $max |

The maximum legographical value to return

| | int | $offset |

An optional offset within the matching values to return

| | int | $count |

An optional count to limit the replies to (used in conjunction with offset)

|

Return Value

| Redis|array|false |

An array of matching elements or false on failure.

|

See also

| https://redis.io/docs/latest/commands/zrangebylex/ | |

Examples

|

$redis = new Redis(['host' => 'localhost']);
$redis->zAdd('captains', 0, 'Janeway', 0, 'Kirk', 0, 'Picard', 0, 'Sisko', 0, 'Archer');

$redis->zRangeByLex('captains', '[A', '[S');
$redis->zRangeByLex('captains', '[A', '[S', 2, 2);

|

at line 5534 Redis|array|false zRangeByScore(string $key, string $start, string $end, array $options = [])

Retrieve a range of members from a sorted set by their score.

Parameters

| string | $key |

The sorted set to query.

| | string | $start |

The minimum score of elements that Redis should return.

| | string | $end |

The maximum score of elements that Redis should return.

| | array | $options |

Options that change how Redis will execute the command.

OPTION TYPE MEANING 'WITHSCORES' bool Whether to also return scores. 'LIMIT' [offset, count] Limit the reply to a subset of elements.

|

Return Value

| Redis|array|false |

The number of matching elements or false on failure.

|

See also

| https://redis.io/docs/latest/commands/zrangebyscore/ | |

Examples

|

$redis->zRangeByScore('zs', 20, 30, ['WITHSCORES' => true]);
$redis->zRangeByScore('zs', 20, 30, ['WITHSCORES' => true, 'LIMIT' => [5, 5]]);

|

at line 5558 Redis|int|false zrangestore(string $dstkey, string $srckey, string $start, string $end, array|bool|null $options = null)

This command is similar to ZRANGE except that instead of returning the values directly it will store them in a destination key provided by the user

Parameters

| string | $dstkey |

The key to store the resulting element(s)

| | string | $srckey |

The source key with element(s) to retrieve

| | string | $start |

The starting index to store

| | string | $end |

The ending index to store

| | array|bool|null | $options |

Our options array that controls how the command will function.

|

Return Value

| Redis|int|false |

The number of elements stored in $dstkey or false on failure.

|

See also

| https://redis.io/docs/latest/commands/zrange/ | | | Redis::zRange | |

Examples

|

$redis->zrangestore('recent:leaders', 'leaders', '0', '9');

|

at line 5577 Redis|string|array zRandMember(string $key, array|null $options = null)

Retrieve one or more random members from a Redis sorted set.

Parameters

| string | $key |

The sorted set to pull random members from.

| | array|null | $options |

One or more options that determine exactly how the command operates. OPTION TYPE MEANING 'COUNT' int The number of random members to return. 'WITHSCORES' bool Whether to return scores and members instead of

|

Return Value

| Redis|string|array |

One or more random elements.

|

See also

| https://redis.io/docs/latest/commands/zrandmember/ | |

Examples

|

$redis->zRandMember('zs', ['COUNT' => 2, 'WITHSCORES' => true]);

|

at line 5592 Redis|int|false zRank(string $key, mixed $member)

Get the rank of a member of a sorted set, by score.

Parameters

| string | $key |

The sorted set to check.

| | mixed | $member |

The member to test.

|

Return Value

| Redis|int|false |

The rank of the requested member.

|

See also

| https://redis.io/docs/latest/commands/zrank/ | |

Examples

|

$redis->zRank('zs', 'zero');
$redis->zRank('zs', 'three');

|

at line 5608 Redis|int|false zRem(mixed $key, mixed $member, mixed ...$other_members)

Remove one or more members from a Redis sorted set.

Parameters

| mixed | $key |

The sorted set in question.

| | mixed | $member |

The first member to remove.

| | mixed | ...$other_members |

One or more members to remove passed in a variadic fashion.

|

Return Value

| Redis|int|false |

The number of members that were actually removed or false on failure.

|

See also

| https://redis.io/docs/latest/commands/zrem/ | |

Examples

|

$redis->zRem('zs', 'mem:0', 'mem:1', 'mem:2', 'mem:6', 'mem:7', 'mem:8', 'mem:9');

|

at line 5626 Redis|int|false zRemRangeByLex(string $key, string $min, string $max)

Remove zero or more elements from a Redis sorted set by legographical range.

Parameters

| string | $key |

The sorted set to remove elements from.

| | string | $min |

The start of the lexographical range to remove.

| | string | $max |

The end of the lexographical range to remove

|

Return Value

| Redis|int|false |

The number of elements removed from the set or false on failure.

|

See also

| https://redis.io/docs/latest/commands/zremrangebylex/ | | | \Redis::zrangebylex() | |

Examples

|

$redis->zRemRangeByLex('zs', '[a', '(b');
$redis->zRemRangeByLex('zs', '(banana', '(eggplant');

|

at line 5642 Redis|int|false zRemRangeByRank(string $key, int $start, int $end)

Remove one or more members of a sorted set by their rank.

Parameters

| string | $key |

The sorted set where we want to remove members.

| | int | $start |

The rank when we want to start removing members

| | int | $end |

The rank we want to stop removing membersk.

|

Return Value

| Redis|int|false |

The number of members removed from the set or false on failure.

|

See also

| https://redis.io/docs/latest/commands/zremrangebyrank/ | |

Examples

|

$redis->zRemRangeByRank('zs', 0, 3);

|

at line 5659 Redis|int|false zRemRangeByScore(string $key, string $start, string $end)

Remove one or more members of a sorted set by their score.

Parameters

| string | $key |

The sorted set where we want to remove members.

| | string | $start |

The lowest score to remove.

| | string | $end |

The highest score to remove.

|

Return Value

| Redis|int|false |

The number of members removed from the set or false on failure.

|

See also

| https://redis.io/docs/latest/commands/zremrangebyrank/ | |

Examples

|

$redis->zAdd('zs', 2, 'two', 4, 'four', 6, 'six');
$redis->zRemRangeByScore('zs', 2, 4);

|

at line 5681 Redis|array|false zRevRange(string $key, int $start, int $end, mixed $scores = null)

List the members of a Redis sorted set in reverse order

Parameters

| string | $key |

The sorted set in question.

| | int | $start |

The index to start listing elements

| | int | $end |

The index to stop listing elements.

| | mixed | $scores |

Whether or not Redis should also return each members score. See the example below demonstrating how it may be used.

|

Return Value

| Redis|array|false |

The members (and possibly scores) of the matching elements or false on failure.

|

See also

| https://redis.io/docs/latest/commands/zrevrange/ | |

Examples

|

$redis->zRevRange('zs', 0, -1);
$redis->zRevRange('zs', 2, 3);
$redis->zRevRange('zs', 0, -1, true);
$redis->zRevRange('zs', 0, -1, ['withscores' => true]);

|

at line 5701 Redis|array|false zRevRangeByLex(string $key, string $max, string $min, int $offset = -1, int $count = -1)

List members of a Redis sorted set within a legographical range, in reverse order.

Parameters

| string | $key |

The sorted set to list

| | string | $max |

The maximum legographical element to include in the result.

| | string | $min |

The minimum lexographical element to include in the result.

| | int | $offset |

An option offset within the matching elements to start at.

| | int | $count |

An optional count to limit the replies to.

|

Return Value

| Redis|array|false |

The matching members or false on failure.

|

See also

| https://redis.io/docs/latest/commands/zrevrangebylex/ | | | \Redis::zrangebylex() | |

Examples

|

$redis->zRevRangeByLex('captains', '[Q', '[J');
$redis->zRevRangeByLex('captains', '[Q', '[J', 1, 2);

|

at line 5736 Redis|array|false zRevRangeByScore(string $key, string $max, string $min, array|bool $options = [])

List elements from a Redis sorted set by score, highest to lowest

Parameters

| string | $key |

The sorted set to query.

| | string | $max |

The highest score to include in the results.

| | string | $min |

The lowest score to include in the results.

| | array|bool | $options |

An options array that modifies how the command executes.

$options = [
    'WITHSCORES' => true|false # Whether or not to return scores
    'LIMIT' => [offset, count] # Return a subset of the matching members
];

NOTE: For legacy reason, you may also simply pass true for the options argument, to mean WITHSCORES.

|

Return Value

| Redis|array|false |

The matching members in reverse order of score or false on failure.

|

See also

| https://redis.io/docs/latest/commands/zrevrangebyscore/ | |

Examples

|

$redis->zadd('oldest-people', 122.4493, 'Jeanne Calment', 119.2932, 'Kane Tanaka',
                              119.2658, 'Sarah Knauss', 118.7205, 'Lucile Randon',
                              117.7123, 'Nabi Tajima', 117.6301, 'Marie-Louise Meilleur',
                              117.5178, 'Violet Brown', 117.3753, 'Emma Morano',
                              117.2219, 'Chiyo Miyako', 117.0740, 'Misao Okawa');

$redis->zRevRangeByScore('oldest-people', 122, 119);
$redis->zRevRangeByScore('oldest-people', 'inf', 118);
$redis->zRevRangeByScore('oldest-people', '117.5', '-inf', ['LIMIT' => [0, 1]]);

|

at line 5754 Redis|int|false zRevRank(string $key, mixed $member)

Retrieve a member of a sorted set by reverse rank.

Parameters

| string | $key |

The sorted set to query.

| | mixed | $member |

The member to look up.

|

Return Value

| Redis|int|false |

The reverse rank (the rank if counted high to low) of the member or false on failure.

|

See also

| https://redis.io/docs/latest/commands/zrevrank/ | |

Examples

|

$redis->zAdd('ds9-characters', 10, 'Sisko', 9, 'Garak', 8, 'Dax', 7, 'Odo');

$redis->zrevrank('ds9-characters', 'Sisko');
$redis->zrevrank('ds9-characters', 'Garak');

|

at line 5770 Redis|float|false zScore(string $key, mixed $member)

Get the score of a member of a sorted set.

Parameters

| string | $key |

The sorted set to query.

| | mixed | $member |

The member we wish to query.

|

Return Value

| Redis|float|false |

The score of the requested element or false if it is not found.

|

See also

| https://redis.io/docs/latest/commands/zscore/ | |

Examples

|

$redis->zAdd('telescopes', 11.9, 'LBT', 10.4, 'GTC', 10, 'HET');
$redis->zScore('telescopes', 'LBT');

|

at line 5791 Redis|array|false zdiff(array $keys, array|null $options = null)

Given one or more sorted set key names, return every element that is in the first set but not any of the others.

Parameters

| array | $keys |

One or more sorted sets.

| | array|null | $options |

An array which can contain ['WITHSCORES' => true] if you want Redis to return members and scores.

|

Return Value

| Redis|array|false |

An array of members or false on failure.

|

See also

| https://redis.io/docs/latest/commands/zdiff/ | |

Examples

|

$redis->zAdd('primes', 1, 'one', 3, 'three', 5, 'five');
$redis->zAdd('evens', 2, 'two', 4, 'four');
$redis->zAdd('mod3', 3, 'three', 6, 'six');

$redis->zDiff(['primes', 'evens', 'mod3']);

|

at line 5811 Redis|int|false zdiffstore(string $dst, array $keys)

Store the difference of one or more sorted sets in a destination sorted set.

See Redis::zdiff for a more detailed description of how the diff operation works.

Parameters

| string | $dst |

The destination set name.

| | array | $keys |

One or more source key names

|

Return Value

| Redis|int|false |

The number of elements stored in the destination set or false on failure.

|

See also

| https://redis.io/docs/latest/commands/zdiff/ | | | Redis::zdiff | |

Examples

|

$redis->zdiffstore('only:new', ['all:users', 'inactive:users']);

|

at line 5834 Redis|array|false zinter(array $keys, array|null $weights = null, array|null $options = null)

Compute the intersection of one or more sorted sets and return the members

Parameters

| array | $keys |

One or more sorted sets.

| | array|null | $weights |

An optional array of weights to be applied to each set when performing the intersection.

| | array|null | $options |

Options for how Redis should combine duplicate elements when performing the intersection. See Redis::zunion() for details.

|

Return Value

| Redis|array|false |

All of the members that exist in every set.

|

See also

| https://redis.io/docs/latest/commands/zinter/ | |

Examples

|

$redis->zAdd('TNG', 2, 'Worf', 2.5, 'Data', 4.0, 'Picard');
$redis->zAdd('DS9', 2.5, 'Worf', 3.0, 'Kira', 4.0, 'Sisko');

$redis->zInter(['TNG', 'DS9']);
$redis->zInter(['TNG', 'DS9'], NULL, ['withscores' => true]);
$redis->zInter(['TNG', 'DS9'], NULL, ['withscores' => true, 'aggregate' => 'max']);

|

at line 5857 Redis|int|false zintercard(array $keys, int $limit = -1)

Similar to ZINTER but instead of returning the intersected values, this command returns the cardinality of the intersected set.

Parameters

| array | $keys |

One or more sorted set key names.

| | int | $limit |

An optional upper bound on the returned cardinality. If set to a value greater than zero, Redis will stop processing the intersection once the resulting cardinality reaches this limit.

|

Return Value

| Redis|int|false |

The cardinality of the intersection or false on failure.

|

See also

| https://redis.io/docs/latest/commands/zintercard/ | | | https://redis.io/docs/latest/commands/zinter/ | | | Redis::zinter | |

Examples

|

$redis->zAdd('zs1', 1, 'one', 2, 'two', 3, 'three', 4, 'four');
$redis->zAdd('zs2', 2, 'two', 4, 'four');

$redis->zInterCard(['zs1', 'zs2']);

|

at line 5883 Redis|int|false zinterstore(string $dst, array $keys, array|null $weights = null, string|null $aggregate = null)

Compute the intersection of one or more sorted sets storing the result in a new sorted set.

Parameters

| string | $dst |

The destination sorted set to store the intersected values.

| | array | $keys |

One or more sorted set key names.

| | array|null | $weights |

An optional array of floats to weight each passed input set.

| | string|null | $aggregate |

An optional aggregation method to use. 'SUM' - Store sum of all intersected members (this is the default). 'MIN' - Store minimum value for each intersected member. 'MAX' - Store maximum value for each intersected member.

|

Return Value

| Redis|int|false |

The total number of members writtern to the destination set or false on failure.

|

See also

| https://redis.io/docs/latest/commands/zinterstore/ | | | https://redis.io/docs/latest/commands/zinter/ | |

Examples

|

$redis->zAdd('zs1', 3, 'apples', 2, 'pears');
$redis->zAdd('zs2', 4, 'pears', 3, 'bananas');
$redis->zAdd('zs3', 2, 'figs', 3, 'pears');

$redis->zInterStore('fruit-sum', ['zs1', 'zs2', 'zs3']);
$redis->zInterStore('fruit-max', ['zs1', 'zs2', 'zs3'], NULL, 'MAX');

|

at line 5915 Redis|array|false zscan(string $key, null|int|string $iterator, string|null $pattern = null, int $count = 0)

Scan the members of a sorted set incrementally, using a cursor

Parameters

| string | $key |

The sorted set to scan.

| | null|int|string | $iterator |

A reference to an iterator that should be initialized to NULL initially, that will be updated after each subsequent call to ZSCAN. Once the iterator has returned to zero the scan is complete

| | string|null | $pattern |

An optional glob-style pattern that limits which members are returned during the scanning process.

| | int | $count |

A hint for Redis that tells it how many elements it should test before returning from the call. The higher the more work Redis may do in any one given call to ZSCAN potentially blocking for longer periods of time.

|

Return Value

| Redis|array|false |

An array of elements or false on failure.

|

See also

| https://redis.io/docs/latest/commands/zscan/ | | | https://redis.io/docs/latest/commands/scan/ | | | Redis::scan | NOTE: See Redis::scan() for detailed example code on how to call SCAN like commands. |

Examples

|

$it = null;
while ($members = $redis->zscan('leaders', $it)) {
    foreach ($members as $member => $score) {
        printf('%s => %s' . PHP_EOL, $member, $score);
    }
}

|

at line 5952 Redis|array|false zunion(array $keys, array|null $weights = null, array|null $options = null)

Retrieve the union of one or more sorted sets

Parameters

| array | $keys |

One or more sorted set key names

| | array|null | $weights |

An optional array with floating point weights used when performing the union. Note that if this argument is passed, it must contain the same number of elements as the $keys array.

| | array|null | $options |

An array that modifies how this command functions.

$options = [
    # By default when members exist in more than one set Redis will SUM
    # total score for each match. Instead, it can return the AVG, MIN,
    # or MAX value based on this option.
    'AGGREGATE' => 'sum' | 'min' | 'max'

    # Whether Redis should also return each members aggregated score.
    'WITHSCORES' => true | false
]

|

Return Value

| Redis|array|false |

The union of each sorted set or false on failure

|

See also

| https://redis.io/docs/latest/commands/zunion/ | |

Examples

|

$redis->del('store1', 'store2', 'store3');
$redis->zAdd('store1', 1, 'apples', 3, 'pears', 6, 'bananas');
$redis->zAdd('store2', 3, 'apples', 5, 'coconuts', 2, 'bananas');
$redis->zAdd('store3', 2, 'bananas', 6, 'apples', 4, 'figs');

$redis->zUnion(['store1', 'store2', 'store3'], NULL, ['withscores' => true]);
$redis->zUnion(['store1', 'store3'], [2, .5], ['withscores' => true]);
$redis->zUnion(['store1', 'store3'], [2, .5], ['withscores' => true, 'aggregate' => 'MIN']);

|

at line 5975 Redis|int|false zunionstore(string $dst, array $keys, array|null $weights = null, string|null $aggregate = null)

Perform a union on one or more Redis sets and store the result in a destination sorted set.

Parameters

| string | $dst |

The destination set to store the union.

| | array | $keys |

One or more input keys on which to perform our union.

| | array|null | $weights |

An optional weights array used to weight each input set.

| | string|null | $aggregate |

An optional modifier in how Redis will combine duplicate members. Valid: 'MIN', 'MAX', 'SUM'.

|

Return Value

| Redis|int|false |

The number of members stored in the destination set or false on failure.

|

See also

| https://redis.io/docs/latest/commands/zunionstore/ | | | Redis::zunion | |

Examples

|

$redis->zAdd('zs1', 1, 'one', 3, 'three');
$redis->zAdd('zs1', 2, 'two', 4, 'four');
$redis->zadd('zs3', 1, 'one', 7, 'five');

$redis->zUnionStore('dst', ['zs1', 'zs2', 'zs3']);

|

at line 5989 Redis|string|false digest(string $key)

Ask the server for the XXH3 digest of a given key's value

Parameters

| string | $key |

The key to retrieve the digest for.

|

Return Value

| Redis|string|false |

The XXH3 digest as a string or false on failure.

|

See also

| https://redis.io/docs/latest/commands/digest/ | |

Examples

|

$redis->digest('session:42');

|

Generated by Doctum, a API Documentation generator and fork of Sami.