Redis
class Redis (View source)
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 as set with Redis::setOption().
Uncompress the provided argument that has been compressed with the currently configured compressor as set with Redis::setOption().
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 with the configured serializer and compressor as set with Redis::setOption().
Unpack the provided value with the configured compressor and serializer as set with Redis::setOption().
No description
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
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
No description
No description
No description
Execute the Redis CONFIG command in a variety of ways.
No description
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.
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.
Deletes every key in all Redis databases
Deletes all the keys of the currently selected database.
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.
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.
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
No description
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.
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.
Add or update one or more hash fields and values
Get one or more random field from a hash.
No description
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.
Iterate over the fields and values of a hash in an incremental fashion.
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.
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 ore more string keys.
No description
Move a key to a different database on the same redis instance.
Set one ore more string keys.
Set one ore more string keys but only if none of the key exist.
Begin a transaction.
No description
No description
No description
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
No description
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 ore 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.
Retrieve the length of a Redis STRING key.
Subscribe to one or more Redis pubsub channels.
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 ore 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.
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.
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 ore 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.
Details
Redis
__construct(array $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 as set with Redis::setOption().
string
_uncompress(string $value)
Uncompress the provided argument that has been compressed with the currently configured compressor as set with Redis::setOption().
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 with the configured serializer and compressor as set with Redis::setOption().
mixed
_unpack(string $value)
Unpack the provided value with the configured compressor and serializer as set with Redis::setOption().
mixed
acl(string $subcmd, string ...$args)
No description
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|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)
No description
bool
close()
No description
mixed
command(string $opt = null, string|array $arg)
No description
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 $persistent_id = null, int $retry_interval = 0, float $read_timeout = 0, array $context = null)
No description
Redis|bool
copy(string $src, string $dst, array $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
delete(array|string $key, string ...$other_keys)
deprecated
deprecated
No description
Redis|bool
discard()
Discard a transaction currently in progress.
Redis|string
dump(string $key)
Dump Redis' internal binary representation of a key.
$redis->zRange('new-zset', 0, -1, true);
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.
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|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.
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.
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
int|false
getTransferredBytes()
No description
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.
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|bool
hMset(string $key, array $fieldvals)
Add or update one or more hash fields and values
Redis|string|array
hRandField(string $key, array $options = null)
Get one or more random field from a hash.
Redis|int|false
hSet(string $key, string $member, mixed $value)
No description
Redis|bool
hSetNx(string $key, string $field, string $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|bool
hscan(string $key, int|null $iterator, string|null $pattern = null, int $count = 0)
Iterate over the fields and values of a hash in an incremental fashion.
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|array|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|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 $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
mget(array $keys)
Get one ore 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)
No description
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 ore more string keys.
Redis|bool
msetnx(array $key_values)
Set one ore 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)
No description
bool
open(string $host, int $port = 6379, float $timeout = 0, string $persistent_id = NULL, int $retry_interval = 0, float $read_timeout = 0, array $context = NULL)
deprecated
deprecated
No description
bool
pconnect(string $host, int $port = 6379, float $timeout = 0, string $persistent_id = NULL, int $retry_interval = 0, float $read_timeout = 0, array $context = NULL)
No description
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::expire() for a description of the mode argument.
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
pfcount(string $key)
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 $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 $persistent_id = NULL, int $retry_interval = 0, float $read_timeout = 0, array $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)
No description
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 ore 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.
Redis|string|array|false
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(int|null $iterator, string|null $pattern = null, int $count = 0, string $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_NONE Redis::SERIALIZER_PHP Redis::SERIALIZER_IGBINARY Redis::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_NONE Redis::COMPRESSION_LZF Redis::COMPRESSION_LZ4 Redis::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 $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 $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, int|null $iterator, string|null $pattern = null, int $count = 0)
Scan the members of a redis SET key.
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|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 ore 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.
mixed
xgroup(string $operation, string $key = null, string $group = null, string $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
xtrim(string $key, string $threshold, bool $approx = false, bool $minid = false, int $limit = -1)
Truncate a STREAM key in various ways.
Redis|int|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, string $start, 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 $count = null)
Pop one or more of the highest scoring elements from a sorted set.
Redis|array|false
zPopMin(string $key, int $count = null)
Pop one or more of the lowest scoring elements from a sorted set.
Redis|array|false
zRange(string $key, mixed $start, mixed $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 $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 $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 ore more sorted sets storing the result in a new sorted set.
Redis|array|false
zscan(string $key, int|null $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.