Methods |
public
|
__construct(array|null $options = null)
Creates a Redis client
Parameters
$options |
configuration options
|
|
#
|
public
|
connect(
string $host,
int $port = 6379,
float $timeout = 0,
string $persistent_id = null,
int $retry_interval = 0,
float $read_timeout = 0,
array $context = null,
): bool
Connects to a Redis instance.
Connects to a Redis instance.
Parameters
$host |
can be a host, or the path to a unix domain socket
|
$port |
optional
|
$timeout |
value in seconds (optional, default is 0.0 meaning unlimited)
|
$persistent_id |
identity for the requested persistent connection
|
$retry_interval |
retry interval in milliseconds.
|
$read_timeout |
value in seconds (optional, default is 0 meaning unlimited)
|
$context |
since PhpRedis >= 5.3.0 can specify authentication and stream information on connect
|
Returns
TRUE on success, FALSE on error
Throws
|
#
|
public
|
open(
string $host,
int $port = 6379,
float $timeout = 0,
string $persistent_id = null,
int $retry_interval = 0,
float $read_timeout = 0,
array $context = null,
): bool
Connects to a Redis instance.
Connects to a Redis instance.
Parameters
$host |
can be a host, or the path to a unix domain socket
|
$port |
optional
|
$timeout |
value in seconds (optional, default is 0.0 meaning unlimited)
|
$persistent_id |
identity for the requested persistent connection
|
$retry_interval |
retry interval in milliseconds.
|
$read_timeout |
value in seconds (optional, default is 0 meaning unlimited)
|
$context |
since PhpRedis >= 5.3.0 can specify authentication and stream information on connect
|
Returns
TRUE on success, FALSE on error
Throws
|
#
|
public
|
isConnected(): bool
A method to determine if a phpredis object thinks it's connected to a server
A method to determine if a phpredis object thinks it's connected to a server
Returns
Returns TRUE if phpredis thinks it's connected and FALSE if not
Throws
|
#
|
public
|
getHost(): string|false
Retrieve our host or unix socket that we're connected to
Retrieve our host or unix socket that we're connected to
Returns
The host or unix socket we're connected to or FALSE if we're not connected
Throws
|
#
|
public
|
getPort(): int|false
Get the port we're connected to
Get the port we're connected to
Returns
Returns the port we're connected to or FALSE if we're not connected
Throws
|
#
|
public
|
getDbNum(): int|bool
Get the database number phpredis is pointed to
Get the database number phpredis is pointed to
Returns
Returns the database number (int) phpredis thinks it's pointing to
or FALSE if we're not connected
Throws
|
#
|
public
|
getTimeout(): float|false
Get the (write) timeout in use for phpredis
Get the (write) timeout in use for phpredis
Returns
The timeout (DOUBLE) specified in our connect call or FALSE if we're not connected
Throws
|
#
|
public
|
getReadTimeout(): float|bool
Get the read timeout specified to phpredis or FALSE if we're not connected
Get the read timeout specified to phpredis or FALSE if we're not connected
Returns
Returns the read timeout (which can be set using setOption and Redis::OPT_READ_TIMEOUT)
or FALSE if we're not connected
Throws
|
#
|
public
|
getPersistentID(): string|null|bool
Gets the persistent ID that phpredis is using
Gets the persistent ID that phpredis is using
Returns
Returns the persistent id phpredis is using
(which will only be set if connected with pconnect),
NULL if we're not using a persistent ID,
and FALSE if we're not connected
Throws
|
#
|
public
|
getAuth(): string|array|null
Get the password used to authenticate the phpredis connection
Get the password used to authenticate the phpredis connection
Returns
Returns NULL if no username/password are set,
the password string if a password is set,
and a [username, password] array if authenticated with a username and password.
Throws
|
#
|
public
|
pconnect(
string $host,
int $port = 6379,
float $timeout = 0,
string $persistent_id = null,
int $retry_interval = 0,
float $read_timeout = 0,
array $context = null,
): bool
Connects to a Redis instance or reuse a connection already established with pconnect/popen.
Connects to a Redis instance or reuse a connection already established with pconnect/popen.
The connection will not be closed on close or end of request until the php process ends.
So be patient on to many open FD's (specially on redis server side) when using persistent connections on
many servers connecting to one redis server.
Also more than one persistent connection can be made identified by either host + port + timeout
or host + persistentId or unix socket + timeout.
This feature is not available in threaded versions. pconnect and popen then working like their non persistent
equivalents.
Parameters
$host |
can be a host, or the path to a unix domain socket
|
$port |
optional
|
$timeout |
value in seconds (optional, default is 0.0 meaning unlimited)
|
$persistent_id |
identity for the requested persistent connection
|
$retry_interval |
retry interval in milliseconds.
|
$read_timeout |
value in seconds (optional, default is 0 meaning unlimited)
|
$context |
since PhpRedis >= 5.3.0 can specify authentication and stream information on connect
|
Returns
TRUE on success, FALSE on ertcnror.
Throws
|
#
|
public
|
popen(
string $host,
int $port = 6379,
float $timeout = 0,
string $persistent_id = null,
int $retry_interval = 0,
float $read_timeout = 0,
array $context = null,
): bool
|
#
|
public
|
close(): bool
Disconnects from the Redis instance.
Disconnects from the Redis instance.
Note: Closing a persistent connection requires PhpRedis >= 4.2.0
Returns
TRUE on success, FALSE on error
Throws
|
#
|
public
|
swapdb(int $db1, int $db2): bool
Swap one Redis database with another atomically
Swap one Redis database with another atomically
Note: Requires Redis >= 4.0.0
Returns
TRUE on success and FALSE on failure
Throws
|
#
|
public
|
setOption(int $option, mixed $value): bool
Set client option
Parameters
$option |
option name
|
$value |
option value
|
Returns
TRUE on success, FALSE on error
Throws
|
#
|
public
|
getOption(int $option): mixed|null
Get client option
Parameters
Returns
Throws
|
#
|
public
|
ping(string $message = null): bool|string
Check the current connection status
Check the current connection status
Parameters
Returns
TRUE if the command is successful or returns message
Throws a RedisException object on connectivity error, as described above.
Throws
|
#
|
public
|
echo(string $message): string|Redis
Sends a string to Redis, which replies with the same string
Sends a string to Redis, which replies with the same string
Returns
Returns message or Redis if in multimode
Throws
|
#
|
public
|
get(string $key): string|mixed|false|Redis
Get the value related to the specified key
Get the value related to the specified key
Returns
If key didn't exist, FALSE is returned or Redis if in multimode
Otherwise, the value related to this key is returned
Throws
|
#
|
public
|
set(string $key, string|mixed $value, int|array|mixed $timeout = null): bool|Redis
Set the string value in argument as value of the key.
Set the string value in argument as value of the key.
Parameters
$value |
string if not used serializer
|
$timeout |
[optional] Calling setex() is preferred if you want a timeout.
Since 2.6.12 it also supports different flags inside an array. Example ['NX', 'EX' => 60]
- EX seconds -- Set the specified expire time, in seconds.
- PX milliseconds -- Set the specified expire time, in milliseconds.
- NX -- Only set the key if it does not already exist.
- XX -- Only set the key if it already exist.
|
Returns
TRUE if the command is successful or Redis if in multimode
Throws
|
#
|
public
|
setex(string $key, int $expire, string|mixed $value): bool|Redis
Set the string value in argument as value of the key, with a time to live.
Set the string value in argument as value of the key, with a time to live.
Returns
returns Redis if in multimode
Throws
|
#
|
public
|
psetex(string $key, int $expire, string|mixed $value): bool|Redis
Set the value and expiration in milliseconds of a key.
Set the value and expiration in milliseconds of a key.
Parameters
Returns
returns Redis if in multimode
Throws
|
#
|
public
|
setnx(string $key, mixed $value): bool|array|Redis
Set the string value in argument as value of the key if the key doesn't already exist in the database.
Set the string value in argument as value of the key if the key doesn't already exist in the database.
Returns
returns Redis if in multimode
Throws
|
#
|
public
|
del(int|string|array $key1, int|string ...$otherKeys): false|int|Redis
Remove specified keys.
Parameters
$key1 |
An array of keys, or an undefined number of parameters, each a key: key1 key2 key3 ... keyN
|
Returns
Number of keys deleted or Redis if in multimode
Throws
|
#
|
public
|
delete(string|array $key, string ...$otherKeys): false|int|Redis
Remove specified keys.
Parameters
$key |
An array of keys, or an undefined number of parameters, each a key: key1 key2 key3 ... keyN
|
Returns
Number of keys deleted or Redis if in multimode
Throws
|
#
|
public
|
unlink(string|array $key, string ...$other_keys): false|int|Redis
Delete a key asynchronously in another thread. Otherwise it is just as DEL, but non blocking.
Delete a key asynchronously in another thread. Otherwise it is just as DEL, but non blocking.
Parameters
$key |
An array of keys, or an undefined number of parameters, each a key: key1 key2 key3 ... keyN
|
Returns
Number of keys unlinked or Redis if in multimode
Throws
|
#
|
public
|
multi(int $mode = Redis::MULTI): static|Redis
Enter and exit transactional mode.
Enter and exit transactional mode.
Parameters
$mode |
Redis::MULTI|Redis::PIPELINE
Defaults to Redis::MULTI.
A Redis::MULTI block of commands runs as a single transaction;
a Redis::PIPELINE block is simply transmitted faster to the server, but without any guarantee of atomicity.
discard cancels a transaction.
|
Returns
returns the Redis instance and enters multi-mode or Redis if in multimode
Once in multi-mode, all subsequent method calls return the same object until exec() is called.
Throws
|
#
|
public
|
pipeline(): bool|Redis
Returns a Redis instance which can simply transmitted faster to the server.
Returns a Redis instance which can simply transmitted faster to the server.
Returns
returns the Redis instance.
Once in pipeline-mode, all subsequent method calls return the same object until exec() is called.
Pay attention, that Pipeline is not a transaction, so you can get unexpected
results in case of big pipelines and small read/write timeouts.
Throws
|
#
|
public
|
exec(): void|array|Redis
Returns
returns Redis if in multimode
Throws
|
#
|
public
|
discard(): bool
Flushes all previously queued commands in a transaction and restores the connection state to normal.
Flushes all previously queued commands in a transaction and restores the connection state to normal.
Throws
|
#
|
public
|
watch(string|array $key, string ...$other_keys): bool|Redis
Watches a key for modifications by another client. If the key is modified between WATCH and EXEC,
the MULTI/EXEC…
Watches a key for modifications by another client. If the key is modified between WATCH and EXEC,
the MULTI/EXEC transaction will fail (return FALSE). unwatch cancels all the watching of all keys by this client.
Parameters
$key |
An array of keys, or an undefined number of parameters, each a key: key1 key2 key3 ... keyN
|
Returns
returns Redis if in multimode
Throws
|
#
|
public
|
unwatch(): bool|Redis
|
#
|
public
|
subscribe(string $channel, string ...$other_channels): false|array|Redis
Subscribes the client to the specified channels.
Subscribes the client to the specified channels.
Once the client enters the subscribed state it is not supposed to issue any other commands, except for additional SUBSCRIBE, SSUBSCRIBE, PSUBSCRIBE, UNSUBSCRIBE, SUNSUBSCRIBE, PUNSUBSCRIBE, PING, RESET and QUIT commands.
Throws
|
#
|
public
|
psubscribe(array $patterns, string|array|callable $callback): mixed|Redis
Subscribe to channels by pattern
Subscribe to channels by pattern
Parameters
$patterns |
an array of glob-style patterns to subscribe
|
$callback |
Either a string or an array with an object and method.
The callback will get four arguments ($redis, $pattern, $channel, $message)
|
Returns
Any non-null return value in the callback will be returned to the caller or Redis if in multimode
Throws
|
#
|
public
|
publish(string $channel, string $message): false|int|Redis
Publish messages to channels.
Publish messages to channels.
Warning: this function will probably change in the future.
Parameters
$channel |
a channel to publish to
|
$message |
string
|
Returns
Number of clients that received the message or Redis if in multimode
Throws
|
#
|
public
|
pubsub(string $keyword, string|array $argument = null): array|int|Redis
A command allowing you to get information on the Redis pub/sub system
A command allowing you to get information on the Redis pub/sub system
Parameters
$keyword |
String, which can be: "channels", "numsub", or "numpat"
|
$argument |
Optional, variant.
For the "channels" subcommand, you can pass a string pattern.
For "numsub" an array of channel names
|
Returns
Either an integer or an array or Redis if in multimode
- channels Returns an array where the members are the matching channels.
- numsub Returns a key/value array where the keys are channel names and
values are their counts.
- numpat Integer return containing the number active pattern subscriptions
Throws
|
#
|
public
|
unsubscribe(string $channel, string ...$other_channels): bool|array
Stop listening for messages posted to the given channels.
Stop listening for messages posted to the given channels.
Throws
|
#
|
public
|
punsubscribe(array $patterns): false|array
Stop listening for messages posted to the given channels.
Stop listening for messages posted to the given channels.
Parameters
$patterns |
an array of glob-style patterns to unsubscribe
|
Throws
|
#
|
public
|
exists(string|string[] $key): int|bool|Redis
Verify if the specified key/keys exists
Verify if the specified key/keys exists
This function took a single argument and returned TRUE or FALSE in phpredis versions < 4.0.0.
Returns
The number of keys tested that do exist or Redis if in multimode
Throws
|
#
|
public
|
incr(string $key): false|int|Redis
Increment the number stored at key by one.
Increment the number stored at key by one.
Returns
the new value or Redis if in multimode
Throws
|
#
|
public
|
incrByFloat(string $key, float $increment): float|Redis
Increment the float value of a key by the given amount
Increment the float value of a key by the given amount
Returns
returns Redis if in multimode
Throws
|
#
|
public
|
incrBy(string $key, int $value): false|int|Redis
Increment the number stored at key by one.
If the second argument is filled, it will be used as the integer value of…
Increment the number stored at key by one.
If the second argument is filled, it will be used as the integer value of the increment.
Parameters
$key |
key
|
$value |
value that will be added to key (only for incrBy)
|
Returns
the new value or Redis if in multimode
Throws
|
#
|
public
|
decr(string $key): false|int|Redis
Decrement the number stored at key by one.
Decrement the number stored at key by one.
Returns
the new value or Redis if in multimode
Throws
|
#
|
public
|
decrBy(string $key, int $value): false|int|Redis
Decrement the number stored at key by one.
If the second argument is filled, it will be used as the integer value of…
Decrement the number stored at key by one.
If the second argument is filled, it will be used as the integer value of the decrement.
Parameters
$value |
that will be subtracted to key (only for decrBy)
|
Returns
the new value or Redis if in multimode
Throws
|
#
|
public
|
lPush(string $key, string|mixed ...$value1): int|false|Redis
Adds the string values to the head (left) of the list.
Creates the list if the key didn't exist.
If the key exists and…
Adds the string values to the head (left) of the list.
Creates the list if the key didn't exist.
If the key exists and is not a list, FALSE is returned.
Parameters
...$value1 |
Variadic list of values to push in key, if dont used serialized, used string
|
Returns
The new length of the list in case of success, FALSE in case of Failure or Redis if in multimode
Throws
|
#
|
public
|
rPush(string $key, string|mixed ...$value1): int|false|Redis
Adds the string values to the tail (right) of the list.
Creates the list if the key didn't exist.
If the key exists and…
Adds the string values to the tail (right) of the list.
Creates the list if the key didn't exist.
If the key exists and is not a list, FALSE is returned.
Parameters
...$value1 |
Variadic list of values to push in key, if dont used serialized, used string
|
Returns
The new length of the list in case of success, FALSE in case of Failure or Redis if in multimode
Throws
|
#
|
public
|
lPushx(string $key, string|mixed $value): int|false|Redis
Adds the string value to the head (left) of the list if the list exists.
Adds the string value to the head (left) of the list if the list exists.
Parameters
$value |
String, value to push in key
|
Returns
The new length of the list in case of success, FALSE in case of Failure or Redis if in multimode
Throws
|
#
|
public
|
rPushx(string $key, string|mixed $value): int|false|Redis
Adds the string value to the tail (right) of the list if the ist exists. FALSE in case of Failure.
Adds the string value to the tail (right) of the list if the ist exists. FALSE in case of Failure.
Parameters
$value |
String, value to push in key
|
Returns
The new length of the list in case of success, FALSE in case of Failure or Redis if in multimode
Throws
|
#
|
public
|
lPop(string $key, int $count = 0): mixed|bool|Redis
Returns and removes the first element of the list.
Returns and removes the first element of the list.
Returns
if command executed successfully BOOL FALSE in case of failure (empty list) or Redis if in multimode
Throws
|
#
|
public
|
rPop(string $key, int $count = 0): mixed|bool|Redis
Returns and removes the last element of the list.
Returns and removes the last element of the list.
Returns
if command executed successfully BOOL FALSE in case of failure (empty list) or Redis if in multimode
Throws
|
#
|
public
|
blPop(string|string[] $key, int $timeout_or_key, mixed ...$extra_args): array|Redis
Is a blocking lPop primitive. If at least one of the lists contains at least one element,
the element will be popped…
Is a blocking lPop primitive. If at least one of the lists contains at least one element,
the element will be popped from the head of the list and returned to the caller.
Il all the list identified by the keys passed in arguments are empty, blPop will block
during the specified timeout until an element is pushed to one of those lists. This element will be popped.
Parameters
$key |
String array containing the keys of the lists OR variadic list of strings
|
$timeout_or_key |
Timeout is always the required final parameter
|
Returns
['listName', 'element'] or Redis if in multimode
Throws
|
#
|
public
|
brPop(string|string[] $key, int $timeout_or_key, mixed ...$extra_args): array|Redis
Is a blocking rPop primitive. If at least one of the lists contains at least one element,
the element will be popped…
Is a blocking rPop primitive. If at least one of the lists contains at least one element,
the element will be popped from the head of the list and returned to the caller.
Il all the list identified by the keys passed in arguments are empty, brPop will
block during the specified timeout until an element is pushed to one of those lists.
This element will be popped.
Parameters
$key |
String array containing the keys of the lists OR variadic list of strings
|
$timeout_or_key |
Timeout is always the required final parameter
|
Returns
['listName', 'element'] or Redis if in multimode
Throws
|
#
|
public
|
lLen(string $key): int|bool|Redis
Returns the size of a list identified by Key. If the list didn't exist or is empty,
the command returns 0. If the data…
Returns the size of a list identified by Key. If the list didn't exist or is empty,
the command returns 0. If the data type identified by Key is not a list, the command return FALSE.
Returns
The size of the list identified by Key exists or Redis if in multimode
bool FALSE if the data type identified by Key is not list
Throws
|
#
|
public
|
lSize(string $key): false|int|Redis
Returns
The size of the list identified by Key exists or Redis if in multimode
Throws
|
#
|
public
|
lIndex(string $key, int $index): mixed|bool|Redis
Return the specified element of the list stored at the specified key.
0 the first element, 1 the second ... -1 the last…
Return the specified element of the list stored at the specified key.
0 the first element, 1 the second ... -1 the last element, -2 the penultimate ...
Return FALSE in case of a bad index or a key that doesn't point to a list.
Returns
the element at this index or Redis if in multimode
Throws
|
#
|
public
|
lGet(string $key, int $index): mixed|bool|Redis
Returns
the element at this index or Redis if in multimode
Throws
|
#
|
public
|
lSet(string $key, int $index, string $value): bool|Redis
Set the list at index with the new value.
Set the list at index with the new value.
Returns
TRUE if the new value is setted or Redis if in multimode
FALSE if the index is out of range, or data type identified by key is not a list.
Throws
|
#
|
public
|
lRange(string $key, int $start, int $end): array|Redis
Returns the specified elements of the list stored at the specified key in
the range [start, end]. start and stop are…
Returns the specified elements of the list stored at the specified key in
the range [start, end]. start and stop are interpretated as indices: 0 the first element,
1 the second ... -1 the last element, -2 the penultimate ...
Returns
containing the values in specified range or Redis if in multimode
Throws
|
#
|
public
|
lGetRange(string $key, int $start, int $end): array|Redis
Returns
returns Redis if in multimode
Throws
|
#
|
public
|
lTrim(string $key, int $start, int $stop): array|false|Redis
Trims an existing list so that it will contain only a specified range of elements.
Trims an existing list so that it will contain only a specified range of elements.
Returns
Bool return FALSE if the key identify a non-list value or Redis if in multimode
Throws
|
#
|
public
|
listTrim(string $key, int $start, int $stop)
|
#
|
public
|
lRem(string $key, string $value, int $count): int|bool|Redis
Removes the first count occurrences of the value element from the list.
If count is zero, all the matching elements are…
Removes the first count occurrences of the value element from the list.
If count is zero, all the matching elements are removed. If count is negative,
elements are removed from tail to head.
Returns
the number of elements to remove or Redis if in multimode
bool FALSE if the value identified by key is not a list.
Throws
|
#
|
public
|
lRemove(string $key, string $value, int $count)
|
#
|
public
|
lInsert(string $key, string $position, mixed $pivot, string|mixed $value): false|int|Redis
Insert value in the list before or after the pivot value. the parameter options
specify the position of the insert …
Insert value in the list before or after the pivot value. the parameter options
specify the position of the insert (before or after). If the list didn't exists,
or the pivot didn't exists, the value is not inserted.
Parameters
$position |
Redis::BEFORE | Redis::AFTER
|
Returns
The number of the elements in the list, -1 if the pivot didn't exists or Redis if in multimode
Throws
|
#
|
public
|
sAdd(string $key, string $value, mixed ...$other_values): int|bool|Redis
Adds a values to the set value stored at key.
Adds a values to the set value stored at key.
Parameters
$key |
Required key
|
...$other_values |
Variadic list of values
|
Returns
The number of elements added to the set or Redis if in multimode
If this value is already in the set, FALSE is returned
|
#
|
public
|
sRem(string $key, string $value, string|mixed ...$other_values): false|int|Redis
Removes the specified members from the set value stored at key.
Removes the specified members from the set value stored at key.
Parameters
...$other_values |
Variadic list of members
|
Returns
The number of elements removed from the set or Redis if in multimode
|
#
|
public
|
sRemove(string $key, string|mixed ...$member1)
|
#
|
public
|
sMove(string $srcKey, string $dstKey, string $member): bool|Redis
Moves the specified member from the set at srcKey to the set at dstKey.
Moves the specified member from the set at srcKey to the set at dstKey.
Returns
If the operation is successful, return TRUE or Redis if in multimode
If the srcKey and/or dstKey didn't exist, and/or the member didn't exist in srcKey, FALSE is returned.
Throws
|
#
|
public
|
sIsMember(string $key, string|mixed $value): bool|Redis
Checks if value is a member of the set stored at the key key.
Checks if value is a member of the set stored at the key key.
Returns
TRUE if value is a member of the set at key key, FALSE otherwise or Redis if in multimode
Throws
|
#
|
public
|
sContains(string $key, string|mixed $value)
|
#
|
public
|
sCard(string $key): false|int|Redis
Returns the cardinality of the set identified by key.
Returns the cardinality of the set identified by key.
Returns
the cardinality of the set identified by key, 0 if the set doesn't exist or Redis if in multimode
Throws
|
#
|
public
|
sPop(string $key, int $count = 0): string|mixed|array|bool|Redis
Removes and returns a random element from the set value at Key.
Removes and returns a random element from the set value at Key.
Parameters
Returns
"popped" values or Redis if in multimode
bool FALSE if set identified by key is empty or doesn't exist.
Throws
|
#
|
public
|
sRandMember(string $key, int $count = 0): string|mixed|array|bool|Redis
Returns a random element(s) from the set value at Key, without removing it.
Returns a random element(s) from the set value at Key, without removing it.
Parameters
Returns
value(s) from the set or Redis if in multimode
bool FALSE if set identified by key is empty or doesn't exist and count argument isn't passed.
Throws
|
#
|
public
|
sInter(string $key1, string ...$otherKeys): array|false|Redis
Returns the members of a set resulting from the intersection of all the sets
held at the specified keys. If just a…
Returns the members of a set resulting from the intersection of all the sets
held at the specified keys. If just a single key is specified, then this command
produces the members of this set. If one of the keys is missing, FALSE is returned.
Parameters
$key1 |
keys identifying the different sets on which we will apply the intersection.
|
...$otherKeys |
variadic list of keys
|
Returns
contain the result of the intersection between those keys or Redis if in multimode
If the intersection between the different sets is empty, the return value will be empty array.
Throws
|
#
|
public
|
sInterStore(string $dstKey, string $key1, string ...$otherKeys): int|false|Redis
Performs a sInter command and stores the result in a new set.
Performs a sInter command and stores the result in a new set.
Parameters
$dstKey |
the key to store the diff into.
|
$key1 |
keys identifying the different sets on which we will apply the intersection.
|
...$otherKeys |
variadic list of keys
|
Returns
The cardinality of the resulting set, or FALSE in case of a missing key or Redis if in multimode
Throws
|
#
|
public
|
sUnion(string $key1, string ...$otherKeys): array|Redis
Performs the union between N sets and returns it.
Performs the union between N sets and returns it.
Parameters
$key1 |
first key for union
|
...$otherKeys |
variadic list of keys corresponding to sets in redis
|
Returns
string[] The union of all these sets or Redis if in multimode
Throws
|
#
|
public
|
sUnionStore(string $dstKey, string $key1, string ...$otherKeys): false|int|Redis
Performs the same action as sUnion, but stores the result in the first key
Performs the same action as sUnion, but stores the result in the first key
Parameters
$dstKey |
the key to store the diff into.
|
$key1 |
first key for union
|
...$otherKeys |
variadic list of keys corresponding to sets in redis
|
Returns
Any number of keys corresponding to sets in redis or Redis if in multimode
Throws
|
#
|
public
|
sDiff(string $key1, string ...$otherKeys): array|Redis
Performs the difference between N sets and returns it.
Performs the difference between N sets and returns it.
Parameters
$key1 |
first key for diff
|
...$otherKeys |
variadic list of keys corresponding to sets in redis
|
Returns
string[] The difference of the first set will all the others or Redis if in multimode
Throws
|
#
|
public
|
sDiffStore(string $dstKey, string $key1, string ...$otherKeys): int|false|Redis
Performs the same action as sDiff, but stores the result in the first key
Performs the same action as sDiff, but stores the result in the first key
Parameters
$dstKey |
the key to store the diff into.
|
$key1 |
first key for diff
|
...$otherKeys |
variadic list of keys corresponding to sets in redis
|
Returns
The cardinality of the resulting set, or FALSE in case of a missing key or Redis if in multimode
Throws
|
#
|
public
|
sMembers(string $key): array|Redis
Returns the contents of a set.
Returns the contents of a set.
Returns
An array of elements, the contents of the set or Redis if in multimode
Throws
|
#
|
public
|
sMisMember(string $key, string $member, string ...$other_members): array|false
|
#
|
public
|
sGetMembers(string $key): array|Redis
Returns
An array of elements, the contents of the set or Redis if in multimode
Throws
|
#
|
public
|
sScan(string $key, int &$iterator, string $pattern = null, int $count = 0): array|false|Redis
Scan a set for members
Parameters
$key |
The set to search.
|
$iterator |
LONG (reference) to the iterator as we go.
|
$pattern |
String, optional pattern to match against.
|
$count |
How many members to return at a time (Redis might return a different amount)
|
Returns
PHPRedis will return an array of keys or FALSE when we're done iterating or Redis if in multimode
Throws
|
#
|
public
|
getSet(string $key, string|mixed $value): string|mixed|Redis
Sets a value and returns the previous entry at that key.
Sets a value and returns the previous entry at that key.
Returns
A string (mixed, if used serializer), the previous value located at this key or Redis if in multimode
Throws
|
#
|
public
|
randomKey(): string|Redis
Returns a random key
Returns
an existing key in redis or Redis if in multimode
Throws
|
#
|
public
|
select(int $dbIndex): bool|Redis
Switches to a given database
Switches to a given database
Returns
TRUE in case of success, FALSE in case of failure or Redis if in multimode
Throws
|
#
|
public
|
move(string $key, int $dbIndex): bool|Redis
Moves a key to a different database.
Moves a key to a different database.
Returns
TRUE in case of success, FALSE in case of failure or Redis if in multimode
Throws
|
#
|
public
|
rename(string $srcKey, string $dstKey): bool|Redis
Renames a key
Returns
TRUE in case of success, FALSE in case of failure or Redis if in multimode
Throws
|
#
|
public
|
renameKey(string $srcKey, string $dstKey)
|
#
|
public
|
renameNx(string $srcKey, string $dstKey): bool|Redis
Renames a key
Renames a key
Same as rename, but will not replace a key if the destination already exists.
This is the same behaviour as setnx.
Returns
TRUE in case of success, FALSE in case of failure or Redis if in multimode
Throws
|
#
|
public
|
expire(string $key, int $ttl): bool|Redis
Sets an expiration date (a timeout) on an item
Sets an expiration date (a timeout) on an item
Parameters
$key |
The key that will disappear
|
$ttl |
The key's remaining Time To Live, in seconds
|
Returns
TRUE in case of success, FALSE in case of failure or Redis if in multimode
Throws
|
#
|
public
|
pExpire(string $key, int $ttl): bool|Redis
Sets an expiration date (a timeout in milliseconds) on an item
Sets an expiration date (a timeout in milliseconds) on an item
Parameters
$key |
The key that will disappear.
|
$ttl |
The key's remaining Time To Live, in milliseconds
|
Returns
TRUE in case of success, FALSE in case of failure or Redis if in multimode
Throws
|
#
|
public
|
setTimeout(string $key, int $ttl): bool|Redis
Returns
returns Redis if in multimode
Throws
|
#
|
public
|
expireAt(string $key, int $timestamp): bool|Redis
Sets an expiration date (a timestamp) on an item.
Sets an expiration date (a timestamp) on an item.
Parameters
$key |
The key that will disappear.
|
$timestamp |
Unix timestamp. The key's date of death, in seconds from Epoch time.
|
Returns
TRUE in case of success, FALSE in case of failure or Redis if in multimode
Throws
|
#
|
public
|
pExpireAt(string $key, int $timestamp): bool|Redis
Sets an expiration date (a timestamp) on an item. Requires a timestamp in milliseconds
Sets an expiration date (a timestamp) on an item. Requires a timestamp in milliseconds
Parameters
$key |
The key that will disappear
|
$timestamp |
Unix timestamp. The key's date of death, in seconds from Epoch time
|
Returns
TRUE in case of success, FALSE in case of failure or Redis if in multimode
Throws
|
#
|
public
|
keys(string $pattern): array|Redis
Returns the keys that match a certain pattern.
Returns the keys that match a certain pattern.
Parameters
$pattern |
pattern, using '*' as a wildcard
|
Returns
string[] The keys that match a certain pattern or Redis if in multimode
Throws
|
#
|
public
|
getKeys(string $pattern)
|
#
|
public
|
dbSize(): false|int|Redis
Returns the current database's size
Returns the current database's size
Returns
DB size, in number of keys or Redis if in multimode
Throws
|
#
|
public
|
auth(mixed $credentials): bool|Redis
Authenticate the connection using a password.
Warning: The password is sent in plain-text over the network.
Authenticate the connection using a password.
Warning: The password is sent in plain-text over the network.
Returns
TRUE if the connection is authenticated, FALSE otherwise or Redis if in multimode
Throws
|
#
|
public
|
bgrewriteaof(): bool|Redis
Starts the background rewrite of AOF (Append-Only File)
Starts the background rewrite of AOF (Append-Only File)
Returns
TRUE in case of success, FALSE in case of failure or Redis if in multimode
Throws
|
#
|
public
|
slaveof(string $host = '127.0.0.1', int $port = 6379): bool|Redis
Changes the slave status
Either host and port, or no parameter to stop being a slave.
Changes the slave status
Either host and port, or no parameter to stop being a slave.
Parameters
$host |
[optional]
|
$port |
[optional]
|
Returns
TRUE in case of success, FALSE in case of failure or Redis if in multimode
Throws
|
#
|
public
|
slowLog(string $operation, int|null $length = null): mixed|Redis
Access the Redis slowLog
Parameters
$operation |
This can be either GET, LEN, or RESET
|
$length |
If executing a SLOWLOG GET command, you can pass an optional length.
|
Returns
The return value of SLOWLOG will depend on which operation was performed or Redis if in multimode
- SLOWLOG GET: Array of slowLog entries, as provided by Redis
- SLOGLOG LEN: Integer, the length of the slowLog
- SLOWLOG RESET: Boolean, depending on success
Throws
|
#
|
public
|
object(string $subcommand, string $key): string|int|false|Redis
Describes the object pointed to by a key.
The information to retrieve (string) and the key (string).
Info can be one of…
Describes the object pointed to by a key.
The information to retrieve (string) and the key (string).
Info can be one of the following:
- "encoding"
- "refcount"
- "idletime"
Returns
for "encoding", int for "refcount" and "idletime", FALSE if the key doesn't exist or Redis if in multimode
Throws
|
#
|
public
|
save(): bool|Redis
Performs a synchronous save.
Performs a synchronous save.
Returns
TRUE in case of success, FALSE in case of failure or Redis if in multimode
If a save is already running, this command will fail and return FALSE.
Throws
|
#
|
public
|
bgsave(): bool|Redis
Performs a background save.
Performs a background save.
Returns
TRUE in case of success, FALSE in case of failure or Redis if in multimode
If a save is already running, this command will fail and return FALSE
Throws
|
#
|
public
|
lastSave(): false|int|Redis
Returns the timestamp of the last disk save.
Returns the timestamp of the last disk save.
Returns
timestamp or Redis if in multimode
Throws
|
#
|
public
|
wait(int $numSlaves, int $timeout): int|Redis
Blocks the current client until all the previous write commands are successfully transferred and
acknowledged by at…
Blocks the current client until all the previous write commands are successfully transferred and
acknowledged by at least the specified number of slaves.
Parameters
$numSlaves |
Number of slaves that need to acknowledge previous write commands.
|
$timeout |
Timeout in milliseconds.
|
Returns
The command returns the number of slaves reached by all the writes performed in the or Redis if in multimode
context of the current connection
Throws
|
#
|
public
|
type(string $key): false|int|Redis
Returns the type of data pointed by a given key.
Returns the type of data pointed by a given key.
Returns
returns Redis if in multimode
Depending on the type of the data pointed by the key,
this method will return the following value:
- string: Redis::REDIS_STRING
- set: Redis::REDIS_SET
- list: Redis::REDIS_LIST
- zset: Redis::REDIS_ZSET
- hash: Redis::REDIS_HASH
- stream: Redis::REDIS_STREAM
- other: Redis::REDIS_NOT_FOUND
Throws
|
#
|
public
|
append(string $key, string|mixed $value): false|int|Redis
Append specified string to the string stored in specified key.
Append specified string to the string stored in specified key.
Returns
Size of the value after the append or Redis if in multimode
Throws
|
#
|
public
|
getRange(string $key, int $start, int $end): string|Redis
Return a substring of a larger string
Return a substring of a larger string
Returns
the substring or Redis if in multimode
Throws
|
#
|
public
|
substr(string $key, int $start, int $end)
Return a substring of a larger string
Return a substring of a larger string
Throws
|
#
|
public
|
setRange(string $key, int $offset, string $value): false|int|Redis
Changes a substring of a larger string.
Changes a substring of a larger string.
Returns
the length of the string after it was modified or Redis if in multimode
Throws
|
#
|
public
|
strlen(string $key): false|int|Redis
Get the length of a string value.
Get the length of a string value.
Returns
returns Redis if in multimode
Throws
|
#
|
public
|
bitpos(string $key, int $bit, int $start = 0, int $end = -1): false|int|Redis
Return the position of the first bit set to 1 or 0 in a string. The position is returned, thinking of the
string as an…
Return the position of the first bit set to 1 or 0 in a string. The position is returned, thinking of the
string as an array of bits from left to right, where the first byte's most significant bit is at position 0,
the second byte's most significant bit is at position 8, and so forth.
Returns
The command returns the position of the first bit set to 1 or 0 according to the request or Redis if in multimode
If we look for set bits (the bit argument is 1) and the string is empty or composed of just
zero bytes, -1 is returned. If we look for clear bits (the bit argument is 0) and the string
only contains bit set to 1, the function returns the first bit not part of the string on the
right. So if the string is three bytes set to the value 0xff the command BITPOS key 0 will
return 24, since up to bit 23 all the bits are 1. Basically, the function considers the right
of the string as padded with zeros if you look for clear bits and specify no range or the
start argument only. However, this behavior changes if you are looking for clear bits and
specify a range with both start and end. If no clear bit is found in the specified range, the
function returns -1 as the user specified a clear range and there are no 0 bits in that range.
Throws
|
#
|
public
|
getBit(string $key, int $offset): false|int|Redis
Return a single bit out of a larger string
Return a single bit out of a larger string
Returns
the bit value (0 or 1) or Redis if in multimode
Throws
|
#
|
public
|
setBit(string $key, int $offset, bool|int $value): false|int|Redis
Changes a single bit of a string.
Changes a single bit of a string.
Parameters
$value |
bool or int (1 or 0)
|
Returns
0 or 1, the value of the bit before it was set or Redis if in multimode
Throws
|
#
|
public
|
bitCount(string $key, int $start = 0, int $end = -1): false|int|Redis
Count bits in a string
Returns
The number of bits set to 1 in the value behind the input key or Redis if in multimode
Throws
|
#
|
public
|
bitOp(string $operation, string $retKey, string $key1, string ...$otherKeys): false|int|Redis
Bitwise operation on multiple keys.
Bitwise operation on multiple keys.
Parameters
$operation |
either "AND", "OR", "NOT", "XOR"
|
$retKey |
return key
|
$key1 |
first key
|
...$otherKeys |
variadic list of keys
|
Returns
The size of the string stored in the destination key or Redis if in multimode
Throws
|
#
|
public
|
flushDB(bool $async = null): bool|Redis
Removes all entries from the current database.
Removes all entries from the current database.
Parameters
$async |
requires server version 4.0.0 or greater
|
Returns
Always TRUE or Redis if in multimode
Throws
|
#
|
public
|
flushAll(bool $async = null): bool|Redis
Removes all entries from all databases.
Removes all entries from all databases.
Parameters
$async |
requires server version 4.0.0 or greater
|
Returns
Always TRUE or Redis if in multimode
Throws
|
#
|
public
|
sort(string $key, array $option = null): array|Redis
Sort
Parameters
$option |
array(key => value, ...) - optional, with the following keys and values:
- 'by' => 'some_pattern_*',
- 'limit' => array(0, 1),
- 'get' => 'some_other_pattern_*' or an array of patterns,
- 'sort' => 'asc' or 'desc',
- 'alpha' => TRUE,
- 'store' => 'external-key'
|
Returns
returns Redis if in multimode
An array of values, or a number corresponding to the number of elements stored if that was used
Throws
|
#
|
public
|
info(string $option = null): array|Redis
Returns an associative array of strings and integers
Returns an associative array of strings and integers
Parameters
$option |
Optional. The option to provide redis.
SERVER | CLIENTS | MEMORY | PERSISTENCE | STATS | REPLICATION | CPU | CLUSTER | KEYSPACE | COMMANDSTATS
|
Returns
returns Redis if in multimode
Throws
|
#
|
public
|
role(): array|Redis
Returns an indexed array whose first element is the role
Returns an indexed array whose first element is the role
Returns
returns Redis if in multimode
Throws
|
#
|
public
|
resetStat(): bool|Redis
Resets the statistics reported by Redis using the INFO command (`info()` function).
These are the counters that are…
Resets the statistics reported by Redis using the INFO command (info() function).
These are the counters that are reset:
- Keyspace hits
- Keyspace misses
- Number of commands processed
- Number of connections received
- Number of expired keys
Returns
TRUE in case of success, FALSE in case of failure or Redis if in multimode
Throws
|
#
|
public
|
ttl(string $key): int|bool|Redis
Returns the time to live left for a given key, in seconds. If the key doesn't exist, FALSE is returned.
Returns the time to live left for a given key, in seconds. If the key doesn't exist, FALSE is returned.
Returns
the time left to live in seconds or Redis if in multimode
Throws
|
#
|
public
|
pttl(string $key): int|bool|Redis
Returns a time to live left for a given key, in milliseconds.
Returns a time to live left for a given key, in milliseconds.
If the key doesn't exist, FALSE is returned.
Returns
the time left to live in milliseconds or Redis if in multimode
Throws
|
#
|
public
|
persist(string $key): bool|Redis
Remove the expiration timer from a key.
Remove the expiration timer from a key.
Returns
TRUE if a timeout was removed, FALSE if the key didn’t exist or didn’t have an expiration timer or Redis if in multimode
Throws
|
#
|
public
|
mSet(array<string, string> $array): bool|Redis
Sets multiple key-value pairs in one atomic command.
MSETNX only returns TRUE if all the keys were set (see SETNX).
Sets multiple key-value pairs in one atomic command.
MSETNX only returns TRUE if all the keys were set (see SETNX).
Parameters
$array |
Pairs: array(key => value, ...)
|
Returns
TRUE in case of success, FALSE in case of failure or Redis if in multimode
Throws
|
#
|
public
|
getMultiple(array $keys): array|Redis
Get the values of all the specified keys.
If one or more keys dont exist, the array will contain FALSE at the position…
Get the values of all the specified keys.
If one or more keys dont exist, the array will contain FALSE at the position of the key.
Parameters
$keys |
Array containing the list of the keys
|
Returns
Array containing the values related to keys in argument or Redis if in multimode
Throws
|
#
|
public
|
mGet(array $array): false|list<false|string>|Redis
Returns the values of all specified keys.
Returns the values of all specified keys.
For every key that does not hold a string value or does not exist,
the special value false is returned. Because of this, the operation never fails.
Returns
returns Redis if in multimode
Throws
|
#
|
public
|
msetnx(array<string, string> $array): false|int|Redis
Returns
1 (if the keys were set) or 0 (no key was set) or Redis if in multimode
Throws
|
#
|
public
|
rPopLPush(string $srcKey, string $dstKey): string|mixed|false|Redis
Pops a value from the tail of a list, and pushes it to the front of another list.
Also return this value.
Pops a value from the tail of a list, and pushes it to the front of another list.
Also return this value.
Returns
The element that was moved in case of success, FALSE in case of failure or Redis if in multimode
Throws
|
#
|
public
|
bRPopLPush(string $srcKey, string $dstKey, int $timeout): string|mixed|bool|Redis
A blocking version of rPopLPush, with an integral timeout in the third parameter.
A blocking version of rPopLPush, with an integral timeout in the third parameter.
Returns
The element that was moved in case of success, FALSE in case of timeout or Redis if in multimode
Throws
|
#
|
public
|
zAdd(
string $key,
array|float $options,
float|string|mixed $score1,
string|float|mixed $value1 = null,
float|string|mixed $score2 = null,
string|float|mixed $value2 = null,
float|string|mixed $scoreN = null,
string|float|mixed $valueN = null,
): false|int|Redis
Adds the specified member with a given score to the sorted set stored at key
Adds the specified member with a given score to the sorted set stored at key
Parameters
$key |
Required key
|
$options |
Options if needed or score if omitted
|
$score1 |
Required score or value if options omitted
|
$value1 |
Required value or optional score if options omitted
|
$score2 |
Optional score or value if options omitted
|
$value2 |
Optional value or score if options omitted
|
$scoreN |
Optional score or value if options omitted
|
$valueN |
Optional value or score if options omitted
|
Returns
Number of values added or Redis if in multimode
Throws
|
#
|
public
|
zRange(string $key, int $start, int $end, mixed $withscores = null): array|Redis
Returns a range of elements from the ordered set stored at the specified key,
with values in the range [start, end].…
Returns a range of elements from the ordered set stored at the specified key,
with values in the range [start, end]. start and stop are interpreted as zero-based indices:
0 the first element,
1 the second ...
-1 the last element,
-2 the penultimate ...
Returns
Array containing the values in specified range or Redis if in multimode
Throws
|
#
|
public
|
zRem(string $key, string|mixed $member1, string|mixed ...$otherMembers): false|int|Redis
Deletes a specified member from the ordered set.
Deletes a specified member from the ordered set.
Returns
Number of deleted values or Redis if in multimode
Throws
|
#
|
public
|
zDelete(string $key, string|mixed $member1, string|mixed ...$otherMembers): false|int|Redis
Returns
Number of deleted values or Redis if in multimode
Throws
|
#
|
public
|
zRevRange(string $key, int $start, int $end, mixed $withscore = null): array|Redis
Returns the elements of the sorted set stored at the specified key in the range [start, end]
in reverse order. start…
Returns the elements of the sorted set stored at the specified key in the range [start, end]
in reverse order. start and stop are interpretated as zero-based indices:
0 the first element,
1 the second ...
-1 the last element,
-2 the penultimate ...
Returns
Array containing the values in specified range or Redis if in multimode
Throws
|
#
|
public
|
zRangeByScore(string $key, int $start, int $end, array $options = []): array|Redis
Returns the elements of the sorted set stored at the specified key which have scores in the
range [start,end]. Adding a…
Returns the elements of the sorted set stored at the specified key which have scores in the
range [start,end]. Adding a parenthesis before start or end excludes it from the range.
+inf and -inf are also valid limits.
zRevRangeByScore returns the same items in reverse order, when the start and end parameters are swapped.
Parameters
$options |
Two options are available:
- withscores => TRUE,
- and limit => array($offset, $count)
|
Returns
Array containing the values in specified range or Redis if in multimode
Throws
|
#
|
public
|
zRevRangeByScore(string $key, string $start, string $end, array $options = []): array|Redis
Returns
returns Redis if in multimode
Throws
|
#
|
public
|
zRangeByLex(string $key, string $min, string $max, int $offset = -1, int $count = -1): array|false|Redis
Returns a lexigraphical range of members in a sorted set, assuming the members have the same score. The
min and max…
Returns a lexigraphical range of members in a sorted set, assuming the members have the same score. The
min and max values are required to start with '(' (exclusive), '[' (inclusive), or be exactly the values
'-' (negative inf) or '+' (positive inf). The command must be called with either three or five
arguments or will return FALSE.
Parameters
$key |
The ZSET you wish to run against.
|
$min |
The minimum alphanumeric value you wish to get.
|
$max |
The maximum alphanumeric value you wish to get.
|
$offset |
Optional argument if you wish to start somewhere other than the first element.
|
Returns
Array containing the values in the specified range or Redis if in multimode
Throws
|
#
|
public
|
zMscore(string $key, string $member, string ...$other_members): array|false
|
#
|
public
|
zPopMax(string $key, int $count = null): array|Redis
Can pop the highest scoring members from one ZSET.
Can pop the highest scoring members from one ZSET.
Returns
Either an array with the key member and score of the highest element or an empty array or Redis if in multimode
if there is no element to pop.
Throws
|
#
|
public
|
zPopMin(string $key, int $count = null): array|Redis
Can pop the lowest scoring members from one ZSET.
Can pop the lowest scoring members from one ZSET.
Returns
Either an array with the key member and score of the lowest element or an empty array or Redis if in multimode
if there is no element to pop.
Throws
|
#
|
public
|
zRandMember(string $key, array $options = null): string|array|false
|
#
|
public
|
zRevRangeByLex(string $key, string $min, string $max, int $offset = -1, int $count = -1): false|array|Redis
Returns
returns Redis if in multimode
Throws
|
#
|
public
|
zRemRangeByLex(string $key, string $min, string $max): int|false
Removes all elements in the sorted set stored at key between the lexicographical range specified by min and max.…
Removes all elements in the sorted set stored at key between the lexicographical range specified by min and max.
Applies when all the elements in a sorted set are inserted with the same score, in order to force lexicographical ordering.
Parameters
$key |
The ZSET you wish to run against.
|
$min |
The minimum alphanumeric value you wish to get.
|
$max |
The maximum alphanumeric value you wish to get.
|
Returns
the number of elements removed.
|
#
|
public
|
zCount(string $key, string $start, string $end): false|int|Redis
Returns the number of elements of the sorted set stored at the specified key which have
scores in the range [start,end]…
Returns the number of elements of the sorted set stored at the specified key which have
scores in the range [start,end]. Adding a parenthesis before start or end excludes it
from the range. +inf and -inf are also valid limits.
Returns
the size of a corresponding zRangeByScore or Redis if in multimode
Throws
|
#
|
public
|
zRemRangeByScore(string $key, string $start, string $end): false|int|Redis
Deletes the elements of the sorted set stored at the specified key which have scores in the range [start,end].
Deletes the elements of the sorted set stored at the specified key which have scores in the range [start,end].
Parameters
$start |
double or "+inf" or "-inf" as a string
|
$end |
double or "+inf" or "-inf" as a string
|
Returns
The number of values deleted from the sorted set or Redis if in multimode
Throws
|
#
|
public
|
zDeleteRangeByScore(string $key, float $start, float $end)
|
#
|
public
|
zRemRangeByRank(string $key, int $start, int $end): false|int|Redis
Deletes the elements of the sorted set stored at the specified key which have rank in the range [start,end].
Deletes the elements of the sorted set stored at the specified key which have rank in the range [start,end].
Returns
The number of values deleted from the sorted set or Redis if in multimode
Throws
|
#
|
public
|
zDeleteRangeByRank(string $key, int $start, int $end)
|
#
|
public
|
zCard(string $key): false|int|Redis
Returns the cardinality of an ordered set.
Returns the cardinality of an ordered set.
Returns
the set's cardinality or Redis if in multimode
Throws
|
#
|
public
|
zdiff(array $keys, array $options = null): array|false
|
#
|
public
|
zSize(string $key): false|int|Redis
Returns
returns Redis if in multimode
Throws
|
#
|
public
|
zScore(string $key, string|mixed $member): float|bool|Redis
Returns the score of a given member in the specified sorted set.
Returns the score of a given member in the specified sorted set.
Returns
false if member or key not exists or Redis if in multimode
Throws
|
#
|
public
|
zRank(string $key, string|mixed $member): int|false|Redis
Returns the rank of a given member in the specified sorted set, starting at 0 for the item
with the smallest score.…
Returns the rank of a given member in the specified sorted set, starting at 0 for the item
with the smallest score. zRevRank starts at 0 for the item with the largest score.
Returns
the item's score, or false if key or member is not exists or Redis if in multimode
Throws
|
#
|
public
|
zRevRank(string $key, string|mixed $member): int|false|Redis
Returns
the item's score, false - if key or member is not exists or Redis if in multimode
Throws
|
#
|
public
|
zIncrBy(string $key, float $value, string|mixed $member): float|Redis
Increments the score of a member from a sorted set by a given amount.
Increments the score of a member from a sorted set by a given amount.
Parameters
$value |
(double) value that will be added to the member's score
|
Returns
the new value or Redis if in multimode
Throws
|
#
|
public
|
zUnionStore(
string $output,
array $zSetKeys,
null|array $weights = null,
string $aggregateFunction = null,
): false|int|Redis
Creates an union of sorted sets given in second argument.
The result of the union will be stored in the sorted set…
Creates an union of sorted sets given in second argument.
The result of the union will be stored in the sorted set defined by the first argument.
The third optionnel argument defines weights to apply to the sorted sets in input.
In this case, the weights will be multiplied by the score of each element in the sorted set
before applying the aggregation. The forth argument defines the AGGREGATE option which
specify how the results of the union are aggregated.
Parameters
$aggregateFunction |
Either "SUM", "MIN", or "MAX": defines the behaviour to use on
duplicate entries during the zUnionStore
|
Returns
The number of values in the new sorted set or Redis if in multimode
Throws
|
#
|
public
|
zUnion(string $Output, array $ZSetKeys, array|null $Weights = null, string $aggregateFunction = 'SUM')
|
#
|
public
|
zInterStore(
string $output,
array $zSetKeys,
null|array $weights = null,
string $aggregateFunction = null,
): false|int|Redis
Creates an intersection of sorted sets given in second argument.
The result of the union will be stored in the sorted…
Creates an intersection of sorted sets given in second argument.
The result of the union will be stored in the sorted set defined by the first argument.
The third optional argument defines weights to apply to the sorted sets in input.
In this case, the weights will be multiplied by the score of each element in the sorted set
before applying the aggregation. The forth argument defines the AGGREGATE option which
specify how the results of the union are aggregated.
Parameters
$aggregateFunction |
Either "SUM", "MIN", or "MAX":
defines the behaviour to use on duplicate entries during the zInterStore.
|
Returns
The number of values in the new sorted set or Redis if in multimode
Throws
|
#
|
public
|
zInter($Output, $ZSetKeys, array|null $Weights = null, string $aggregateFunction = 'SUM')
|
#
|
public
|
zScan(string $key, int &$iterator, string $pattern = null, int $count = 0): array|false|Redis
Scan a sorted set for members, with optional pattern and count
Scan a sorted set for members, with optional pattern and count
Parameters
$key |
String, the set to scan.
|
$iterator |
Long (reference), initialized to NULL.
|
$pattern |
String (optional), the pattern to match.
|
$count |
How many keys to return per iteration (Redis might return a different number).
|
Returns
PHPRedis will return matching keys from Redis, or FALSE when iteration is complete or Redis if in multimode
Throws
|
#
|
public
|
bzPopMax(string|array $key, string|int|array $timeout_or_key, mixed ...$extra_args): false|array|Redis
Block until Redis can pop the highest or lowest scoring members from one or more ZSETs.
There are two commands …
Block until Redis can pop the highest or lowest scoring members from one or more ZSETs.
There are two commands (BZPOPMIN and BZPOPMAX for popping the lowest and highest scoring elements respectively.)
Parameters
Returns
Either an array with the key member and score of the highest or lowest element or an empty array or Redis if in multimode
if the timeout was reached without an element to pop.
Throws
|
#
|
public
|
bzPopMin(string|array $key, string|int|array $timeout_or_key, mixed ...$extra_args): false|array|Redis
Parameters
Returns
Either an array with the key member and score of the highest or lowest element or an empty array or Redis if in multimode
if the timeout was reached without an element to pop.
Throws
|
#
|
public
|
hSet(string $key, string $hashKey, string $value): int|bool|Redis
Adds a value to the hash stored at key. If this value is already in the hash, FALSE is returned.
Adds a value to the hash stored at key. If this value is already in the hash, FALSE is returned.
Returns
returns Redis if in multimode
- 1 if value didn't exist and was added successfully,
- 0 if the value was already present and was replaced, FALSE if there was an error.
Throws
|
#
|
public
|
hSetNx(string $key, string $hashKey, string $value): bool|Redis
Adds a value to the hash stored at key only if this field isn't already in the hash.
Adds a value to the hash stored at key only if this field isn't already in the hash.
Returns
TRUE if the field was set, FALSE if it was already present or Redis if in multimode
Throws
|
#
|
public
|
hGet(string $key, string $hashKey): string|false|Redis
Gets a value from the hash stored at key.
If the hash table doesn't exist, or the key doesn't exist, FALSE is returned.
Gets a value from the hash stored at key.
If the hash table doesn't exist, or the key doesn't exist, FALSE is returned.
Returns
The value, if the command executed successfully BOOL FALSE in case of failure or Redis if in multimode
Throws
|
#
|
public
|
hLen(string $key): int|false|Redis
Returns the length of a hash, in number of items
Returns the length of a hash, in number of items
Returns
the number of items in a hash, FALSE if the key doesn't exist or isn't a hash or Redis if in multimode
Throws
|
#
|
public
|
hDel(string $key, string $hashKey1, string ...$otherHashKeys): int|bool|Redis
Removes a values from the hash stored at key.
If the hash table doesn't exist, or the key doesn't exist, FALSE is…
Removes a values from the hash stored at key.
If the hash table doesn't exist, or the key doesn't exist, FALSE is returned.
Returns
Number of deleted fields or Redis if in multimode
Throws
|
#
|
public
|
hKeys(string $key): array|Redis
Returns the keys in a hash, as an array of strings.
Returns the keys in a hash, as an array of strings.
Returns
An array of elements, the keys of the hash. This works like PHP's array_keys() or Redis if in multimode
Throws
|
#
|
public
|
hVals(string $key): array|Redis
Returns the values in a hash, as an array of strings.
Returns the values in a hash, as an array of strings.
Returns
An array of elements, the values of the hash. This works like PHP's array_values() or Redis if in multimode
Throws
|
#
|
public
|
hGetAll(string $key): array|Redis
Returns the whole hash, as an array of strings indexed by strings.
Returns the whole hash, as an array of strings indexed by strings.
Returns
An array of elements, the contents of the hash or Redis if in multimode
Throws
|
#
|
public
|
hExists(string $key, string $hashKey): bool|Redis
Verify if the specified member exists in a key.
Verify if the specified member exists in a key.
Returns
If the member exists in the hash table, return TRUE, otherwise return FALSE or Redis if in multimode
Throws
|
#
|
public
|
hIncrBy(string $key, string $hashKey, int $value): false|int|Redis
Increments the value of a member from a hash by a given amount.
Increments the value of a member from a hash by a given amount.
Parameters
$value |
(integer) value that will be added to the member's value
|
Returns
the new value or Redis if in multimode
Throws
|
#
|
public
|
hIncrByFloat(string $key, string $field, float $increment): float|Redis
Increment the float value of a hash field by the given amount
Increment the float value of a hash field by the given amount
Returns
returns Redis if in multimode
Throws
|
#
|
public
|
hMSet(string $key, array $hashKeys): bool|Redis
Fills in a whole hash. Non-string values are converted to string, using the standard (string) cast.
NULL values are…
Fills in a whole hash. Non-string values are converted to string, using the standard (string) cast.
NULL values are stored as empty strings
Parameters
$hashKeys |
key → value array
|
Returns
returns Redis if in multimode
Throws
|
#
|
public
|
hMGet(string $key, array $hashKeys): array|Redis
Retrieve the values associated to the specified fields in the hash.
Retrieve the values associated to the specified fields in the hash.
Returns
Array An array of elements, the values of the specified fields in the hash, or Redis if in multimode
with the hash keys as array keys.
Throws
|
#
|
public
|
hScan(string $key, int &$iterator, string $pattern = null, int $count = 0): array|bool|Redis
Scan a HASH value for members, with an optional pattern and count.
Scan a HASH value for members, with an optional pattern and count.
Parameters
$pattern |
Optional pattern to match against.
|
$count |
How many keys to return in a go (only a sugestion to Redis).
|
Returns
An array of members that match our pattern or Redis if in multimode
Throws
|
#
|
public
|
hStrLen(string $key, string $field): false|int|Redis
Get the string length of the value associated with field in the hash stored at key
Get the string length of the value associated with field in the hash stored at key
Returns
the string length of the value associated with field, or zero when field is not present in the hash or Redis if in multimode
or key does not exist at all.
Throws
|
#
|
public
|
geoAdd(string $key, float $longitude, float $latitude, string $member, mixed ...$other_triples): false|int|Redis
Add one or more geospatial items to the specified key.
This function must be called with at least one longitude,…
Add one or more geospatial items to the specified key.
This function must be called with at least one longitude, latitude, member triplet.
Returns
The number of elements added to the geospatial key or Redis if in multimode
Throws
|
#
|
public
|
geoHash(string $key, string ...$member): false|array|Redis
Retrieve Geohash strings for one or more elements of a geospatial index.
Retrieve Geohash strings for one or more elements of a geospatial index.
Parameters
...$member |
variadic list of members
|
Returns
One or more Redis Geohash encoded strings or Redis if in multimode
Throws
|
#
|
public
|
geoPos(string $key, string ...$member): array|Redis
Return longitude, latitude positions for each requested member.
Return longitude, latitude positions for each requested member.
Returns
One or more longitude/latitude positions or Redis if in multimode
Throws
|
#
|
public
|
geosearch(string $key, array|string $position, array|int|float $shape, string $unit, array $options = []): array|false
|
#
|
public
|
geosearchstore(
string $dst,
string $src,
array|string $position,
array|int|float $shape,
string $unit,
array $options = [],
): array|false
|
#
|
public
|
geoDist(string $key, string $member1, string $member2, string|null $unit = null): float|Redis
Return the distance between two members in a geospatial set.
Return the distance between two members in a geospatial set.
If units are passed it must be one of the following values:
- 'm' => Meters
- 'km' => Kilometers
- 'mi' => Miles
- 'ft' => Feet
Returns
The distance between the two passed members in the units requested (meters by default) or Redis if in multimode
Throws
|
#
|
public
|
geoRadius($key, $longitude, $latitude, $radius, $unit, array|null $options = []): mixed|Redis
Return members of a set with geospatial information that are within the radius specified by the caller.
Return members of a set with geospatial information that are within the radius specified by the caller.
Returns
When no STORE option is passed, this function returns an array of results or Redis if in multimode
If it is passed this function returns the number of stored entries.
Throws
|
#
|
public
|
geoRadiusByMember(string $key, string $member, $radius, $units, array|null $options = []): array|Redis
This method is identical to geoRadius except that instead of passing a longitude and latitude as the "source"
you pass…
This method is identical to geoRadius except that instead of passing a longitude and latitude as the "source"
you pass an existing member in the geospatial set
Parameters
Returns
The zero or more entries that are close enough to the member given the distance and radius specified or Redis if in multimode
Throws
|
#
|
public
|
config(string $operation, string $key, string|mixed $value = null): array|Redis
Get or Set the redis config keys.
Get or Set the redis config keys.
Parameters
$operation |
either GET or SET
|
$key |
for SET , glob-pattern for GET
|
$value |
optional string (only for SET )
|
Returns
Associative array for GET , key -> value or Redis if in multimode
Throws
|
#
|
public
|
eval(string $script, array $args = [], int $numKeys = 0): mixed|Redis
Evaluate a LUA script serverside
Evaluate a LUA script serverside
Returns
What is returned depends on what the LUA script itself returns, which could be a scalar value or Redis if in multimode
(int/string), or an array. Arrays that are returned can also contain other arrays, if that's how it was set up in
your LUA script. If there is an error executing the LUA script, the getLastError() function can tell you the
message that came back from Redis (e.g. compile error).
Throws
|
#
|
public
|
evaluate(string $script, array $args = [], int $numKeys = 0): mixed|Redis
Returns
@see eval() , returns Redis if in multimode
Throws
|
#
|
public
|
evalSha(string $scriptSha, array $args = [], int $numKeys = 0): mixed|Redis
Evaluate a LUA script serverside, from the SHA1 hash of the script instead of the script itself.
In order to run this…
Evaluate a LUA script serverside, from the SHA1 hash of the script instead of the script itself.
In order to run this command Redis will have to have already loaded the script, either by running it or via
the SCRIPT LOAD command.
Returns
@see eval() , returns Redis if in multimode
Throws
|
#
|
public
|
evaluateSha(string $scriptSha, array $args = [], int $numKeys = 0)
|
#
|
public
|
script(string $command, mixed ...$script): mixed|Redis
Execute the Redis SCRIPT command to perform various operations on the scripting subsystem.
Execute the Redis SCRIPT command to perform various operations on the scripting subsystem.
Parameters
$command |
load | flush | kill | exists
|
Returns
returns Redis if in multimode
Throws
|
#
|
public
|
getLastError(): string|null
The last error message (if any)
The last error message (if any)
Returns
A string with the last returned script based error message, or NULL if there is no error
Throws
|
#
|
public
|
clearLastError(): bool
Clear the last error message
Clear the last error message
Returns
Throws
|
#
|
public
|
client(string $command, string $value = null): mixed
Issue the CLIENT command with various arguments.
The Redis CLIENT command can be used in four ways:
- CLIENT LIST
-…
Issue the CLIENT command with various arguments.
The Redis CLIENT command can be used in four ways:
- CLIENT LIST
- CLIENT GETNAME
- CLIENT SETNAME [name]
- CLIENT KILL [ip:port]
Returns
This will vary depending on which client command was executed:
- CLIENT LIST will return an array of arrays with client information.
- CLIENT GETNAME will return the client name or false if none has been set
- CLIENT SETNAME will return true if it can be set and false if not
- CLIENT KILL will return true if the client can be killed, and false if not
Throws
|
#
|
public
|
_prefix(string $value): string
A utility method to prefix the value with the prefix setting for phpredis.
A utility method to prefix the value with the prefix setting for phpredis.
Parameters
$value |
The value you wish to prefix
|
Returns
If a prefix is set up, the value now prefixed
If there is no prefix, the value will be returned unchanged.
Throws
|
#
|
public
|
_unserialize(string $value): mixed
A utility method to unserialize data with whatever serializer is set up. If there is no serializer set, the
value will…
A utility method to unserialize data with whatever serializer is set up. If there is no serializer set, the
value will be returned unchanged. If there is a serializer set up, and the data passed in is malformed, an
exception will be thrown. This can be useful if phpredis is serializing values, and you return something from
redis in a LUA script that is serialized.
Parameters
$value |
The value to be unserialized
|
|
#
|
public
|
_serialize(mixed $value): mixed
A utility method to serialize values manually. This method allows you to serialize a value with whatever
serializer is…
A utility method to serialize values manually. This method allows you to serialize a value with whatever
serializer is configured, manually. This can be useful for serialization/unserialization of data going in
and out of EVAL commands as phpredis can't automatically do this itself. Note that if no serializer is
set, phpredis will change Array values to 'Array', and Objects to 'Object'.
Parameters
$value |
The value to be serialized.
|
|
#
|
public
|
dump(string $key): string|false
Dump a key out of a redis database, the value of which can later be passed into redis using the RESTORE command.
The…
Dump a key out of a redis database, the value of which can later be passed into redis using the RESTORE command.
The data that comes out of DUMP is a binary representation of the key as Redis stores it.
Returns
The Redis encoded value of the key, or FALSE if the key doesn't exist
Throws
|
#
|
public
|
restore(string $key, int $ttl, string $value): bool
Restore a key from the result of a DUMP operation.
Restore a key from the result of a DUMP operation.
Parameters
$key |
The key name
|
$ttl |
How long the key should live (if zero, no expire will be set on the key)
|
$value |
(binary). The Redis encoded key value (from DUMP)
|
Throws
|
#
|
public
|
migrate(string $host, int $port, string $key, int $db, int $timeout, bool $copy = false, bool $replace = false): bool
Migrates a key to a different Redis instance.
Migrates a key to a different Redis instance.
Parameters
$host |
The destination host
|
$port |
The TCP port to connect to.
|
$key |
The key to migrate.
|
$db |
The target DB.
|
$timeout |
The maximum amount of time given to this transfer.
|
$copy |
Should we send the COPY flag to redis.
|
$replace |
Should we send the REPLACE flag to redis.
|
Throws
|
#
|
public
|
time(): false|array
Return the current Redis server time.
Return the current Redis server time.
Returns
If successful, the time will come back as an associative array with element zero being the
unix timestamp, and element one being microseconds.
Throws
|
#
|
public
|
scan(int &$iterator, string $pattern = null, int $count = 0): array|false|Redis
Scan the keyspace for keys
Scan the keyspace for keys
Parameters
$iterator |
Iterator, initialized to NULL.
|
$pattern |
Pattern to match.
|
$count |
Count of keys per iteration (only a suggestion to Redis).
|
Returns
This function will return an array of keys or FALSE if there are no more keys or Redis if in multimode
Throws
|
#
|
public
|
pfAdd(string $key, array $elements): bool|Redis
Adds all the element arguments to the HyperLogLog data structure stored at the key.
Adds all the element arguments to the HyperLogLog data structure stored at the key.
Returns
returns Redis if in multimode
Throws
|
#
|
public
|
pfCount(string|array $key): false|int|Redis
When called with a single key, returns the approximated cardinality computed by the HyperLogLog data
structure stored…
When called with a single key, returns the approximated cardinality computed by the HyperLogLog data
structure stored at the specified variable, which is 0 if the variable does not exist.
Returns
returns Redis if in multimode
Throws
|
#
|
public
|
pfMerge(string $destKey, array $sourceKeys): bool|Redis
Merge multiple HyperLogLog values into an unique value that will approximate the cardinality
of the union of the…
Merge multiple HyperLogLog values into an unique value that will approximate the cardinality
of the union of the observed Sets of the source HyperLogLog structures.
Returns
returns Redis if in multimode
Throws
|
#
|
public
|
rawCommand(string $command, mixed ...$arguments): mixed|Redis
Send arbitrary things to the redis server.
Send arbitrary things to the redis server.
Parameters
$command |
Required command to send to the server.
|
...$arguments |
Optional variable amount of arguments to send to the server.
|
Returns
returns Redis if in multimode
Throws
|
#
|
public
|
getMode(): false|int|Redis
Detect whether we're in ATOMIC/MULTI/PIPELINE mode.
Detect whether we're in ATOMIC/MULTI/PIPELINE mode.
Returns
Either Redis::ATOMIC, Redis::MULTI or Redis::PIPELINE or Redis if in multimode
Throws
|
#
|
public
|
xAck(string $stream, string $group, array $messages): false|int|Redis
Acknowledge one or more messages on behalf of a consumer group.
Acknowledge one or more messages on behalf of a consumer group.
Returns
The number of messages Redis reports as acknowledged or Redis if in multimode
Throws
|
#
|
public
|
xAdd(
string $key,
string $id,
array $messages,
int $maxLen = 0,
bool $isApproximate = false,
bool $nomkstream = false,
): string|Redis
Add a message to a stream
Add a message to a stream
Returns
The added message ID or Redis if in multimode
Throws
|
#
|
public
|
xClaim(string $key, string $group, string $consumer, int $min_iddle, array $ids, array $options): false|array|Redis
Claim ownership of one or more pending messages
Claim ownership of one or more pending messages
Parameters
$options |
['IDLE' => $value, 'TIME' => $value, 'RETRYCOUNT' => $value, 'FORCE', 'JUSTID']
|
Returns
Either an array of message IDs along with corresponding data, or just an array of IDs or Redis if in multimode
(if the 'JUSTID' option was passed).
Throws
|
#
|
public
|
xDel(string $key, array $ids): false|int|Redis
Delete one or more messages from a stream
Delete one or more messages from a stream
Returns
The number of messages removed or Redis if in multimode
Throws
|
#
|
public
|
xGroup(
string $operation,
string $key = null,
string $group = null,
string $msgId = null,
bool $mkStream = false,
): mixed|Redis
Parameters
$operation |
e.g.: 'HELP', 'SETID', 'DELGROUP', 'CREATE', 'DELCONSUMER'
|
Returns
This command returns different types depending on the specific XGROUP command executed or Redis if in multimode
Throws
|
#
|
public
|
xInfo(string $operation, string $stream = null, string $group = null): mixed|Redis
Get information about a stream or consumer groups
Get information about a stream or consumer groups
Parameters
$operation |
e.g.: 'CONSUMERS', 'GROUPS', 'STREAM', 'HELP'
|
Returns
This command returns different types depending on which subcommand is used or Redis if in multimode
Throws
|
#
|
public
|
xLen(string $stream): false|int|Redis
Get the length of a given stream.
Get the length of a given stream.
Returns
The number of messages in the stream or Redis if in multimode
Throws
|
#
|
public
|
xPending(
string $stream,
string $group,
string $start = null,
string $end = null,
int $count = -1,
string $consumer = null,
): array|string|Redis
Get information about pending messages in a given stream
Get information about pending messages in a given stream
Returns
Information about the pending messages, in various forms depending on or Redis if in multimode
the specific invocation of XPENDING.
Throws
|
#
|
public
|
xRange(string $stream, string $start, string $end, int $count = -1): array|bool|Redis
Get a range of messages from a given stream
Get a range of messages from a given stream
Returns
The messages in the stream within the requested range or Redis if in multimode
Throws
|
#
|
public
|
xRead(array $streams, int|string $count = -1, int|string $block = -1): array|bool|Redis
Read data from one or more streams and only return IDs greater than sent in the command.
Read data from one or more streams and only return IDs greater than sent in the command.
Returns
The messages in the stream newer than the IDs passed to Redis (if any) or Redis if in multimode
Throws
|
#
|
public
|
xReadGroup(string $group, string $consumer, array $streams, int|null $count = 1, int|null $block = 1): array|Redis
This method is similar to xRead except that it supports reading messages for a specific consumer group.
This method is similar to xRead except that it supports reading messages for a specific consumer group.
Returns
The messages delivered to this consumer group (if any) or Redis if in multimode
Throws
|
#
|
public
|
xRevRange(string $stream, string $end, string $start, int $count = -1): array|bool|Redis
This is identical to xRange except the results come back in reverse order.
Also note that Redis reverses the order of …
This is identical to xRange except the results come back in reverse order.
Also note that Redis reverses the order of "start" and "end".
Returns
The messages in the range specified or Redis if in multimode
Throws
|
#
|
public
|
xTrim(string $stream, int $maxLen, bool $isApproximate): false|int|Redis
Trim the stream length to a given maximum.
If the "approximate" flag is pasesed, Redis will use your size as a hint but…
Trim the stream length to a given maximum.
If the "approximate" flag is pasesed, Redis will use your size as a hint but only trim trees in whole nodes
(this is more efficient)
Returns
The number of messages trimed from the stream or Redis if in multimode
Throws
|
#
|
public
|
sAddArray(string $key, array $values): int|bool|Redis
Adds a values to the set value stored at key.
Adds a values to the set value stored at key.
Parameters
$key |
Required key
|
$values |
Required values
|
Returns
The number of elements added to the set or Redis if in multimode
If this value is already in the set, FALSE is returned
Throws
|
#
|