Redis
class Redis (View source)
Constants
| REDIS_NOT_FOUND |
Returned by |
| REDIS_STRING |
Returned by |
| REDIS_SET |
Returned by |
| REDIS_LIST |
Returned by |
| REDIS_ZSET |
Returned by |
| REDIS_HASH |
Returned by |
| REDIS_STREAM |
Returned by |
| REDIS_VECTORSET |
Returned by |
| ATOMIC |
Returned from |
| MULTI |
Returned from |
| PIPELINE |
Returned from |
| OPT_SERIALIZER |
Used with |
| 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 |
| 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 ( |
| 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 |
| 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 |
| SCAN_RETRY |
When enabled, this option causes PhpRedis to automatically retry |
| SCAN_NORETRY |
Then enabled, this option tells PhpRedis to not retry |
| SCAN_PREFIX |
Tells PhpRedis to prefix keys returned from |
| SCAN_NOPREFIX |
Tells PhpRedis to NOT prefix keys returned from |
| 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 |
| RIGHT |
This is just the string "right" which is used with various list commands
such as |
| OPT_MAX_RETRIES |
How many times should |
| 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 |
| BACKOFF_ALGORITHM_CONSTANT |
Constant backoff - always sleep for exactly |
| BACKOFF_ALGORITHM_UNIFORM |
Uniform backoff - randomly sleep between 0 and |
| BACKOFF_ALGORITHM_EXPONENTIAL |
Exponential backoff - doubles the delay every retry (up to 2^10) before |
| 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 |
| 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
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.
No description
Compress a value with the currently configured compressor (Redis::OPT_COMPRESSION) exactly the same way PhpRedis does before sending data to Redis.
Uncompress the provided argument using the compressor configured via Redis::setOption() (Redis::OPT_COMPRESSION).
Prefix the passed argument with the currently set key prefix as set with Redis::setOption().
Serialize the provided value with the currently set serializer as set with Redis::setOption().
Unserialize the passed argument with the currently set serializer as set with Redis::setOption().
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.
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.
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.
Execute Redis ACL subcommands.
Append data to a Redis STRING key.
Authenticate a Redis connection after its been established.
Execute a save of the Redis database in the background.
Asynchronously rewrite Redis' append-only file
No description
Count the number of set bits in a Redis string.
No description
Return the position of the first bit set to 0 or 1 in a string.
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.
Pop an element off of the end of a Redis list or lists, potentially blocking up to a specified 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.
POP the maximum scoring element off of one or more sorted sets, blocking up to a specified timeout if no elements are available.
POP the minimum scoring element off of one or more sorted sets, blocking up to a specified timeout if no elements are available
POP one or more elements from one or more sorted sets, blocking up to a specified amount of time when no elements are available.
POP one or more of the highest or lowest scoring elements from one or more sorted sets.
Pop one or more elements from one or more Redis LISTs, blocking up to a specified timeout when no elements are available.
Pop one or more elements off of one or more Redis LISTs.
Reset any last error on the connection to NULL
Execute Redis CLIENT subcommands.
Closes the connection to Redis
Execute Redis COMMAND subcommands.
Execute the Redis CONFIG command in a variety of ways.
Connect to a Redis server
Make a copy of a key.
Return the number of keys in the currently selected Redis database.
No description
Decrement a Redis integer by 1 or a provided value.
Decrement a redis integer by a value
Delete one or more keys from Redis.
Delete a key conditionally based on its value or hash digest
Delete a key if it's equal to the specified value. This command is specific to Valkey >= 9.0
Discard a transaction currently in progress.
Dump Redis' internal binary representation of a key.
Have Redis repeat back an arbitrary string to the client.
Execute a LUA script on the redis server.
This is simply the read-only variant of eval, meaning the underlying script may not modify data in redis.
Execute a LUA script on the server but instead of sending the script, send the SHA1 hash of the script.
This is simply the read-only variant of evalsha, meaning the underlying script may not modify data in redis.
Execute either a MULTI or PIPELINE block and return the array of replies.
Test if one or more keys exist.
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.
Set a key to expire at an exact unix timestamp.
No description
Get the expiration of a given key as a unix timestamp
Get the expiration timestamp of a given Redis key but in milliseconds.
Invoke a function.
This is a read-only variant of the FCALL command that cannot execute commands that modify data.
Deletes every key in all Redis databases
Deletes all the keys of the currently selected database.
Functions is an API for managing code to be executed on the server.
Add one or more members to a geospacial sorted set
Get the distance between two members of a geospacially encoded sorted set.
Retrieve one or more GeoHash encoded strings for members of the set.
Return the longitude and latitude for one or more members of a geospacially encoded sorted set.
Retrieve members of a geospacially sorted set that are within a certain radius of a location.
A readonly variant of GEORADIUS that may be executed on replicas.
Similar to GEORADIUS except it uses a member as the center of the query.
This is the read-only variant of GEORADIUSBYMEMBER that can be run on replicas.
Search a geospacial sorted set for members in various ways.
Search a geospacial sorted set for members within a given area or range, storing the results into a new set.
Retrieve a string keys value.
Retrieve a value and metadata of key.
Get the authentication information on the connection, if any.
Get the bit at a given index in a string key.
Get the value of a key and optionally set it's expiration.
Get the database number PhpRedis thinks we're connected to.
Get a key from Redis and delete it in an atomic operation.
Return the host or Unix socket we are connected to.
Get the last error returned to us from Redis, if any.
Returns whether the connection is in ATOMIC, MULTI, or PIPELINE mode
Retrieve the value of a configuration setting as set by Redis::setOption()
Get the persistent connection ID, if there is one.
Get the port we are connected to. This number will be zero if we are connected to a unix socket.
Get the server name as reported by the HELLO response.
Get the server version as reported by the HELLO response.
Retrieve a substring of a string by index.
Get the longest common subsequence between two string keys.
Get the currently set read timeout on the connection.
Sets a key and returns any previously set value, if the key already existed.
Retrieve any set connection timeout
Get the number of bytes sent and received on the socket.
Reset the number of bytes sent and received on the socket.
Remove one or more fields from a hash.
Checks whether a field exists in a hash.
No description
Read every field and value from a hash.
Retrieve a value and metadata of hash field.
Increment a hash field's value by an integer
Increment a hash field by a floating point value
Retrieve all of the fields of a hash.
Get the number of fields in a hash.
Get one or more fields from a hash.
Get one or more fields of a hash while optionally setting expiration information
Set one or more fields in a hash with optional expiration information.
Get one or more fields and delete them
Add or update one or more hash fields and values
Get one or more random field from a hash.
Add or update one or more hash fields and values.
Set a hash field and value, but only if that field does not exist
Get the string length of a hash field
Get all of the values from a hash.
Set the expiration on one or more fields in a hash.
Set the expiration on one or more fields in a hash in milliseconds.
Set the expiration time on one or more fields of a hash.
Set the expiration time on one or more fields of a hash in milliseconds.
Get the TTL of one or more fields in a hash
Get the millisecond TTL of one or more fields in a hash
Get the expiration time of one or more fields in a hash
Get the expiration time in milliseconds of one or more fields in a hash
Persist one or more hash fields
Iterate over the fields and values of a hash in an incremental fashion.
Set an expiration on a key member (KeyDB only).
Set an expiration on a key membert to a specific unix timestamp (KeyDB only).
Increment a key's value, optionally by a specific amount.
Increment a key by a specific integer value
Increment a numeric key by a floating point value.
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.
Check if we are currently connected to a Redis instance.
Retrieve the length of a list.
Move an element from one list into another.
No description
Pop one or more elements off a list.
Retrieve the index of an element in a list.
Prepend one or more elements to a list.
Append one or more elements to a list.
Prepend an element to a list but only if the list exists
Append an element to a list but only if the list exists
Set a list element at an index to a specific value.
Retrieve the last time Redis' database was persisted to disk.
Get the element of a list by its index.
Retrieve elements from a list.
Remove one or more matching elements from a list.
Trim a list to a subrange of elements.
Get one or more string keys.
Proxy for the Redis MIGRATE command.
Move a key to a different database on the same redis instance.
Set one or more string keys.
Set one or more keys and values with optional expiry information.
Set one or more string keys but only if none of the key exist.
Begin a transaction.
Get encoding and other information about a key.
Connects to a Redis server creating or reusing a persistent connection.
Remove the expiration from a key.
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.
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.
Add one or more elements to a Redis HyperLogLog key
Retrieve the cardinality of a Redis HyperLogLog key.
Merge one or more source HyperLogLog sets into a destination set.
PING the redis server with an optional string argument.
Enter into pipeline mode.
No description
Set a key with an expiration time in milliseconds
Subscribe to one or more glob-style patterns
Get a keys time to live in milliseconds.
Publish a message to a pubsub channel
Interact with the Redis PubSub subsystem.
Unsubscribe from one or more channels by pattern
Pop one or more elements from the end of a list.
Return a random key from the current database
Execute any arbitrary Redis command by name.
Unconditionally rename a key from $old_name to $new_name
Renames $key_src to $key_dst but only if newkey does not exist.
Reset the state of the connection.
Restore a key by the binary payload generated by the DUMP command.
Query whether the connected instance is a primary or replica
Atomically pop an element off the end of a Redis LIST and push it to the beginning of another.
Add one or more values to a Redis SET key.
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.
Given one or more Redis SETS, this command returns all of the members from the first set that are not in any subsequent set.
This method performs the same operation as SDIFF except it stores the resulting diff values in a specified destination key.
Given one or more Redis SET keys, this command will return all of the elements that are in every one.
Compute the intersection of one or more sets and return the cardinality of the result.
Perform the intersection of one or more Redis SETs, storing the result in a destination key, rather than returning them.
Retrieve every member from a set key.
Check if one or more values are members of a set.
Pop a member from one set and push it onto another. This command will create the destination set if it does not currently exist.
Remove one or more elements from a set.
Retrieve one or more random members of a set.
Returns the union of one or more Redis SET keys.
Perform a union of one or more Redis SET keys and store the result in a new set
Persist the Redis database to disk. This command will block the server until the save is completed. For a nonblocking alternative, see Redis::bgsave().
Incrementally scan the Redis keyspace, with optional pattern and type matching.
Retrieve the number of members in a Redis set.
An administrative command used to interact with LUA scripts stored on the server.
Select a specific Redis database.
Create or set a Redis STRING key to a value.
Set a specific bit in a Redis string to zero or one
Update or append to a Redis string at a specific starting index
Set a configurable option on the Redis object.
Set a Redis STRING key with a specific expiration in seconds.
Set a key to a value, but only if that key does not already exist.
Check whether a given value is the member of a Redis SET.
Turn a redis instance into a replica of another or promote a replica to a primary.
Used to turn a Redis instance into a replica of another, or to remove replica status promoting the instance to a primary.
Update one or more keys last modified metadata.
Interact with Redis' slowlog functionality in various ways, depending on the value of 'operation'.
Sort the contents of a Redis key in various ways.
This is simply a read-only variant of the sort command
No description
No description
No description
No description
Remove one or more values from a Redis SET key.
Scan the members of a redis SET key.
Subscribes the client to the specified shard channels.
Retrieve the length of a Redis STRING key.
Subscribe to one or more Redis pubsub channels.
Unsubscribes the client from the given shard channels, or from all of them if none is given.
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.
Retrieve the server time from the connected Redis instance.
Get the amount of time a Redis key has before it will expire, in seconds.
Get the type of a given Redis key.
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.
Unsubscribe from one or more subscribed channels.
Remove any previously WATCH'ed keys in a transaction.
Watch one or more keys for conditional execution of a transaction.
Block the client up to the provided timeout until a certain number of replicas have confirmed receiving them.
Acknowledge one or more messages that are pending (have been consumed using XREADGROUP but not yet acknowledged by XACK.)
Append a message to a stream.
This command allows a consumer to claim pending messages that have been idle for a specified period of time.
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.
Remove one or more specific IDs from a stream.
Remove one or more IDs from a stream with extended options.
XGROUP
Retrieve information about a stream key.
Get the number of messages in a Redis STREAM key.
Interact with stream messages that have been consumed by a consumer group but not yet acknowledged with XACK.
Get a range of entries from a STREAM key.
Consume one or more unconsumed elements in one or more streams.
Read one or more messages using a consumer group.
Get a range of entries from a STREAM key in reverse chronological order.
Add to a vector set
Query similarity of a vector by element or scores
Get the length of a vector set
Get the dimensions of a vector set
Get various bits of information about a vector set
Check if an element is a member of a vectorset
Get the embeddings for a specific member
Get one or more random members from a vector set
Retreive a lexographical range of elements from a vector set
Remove an element from a vector set
Set the attributes of a vector set element
Get the attributes of a vector set element
Get any adajcent values for a member of a vector set.
Truncate a STREAM key in various ways.
Add one or more elements and scores to a Redis sorted set.
Return the number of elements in a sorted set.
Count the number of members in a sorted set with scores inside a provided range.
Create or increment the score of a member in a Redis sorted set
Count the number of elements in a sorted set whose members fall within the provided lexographical range.
Retrieve the score of one or more members in a sorted set.
Pop one or more of the highest scoring elements from a sorted set.
Pop one or more of the lowest scoring elements from a sorted set.
Retrieve a range of elements of a sorted set between a start and end point.
Retrieve a range of elements from a sorted set by legographical range.
Retrieve a range of members from a sorted set by their score.
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
Retrieve one or more random members from a Redis sorted set.
Get the rank of a member of a sorted set, by score.
Remove one or more members from a Redis sorted set.
Remove zero or more elements from a Redis sorted set by legographical range.
Remove one or more members of a sorted set by their rank.
Remove one or more members of a sorted set by their score.
List the members of a Redis sorted set in reverse order
List members of a Redis sorted set within a legographical range, in reverse order.
List elements from a Redis sorted set by score, highest to lowest
Retrieve a member of a sorted set by reverse rank.
Get the score of a member of a sorted set.
Given one or more sorted set key names, return every element that is in the first set but not any of the others.
Store the difference of one or more sorted sets in a destination sorted set.
Compute the intersection of one or more sorted sets and return the members
Similar to ZINTER but instead of returning the intersected values, this command returns the cardinality of the intersected set.
Compute the intersection of one or more sorted sets storing the result in a new sorted set.
Scan the members of a sorted set incrementally, using a cursor
Retrieve the union of one or more sorted sets
Perform a union on one or more Redis sets and store the result in a destination sorted set.
Ask the server for the XXH3 digest of a given key's value
Details
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).
__destruct()
No description
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->auth('password'); $redis->auth(['password']); $redis->auth(['username', 'password']);
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.
The calling convention is identical to Redis::blPop() so see that documentation for more details.
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.
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
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.
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.
What the command does in particular depends on the $operation qualifier.
Operations that PhpRedis supports are: RESETSTAT, REWRITE, GET, and SET.
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 = new Redis(['host' => 'localhost']);
Redis|int|false dbSize()
Return the number of keys in the currently selected Redis database.
Redis|string debug(string $key)
No description
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.
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.
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
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.
This value is updated internally in PhpRedis each time Redis::select is called.
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.
If connected to Redis server >= 7.0.0 you may pass multiple optional sections.
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.
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
Get encoding and other information about a key.
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.
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)
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
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.
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.
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.
Following are a list of options you can set:
| OPTION | TYPE | DESCRIPTION |
|---|---|---|
| OPT_MAX_RETRIES | int | The maximum number of times Redis will attempt to reconnect if it gets disconnected, before throwing an exception. |
| OPT_SCAN | enum | Redis::OPT_SCAN_RETRY, or Redis::OPT_SCAN_NORETRY. Whether PhpRedis should automatically SCAN again when zero keys but a nonzero iterator are returned. |
| OPT_SERIALIZER | enum | Set the automatic data serializer.Redis::SERIALIZER_NONERedis::SERIALIZER_PHPRedis::SERIALIZER_IGBINARYRedis::SERIALIZER_MSGPACK, Redis::SERIALIZER_JSON |
| OPT_PREFIX | string | A string PhpRedis will use to prefix every key we read or write. |
| OPT_READ_TIMEOUT | float | How long PhpRedis will block for a response from Redis before throwing a 'read error on connection' exception. |
| OPT_TCP_KEEPALIVE | bool | Set or disable TCP_KEEPALIVE on the connection. |
| OPT_COMPRESSION | enum | Set the compression algorithmRedis::COMPRESSION_NONERedis::COMPRESSION_LZFRedis::COMPRESSION_LZ4Redis::COMPRESSION_ZSTD |
| OPT_REPLY_LITERAL | bool | If set to true, PhpRedis will return the literal string Redis returns for LINE replies (e.g. '+OK'), rather than true. |
| OPT_COMPRESSION_LEVEL | int | Set a specific compression level if Redis is compressing data. |
| OPT_NULL_MULTIBULK_AS_NULL | bool | Causes PhpRedis to return NULL rather than false for NULL MULTIBULK replies |
| OPT_BACKOFF_ALGORITHM | enum | The exponential backoff strategy to use. |
| OPT_BACKOFF_BASE | int | The minimum delay between retries when backing off. |
| OPT_BACKOFF_CAP | int | The maximum delay between replies when backing off. |
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
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.
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
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
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
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
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.
Note: This command simply swaps Redis' internal pointer to the database and is therefore very fast, regardless of the size of the underlying databases.
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.
Its purpose is to provide a mechanism for picking up messages that may have had a failed consumer.
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
Perform various operation on consumer groups for a particular Redis STREAM. What the command does is primarily based on which operation is passed.
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.
How the command works in particular is greatly affected by the options that are passed in.
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.
See Redis::zdiff for a more detailed description of how the diff operation works.
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