Class yii\redis\Connection

Inheritanceyii\redis\Connection » yii\base\Component
Available since extension's version2.0
Source Code https://github.com/yiisoft/yii2-redis/blob/master/src/Connection.php

The redis connection class is used to establish a connection to a redis server.

By default it assumes there is a redis server running on localhost at port 6379 and uses the database number 0.

It is possible to connect to a redis server using $hostname and $port or using a $unixSocket.

It also supports the AUTH command of redis. When the server needs authentication, you can set the $password property to authenticate with the server after connect.

The execution of redis commands is possible with via executeCommand().

Public Properties

Hide inherited properties

Property Type Description Defined By
$connectionString string Socket connection string. yii\redis\Connection
$connectionTimeout float Timeout to use for connection to redis. yii\redis\Connection
$contextOptions array PHP context options which are used in the Redis connection stream. yii\redis\Connection
$dataTimeout float Timeout to use for redis socket when reading and writing data. yii\redis\Connection
$database integer The redis database to use. yii\redis\Connection
$driverName string Name of the DB driver. yii\redis\Connection
$hostname string The hostname or ip address to use for connecting to the redis server. yii\redis\Connection
$isActive boolean Whether the DB connection is established. yii\redis\Connection
$luaScriptBuilder yii\redis\LuaScriptBuilder yii\redis\Connection
$password string The password for establishing DB connection. yii\redis\Connection
$port integer The port to use for connecting to the redis server. yii\redis\Connection
$redirectConnectionString string If the query gets redirected, use this as the temporary new hostname yii\redis\Connection
$redisCommands array List of available redis commands. yii\redis\Connection
$retries integer The number of times a command execution should be retried when a connection failure occurs. yii\redis\Connection
$retryInterval integer The retry interval in microseconds to wait between retry. yii\redis\Connection
$scheme string The connection scheme used for connecting to the redis server. yii\redis\Connection
$socket resource|false yii\redis\Connection
$socketClientFlags integer Bitmask field which may be set to any combination of connection flags passed to stream_socket_client(). yii\redis\Connection
$unixSocket string The unix socket path (e.g. /var/run/redis/redis.sock) to use for connecting to the redis server. yii\redis\Connection
$useSSL boolean Send sockets over SSL protocol. yii\redis\Connection
$username string|null Username for establishing DB connection. yii\redis\Connection

Public Methods

Hide inherited methods

Method Description Defined By
__call() Allows issuing all supported commands via magic methods. yii\redis\Connection
__sleep() Closes the connection when this component is being serialized. yii\redis\Connection
append() Append a value to a key. yii\redis\Connection
auth() Authenticate to the server. yii\redis\Connection
bgrewriteaof() Asynchronously rewrite the append-only file. yii\redis\Connection
bgsave() Asynchronously save the dataset to disk. yii\redis\Connection
bitcount() Count set bits in a string. yii\redis\Connection
bitfield() Perform arbitrary bitfield integer operations on strings. yii\redis\Connection
bitop() Perform bitwise operations between strings. yii\redis\Connection
bitpos() Find first bit set or clear in a string. yii\redis\Connection
blpop() Remove and get the first element in a list, or block until one is available. yii\redis\Connection
brpop() Remove and get the last element in a list, or block until one is available. yii\redis\Connection
brpoplpush() Pop a value from a list, push it to another list and return it; or block until one is available. yii\redis\Connection
clientGetname() Get the current connection name. yii\redis\Connection
clientKill() Kill the connection of a client. yii\redis\Connection
clientList() Get the list of client connections. yii\redis\Connection
clientPause() Stop processing commands from clients for some time. yii\redis\Connection
clientReply() Instruct the server whether to reply to commands. yii\redis\Connection
clientSetname() Set the current connection name. yii\redis\Connection
close() Closes the currently active DB connection. yii\redis\Connection
clusterAddslots() Assign new hash slots to receiving node. yii\redis\Connection
clusterCountkeysinslot() Return the number of local keys in the specified hash slot. yii\redis\Connection
clusterDelslots() Set hash slots as unbound in receiving node. yii\redis\Connection
clusterFailover() Forces a slave to perform a manual failover of its master.. yii\redis\Connection
clusterForget() Remove a node from the nodes table. yii\redis\Connection
clusterGetkeysinslot() Return local key names in the specified hash slot. yii\redis\Connection
clusterInfo() Provides info about Redis Cluster node state. yii\redis\Connection
clusterKeyslot() Returns the hash slot of the specified key. yii\redis\Connection
clusterMeet() Force a node cluster to handshake with another node. yii\redis\Connection
clusterNodes() Get Cluster config for the node. yii\redis\Connection
clusterReplicate() Reconfigure a node as a slave of the specified master node. yii\redis\Connection
clusterReset() Reset a Redis Cluster node. yii\redis\Connection
clusterSaveconfig() Forces the node to save cluster state on disk. yii\redis\Connection
clusterSetslot() Bind a hash slot to a specific node. yii\redis\Connection
clusterSlaves() List slave nodes of the specified master node. yii\redis\Connection
clusterSlots() Get array of Cluster slot to node mappings. yii\redis\Connection
command() Get array of Redis command details. yii\redis\Connection
commandCount() Get total number of Redis commands. yii\redis\Connection
commandGetkeys() Extract keys given a full Redis command. yii\redis\Connection
commandInfo() Get array of specific Redis command details. yii\redis\Connection
configGet() Get the value of a configuration parameter. yii\redis\Connection
configResetstat() Reset the stats returned by INFO. yii\redis\Connection
configRewrite() Rewrite the configuration file with the in memory configuration. yii\redis\Connection
configSet() Set a configuration parameter to the given value. yii\redis\Connection
dbsize() Return the number of keys in the selected database. yii\redis\Connection
debugObject() Get debugging information about a key. yii\redis\Connection
debugSegfault() Make the server crash. yii\redis\Connection
decr() Decrement the integer value of a key by one. yii\redis\Connection
decrby() Decrement the integer value of a key by the given number. yii\redis\Connection
del() Delete a key. yii\redis\Connection
discard() Discard all commands issued after MULTI. yii\redis\Connection
dump() Return a serialized version of the value stored at the specified key.. yii\redis\Connection
echo() Echo the given string. yii\redis\Connection
eval() Execute a Lua script server side. yii\redis\Connection
evalsha() Execute a Lua script server side. yii\redis\Connection
exec() Execute all commands issued after MULTI. yii\redis\Connection
executeCommand() Executes a redis command. yii\redis\Connection
exists() Determine if a key exists. yii\redis\Connection
expire() Set a key's time to live in seconds. yii\redis\Connection
expireat() Set the expiration for a key as a UNIX timestamp. yii\redis\Connection
flushall() Remove all keys from all databases. yii\redis\Connection
flushdb() Remove all keys from the current database. yii\redis\Connection
geoadd() Add one or more geospatial items in the geospatial index represented using a sorted set. yii\redis\Connection
geodist() Returns the distance between two members of a geospatial index. yii\redis\Connection
geohash() Returns members of a geospatial index as standard geohash strings. yii\redis\Connection
geopos() Returns longitude and latitude of members of a geospatial index. yii\redis\Connection
georadius() Query a sorted set representing a geospatial index to fetch members matching a given maximum distance from a point. yii\redis\Connection
georadiusbymember() Query a sorted set representing a geospatial index to fetch members matching a given maximum distance from a member. yii\redis\Connection
get() Get the value of a key. yii\redis\Connection
getConnectionString() Return the connection string used to open a socket connection. During a redirect (cluster mode) this will be the target of the redirect. yii\redis\Connection
getDriverName() Returns the name of the DB driver for the current dsn. yii\redis\Connection
getIsActive() Returns a value indicating whether the DB connection is established. yii\redis\Connection
getLuaScriptBuilder() yii\redis\Connection
getSocket() Return the connection resource if a connection to the target has been established before, false otherwise. yii\redis\Connection
getbit() Returns the bit value at offset in the string value stored at key. yii\redis\Connection
getrange() Get a substring of the string stored at a key. yii\redis\Connection
getset() Set the string value of a key and return its old value. yii\redis\Connection
hdel() Delete one or more hash fields. yii\redis\Connection
hexists() Determine if a hash field exists. yii\redis\Connection
hget() Get the value of a hash field. yii\redis\Connection
hgetall() Get all the fields and values in a hash. yii\redis\Connection
hincrby() Increment the integer value of a hash field by the given number. yii\redis\Connection
hincrbyfloat() Increment the float value of a hash field by the given amount. yii\redis\Connection
hkeys() Get all the fields in a hash. yii\redis\Connection
hlen() Get the number of fields in a hash. yii\redis\Connection
hmget() Get the values of all the given hash fields. yii\redis\Connection
hmset() Set multiple hash fields to multiple values. yii\redis\Connection
hscan() Incrementally iterate hash fields and associated values. yii\redis\Connection
hset() Set the string value of a hash field. yii\redis\Connection
hsetnx() Set the value of a hash field, only if the field does not exist. yii\redis\Connection
hstrlen() Get the length of the value of a hash field. yii\redis\Connection
hvals() Get all the values in a hash. yii\redis\Connection
incr() Increment the integer value of a key by one. yii\redis\Connection
incrby() Increment the integer value of a key by the given amount. yii\redis\Connection
incrbyfloat() Increment the float value of a key by the given amount. yii\redis\Connection
info() Get information and statistics about the server. yii\redis\Connection
keys() Find all keys matching the given pattern. yii\redis\Connection
lastsave() Get the UNIX time stamp of the last successful save to disk. yii\redis\Connection
lindex() Get an element from a list by its index. yii\redis\Connection
linsert() Insert an element before or after another element in a list. yii\redis\Connection
llen() Get the length of a list. yii\redis\Connection
lpop() Remove and get the first element in a list. yii\redis\Connection
lpush() Prepend one or multiple values to a list. yii\redis\Connection
lpushx() Prepend a value to a list, only if the list exists. yii\redis\Connection
lrange() Get a range of elements from a list. yii\redis\Connection
lrem() Remove elements from a list. yii\redis\Connection
lset() Set the value of an element in a list by its index. yii\redis\Connection
ltrim() Trim a list to the specified range. yii\redis\Connection
mget() Get the values of all the given keys. yii\redis\Connection
migrate() Atomically transfer a key from a Redis instance to another one.. yii\redis\Connection
monitor() Listen for all requests received by the server in real time. yii\redis\Connection
move() Move a key to another database. yii\redis\Connection
mset() Set multiple keys to multiple values. yii\redis\Connection
msetnx() Set multiple keys to multiple values, only if none of the keys exist. yii\redis\Connection
multi() Mark the start of a transaction block. yii\redis\Connection
object() Inspect the internals of Redis objects. yii\redis\Connection
open() Establishes a DB connection. yii\redis\Connection
persist() Remove the expiration from a key. yii\redis\Connection
pexpire() Set a key's time to live in milliseconds. yii\redis\Connection
pexpireat() Set the expiration for a key as a UNIX timestamp specified in milliseconds. yii\redis\Connection
pfadd() Adds the specified elements to the specified HyperLogLog.. yii\redis\Connection
pfcount() Return the approximated cardinality of the set(s) observed by the HyperLogLog at key(s).. yii\redis\Connection
pfmerge() Merge N different HyperLogLogs into a single one.. yii\redis\Connection
ping() Ping the server. yii\redis\Connection
psetex() Set the value and expiration in milliseconds of a key. yii\redis\Connection
psubscribe() Listen for messages published to channels matching the given patterns. yii\redis\Connection
pttl() Get the time to live for a key in milliseconds. yii\redis\Connection
publish() Post a message to a channel. yii\redis\Connection
pubsub() Inspect the state of the Pub/Sub subsystem. yii\redis\Connection
punsubscribe() Stop listening for messages posted to channels matching the given patterns. yii\redis\Connection
quit() Close the connection. yii\redis\Connection
randomkey() Return a random key from the keyspace. yii\redis\Connection
readonly() Enables read queries for a connection to a cluster slave node. yii\redis\Connection
readwrite() Disables read queries for a connection to a cluster slave node. yii\redis\Connection
rename() Rename a key. yii\redis\Connection
renamenx() Rename a key, only if the new key does not exist. yii\redis\Connection
restore() Create a key using the provided serialized value, previously obtained using DUMP.. yii\redis\Connection
role() Return the role of the instance in the context of replication. yii\redis\Connection
rpop() Remove and get the last element in a list. yii\redis\Connection
rpoplpush() Remove the last element in a list, prepend it to another list and return it. yii\redis\Connection
rpush() Append one or multiple values to a list. yii\redis\Connection
rpushx() Append a value to a list, only if the list exists. yii\redis\Connection
sadd() Add one or more members to a set. yii\redis\Connection
save() Synchronously save the dataset to disk. yii\redis\Connection
scan() Incrementally iterate the keys space. yii\redis\Connection
scard() Get the number of members in a set. yii\redis\Connection
scriptDebug() Set the debug mode for executed scripts.. yii\redis\Connection
scriptExists() Check existence of scripts in the script cache.. yii\redis\Connection
scriptFlush() Remove all the scripts from the script cache.. yii\redis\Connection
scriptKill() Kill the script currently in execution.. yii\redis\Connection
scriptLoad() Load the specified Lua script into the script cache.. yii\redis\Connection
sdiff() Subtract multiple sets. yii\redis\Connection
sdiffstore() Subtract multiple sets and store the resulting set in a key. yii\redis\Connection
select() Change the selected database for the current connection. yii\redis\Connection
set() Set the string value of a key. yii\redis\Connection
setbit() Sets or clears the bit at offset in the string value stored at key. yii\redis\Connection
setex() Set the value and expiration of a key. yii\redis\Connection
setnx() Set the value of a key, only if the key does not exist. yii\redis\Connection
setrange() Overwrite part of a string at key starting at the specified offset. yii\redis\Connection
shutdown() Synchronously save the dataset to disk and then shut down the server. yii\redis\Connection
sinter() Intersect multiple sets. yii\redis\Connection
sinterstore() Intersect multiple sets and store the resulting set in a key. yii\redis\Connection
sismember() Determine if a given value is a member of a set. yii\redis\Connection
slaveof() Make the server a slave of another instance, or promote it as master. yii\redis\Connection
slowlog() Manages the Redis slow queries log. yii\redis\Connection
smembers() Get all the members in a set. yii\redis\Connection
smove() Move a member from one set to another. yii\redis\Connection
sort() Sort the elements in a list, set or sorted set. yii\redis\Connection
spop() Remove and return one or multiple random members from a set. yii\redis\Connection
srandmember() Get one or multiple random members from a set. yii\redis\Connection
srem() Remove one or more members from a set. yii\redis\Connection
sscan() Incrementally iterate Set elements. yii\redis\Connection
strlen() Get the length of the value stored in a key. yii\redis\Connection
subscribe() Listen for messages published to the given channels. yii\redis\Connection
sunion() Add multiple sets. yii\redis\Connection
sunionstore() Add multiple sets and store the resulting set in a key. yii\redis\Connection
swapdb() Swaps two Redis databases. yii\redis\Connection
sync() Internal command used for replication. yii\redis\Connection
time() Return the current server time. yii\redis\Connection
touch() Alters the last access time of a key(s). yii\redis\Connection
ttl() Get the time to live for a key. yii\redis\Connection
type() Determine the type stored at key. yii\redis\Connection
unlink() Delete a key asynchronously in another thread. yii\redis\Connection
unsubscribe() Stop listening for messages posted to the given channels. yii\redis\Connection
unwatch() Forget about all watched keys. yii\redis\Connection
wait() Wait for the synchronous replication of all the write commands sent in the context of the current connection. yii\redis\Connection
watch() Watch the given keys to determine execution of the MULTI/EXEC block. yii\redis\Connection
xack() Removes one or multiple messages from the pending entries list (PEL) of a stream consumer group https://redis.io/commands/xack yii\redis\Connection
xadd() Appends the specified stream entry to the stream at the specified key https://redis.io/commands/xadd yii\redis\Connection
xclaim() Changes the ownership of a pending message, so that the new owner is the consumer specified as the command argument https://redis.io/commands/xclaim yii\redis\Connection
xdel() Removes the specified entries from a stream, and returns the number of entries deleted https://redis.io/commands/xdel yii\redis\Connection
xgroup() Manages the consumer groups associated with a stream data structure https://redis.io/commands/xgroup yii\redis\Connection
xinfo() Retrieves different information about the streams and associated consumer groups https://redis.io/commands/xinfo yii\redis\Connection
xlen() Returns the number of entries inside a stream https://redis.io/commands/xlen yii\redis\Connection
xpending() Fetching data from a stream via a consumer group, and not acknowledging such data, has the effect of creating pending entries https://redis.io/commands/xpending yii\redis\Connection
xrange() Returns the stream entries matching a given range of IDs https://redis.io/commands/xrange yii\redis\Connection
xread() Read data from one or multiple streams, only returning entries with an ID greater than the last received ID reported by the caller https://redis.io/commands/xread yii\redis\Connection
xreadgroup() Special version of the XREAD command with support for consumer groups https://redis.io/commands/xreadgroup yii\redis\Connection
xrevrange() Exactly like XRANGE, but with the notable difference of returning the entries in reverse order, and also taking the start-end range in reverse order https://redis.io/commands/xrevrange yii\redis\Connection
xtrim() Trims the stream to a given number of items, evicting older items (items with lower IDs) if needed https://redis.io/commands/xtrim yii\redis\Connection
zadd() Add one or more members to a sorted set, or update its score if it already exists. yii\redis\Connection
zcard() Get the number of members in a sorted set. yii\redis\Connection
zcount() Count the members in a sorted set with scores within the given values. yii\redis\Connection
zincrby() Increment the score of a member in a sorted set. yii\redis\Connection
zinterstore() Intersect multiple sorted sets and store the resulting sorted set in a new key. yii\redis\Connection
zlexcount() Count the number of members in a sorted set between a given lexicographical range. yii\redis\Connection
zrange() Return a range of members in a sorted set, by index. yii\redis\Connection
zrangebylex() Return a range of members in a sorted set, by lexicographical range. yii\redis\Connection
zrangebyscore() Return a range of members in a sorted set, by score. yii\redis\Connection
zrank() Determine the index of a member in a sorted set. yii\redis\Connection
zrem() Remove one or more members from a sorted set. yii\redis\Connection
zremrangebylex() Remove all members in a sorted set between the given lexicographical range. yii\redis\Connection
zremrangebyrank() Remove all members in a sorted set within the given indexes. yii\redis\Connection
zremrangebyscore() Remove all members in a sorted set within the given scores. yii\redis\Connection
zrevrange() Return a range of members in a sorted set, by index, with scores ordered from high to low. yii\redis\Connection
zrevrangebylex() Return a range of members in a sorted set, by lexicographical range, ordered from higher to lower strings.. yii\redis\Connection
zrevrangebyscore() Return a range of members in a sorted set, by score, with scores ordered from high to low. yii\redis\Connection
zrevrank() Determine the index of a member in a sorted set, with scores ordered from high to low. yii\redis\Connection
zscan() Incrementally iterate sorted sets elements and associated scores. yii\redis\Connection
zscore() Get the score associated with the given member in a sorted set. yii\redis\Connection
zunionstore() Add multiple sorted sets and store the resulting sorted set in a new key. yii\redis\Connection

Protected Methods

Hide inherited methods

Method Description Defined By
initConnection() Initializes the DB connection. yii\redis\Connection
sendRawCommand() Sends RAW command string to the server. yii\redis\Connection

Events

Hide inherited events

Event Type Description Defined By
EVENT_AFTER_OPEN yii\redis\Event An event that is triggered after a DB connection is established yii\redis\Connection

Property Details

Hide inherited properties

$connectionString public property

Socket connection string.

public string $connectionString null
$connectionTimeout public property

Timeout to use for connection to redis. If not set the timeout set in php.ini will be used: ini_get("default_socket_timeout").

public float $connectionTimeout null
$contextOptions public property (available since version 2.0.15)

PHP context options which are used in the Redis connection stream.

See also https://www.php.net/manual/en/context.ssl.php.

public array $contextOptions = []
$dataTimeout public property

Timeout to use for redis socket when reading and writing data. If not set the php default value will be used.

public float $dataTimeout null
$database public property

The redis database to use. This is an integer value starting from 0. Defaults to 0. Since version 2.0.6 you can disable the SELECT command sent after connection by setting this property to null.

public integer $database 0
$driverName public property

Name of the DB driver.

public string $driverName null
$hostname public property

The hostname or ip address to use for connecting to the redis server. Defaults to 'localhost'. If $unixSocket is specified, hostname and $port will be ignored.

public string $hostname 'localhost'
$isActive public property

Whether the DB connection is established.

public boolean $isActive null
$luaScriptBuilder public property
$password public property

The password for establishing DB connection. Defaults to null meaning no AUTH command is sent. See https://redis.io/commands/auth

public string $password null
$port public property

The port to use for connecting to the redis server. Default port is 6379. If $unixSocket is specified, $hostname and port will be ignored.

public integer $port 6379
$redirectConnectionString public property (available since version 2.0.11)

If the query gets redirected, use this as the temporary new hostname

$redisCommands public property

List of available redis commands.

See also https://redis.io/commands.

public array $redisCommands = [
    
'APPEND',
    
'AUTH',
    
'BGREWRITEAOF',
    
'BGSAVE',
    
'BITCOUNT',
    
'BITFIELD',
    
'BITOP',
    
'BITPOS',
    
'BLPOP',
    
'BRPOP',
    
'BRPOPLPUSH',
    
'CLIENT KILL',
    
'CLIENT LIST',
    
'CLIENT GETNAME',
    
'CLIENT PAUSE',
    
'CLIENT REPLY',
    
'CLIENT SETNAME',
    
'CLUSTER ADDSLOTS',
    
'CLUSTER COUNTKEYSINSLOT',
    
'CLUSTER DELSLOTS',
    
'CLUSTER FAILOVER',
    
'CLUSTER FORGET',
    
'CLUSTER GETKEYSINSLOT',
    
'CLUSTER INFO',
    
'CLUSTER KEYSLOT',
    
'CLUSTER MEET',
    
'CLUSTER NODES',
    
'CLUSTER REPLICATE',
    
'CLUSTER RESET',
    
'CLUSTER SAVECONFIG',
    
'CLUSTER SETSLOT',
    
'CLUSTER SLAVES',
    
'CLUSTER SLOTS',
    
'COMMAND',
    
'COMMAND COUNT',
    
'COMMAND GETKEYS',
    
'COMMAND INFO',
    
'CONFIG GET',
    
'CONFIG REWRITE',
    
'CONFIG SET',
    
'CONFIG RESETSTAT',
    
'DBSIZE',
    
'DEBUG OBJECT',
    
'DEBUG SEGFAULT',
    
'DECR',
    
'DECRBY',
    
'DEL',
    
'DISCARD',
    
'DUMP',
    
'ECHO',
    
'EVAL',
    
'EVALSHA',
    
'EXEC',
    
'EXISTS',
    
'EXPIRE',
    
'EXPIREAT',
    
'FLUSHALL',
    
'FLUSHDB',
    
'GEOADD',
    
'GEOHASH',
    
'GEOPOS',
    
'GEODIST',
    
'GEORADIUS',
    
'GEORADIUSBYMEMBER',
    
'GET',
    
'GETBIT',
    
'GETRANGE',
    
'GETSET',
    
'HDEL',
    
'HEXISTS',
    
'HGET',
    
'HGETALL',
    
'HINCRBY',
    
'HINCRBYFLOAT',
    
'HKEYS',
    
'HLEN',
    
'HMGET',
    
'HMSET',
    
'HSET',
    
'HSETNX',
    
'HSTRLEN',
    
'HVALS',
    
'INCR',
    
'INCRBY',
    
'INCRBYFLOAT',
    
'INFO',
    
'KEYS',
    
'LASTSAVE',
    
'LINDEX',
    
'LINSERT',
    
'LLEN',
    
'LPOP',
    
'LPUSH',
    
'LPUSHX',
    
'LRANGE',
    
'LREM',
    
'LSET',
    
'LTRIM',
    
'MGET',
    
'MIGRATE',
    
'MONITOR',
    
'MOVE',
    
'MSET',
    
'MSETNX',
    
'MULTI',
    
'OBJECT',
    
'PERSIST',
    
'PEXPIRE',
    
'PEXPIREAT',
    
'PFADD',
    
'PFCOUNT',
    
'PFMERGE',
    
'PING',
    
'PSETEX',
    
'PSUBSCRIBE',
    
'PUBSUB',
    
'PTTL',
    
'PUBLISH',
    
'PUNSUBSCRIBE',
    
'QUIT',
    
'RANDOMKEY',
    
'READONLY',
    
'READWRITE',
    
'RENAME',
    
'RENAMENX',
    
'RESTORE',
    
'ROLE',
    
'RPOP',
    
'RPOPLPUSH',
    
'RPUSH',
    
'RPUSHX',
    
'SADD',
    
'SAVE',
    
'SCARD',
    
'SCRIPT DEBUG',
    
'SCRIPT EXISTS',
    
'SCRIPT FLUSH',
    
'SCRIPT KILL',
    
'SCRIPT LOAD',
    
'SDIFF',
    
'SDIFFSTORE',
    
'SELECT',
    
'SET',
    
'SETBIT',
    
'SETEX',
    
'SETNX',
    
'SETRANGE',
    
'SHUTDOWN',
    
'SINTER',
    
'SINTERSTORE',
    
'SISMEMBER',
    
'SLAVEOF',
    
'SLOWLOG',
    
'SMEMBERS',
    
'SMOVE',
    
'SORT',
    
'SPOP',
    
'SRANDMEMBER',
    
'SREM',
    
'STRLEN',
    
'SUBSCRIBE',
    
'SUNION',
    
'SUNIONSTORE',
    
'SWAPDB',
    
'SYNC',
    
'TIME',
    
'TOUCH',
    
'TTL',
    
'TYPE',
    
'UNSUBSCRIBE',
    
'UNLINK',
    
'UNWATCH',
    
'WAIT',
    
'WATCH',
    
'XACK',
    
'XADD',
    
'XCLAIM',
    
'XDEL',
    
'XGROUP',
    
'XINFO',
    
'XLEN',
    
'XPENDING',
    
'XRANGE',
    
'XREAD',
    
'XREADGROUP',
    
'XREVRANGE',
    
'XTRIM',
    
'ZADD',
    
'ZCARD',
    
'ZCOUNT',
    
'ZINCRBY',
    
'ZINTERSTORE',
    
'ZLEXCOUNT',
    
'ZRANGE',
    
'ZRANGEBYLEX',
    
'ZREVRANGEBYLEX',
    
'ZRANGEBYSCORE',
    
'ZRANK',
    
'ZREM',
    
'ZREMRANGEBYLEX',
    
'ZREMRANGEBYRANK',
    
'ZREMRANGEBYSCORE',
    
'ZREVRANGE',
    
'ZREVRANGEBYSCORE',
    
'ZREVRANK',
    
'ZSCORE',
    
'ZUNIONSTORE',
    
'SCAN',
    
'SSCAN',
    
'HSCAN',
    
'ZSCAN',
]
$retries public property (available since version 2.0.7)

The number of times a command execution should be retried when a connection failure occurs. This is used in executeCommand() when a yii\redis\SocketException is thrown. Defaults to 0 meaning no retries on failure.

public integer $retries 0
$retryInterval public property (available since version 2.0.10)

The retry interval in microseconds to wait between retry. This is used in executeCommand() when a yii\redis\SocketException is thrown. Defaults to 0 meaning no wait.

$scheme public property (available since version 2.0.18)

The connection scheme used for connecting to the redis server. Defaults to 'tcp'.

public string $scheme 'tcp'
$socket public property
public resource|false $socket null
$socketClientFlags public property (available since version 2.0.5)

Bitmask field which may be set to any combination of connection flags passed to stream_socket_client(). Currently the select of connection flags is limited to STREAM_CLIENT_CONNECT (default), STREAM_CLIENT_ASYNC_CONNECT and STREAM_CLIENT_PERSISTENT.

Warning: STREAM_CLIENT_PERSISTENT will make PHP reuse connections to the same server. If you are using multiple connection objects to refer to different redis databases on the same $port, redis commands may get executed on the wrong database. STREAM_CLIENT_PERSISTENT is only safe to use if you use only one database.

You may still use persistent connections in this case when disambiguating ports as described in a comment on the PHP manual e.g. on the connection used for session storage, specify the port as:

'port' => '6379/session'

See also https://www.php.net/manual/en/function.stream-socket-client.php.

public integer $socketClientFlags STREAM_CLIENT_CONNECT
$unixSocket public property (available since version 2.0.1)

The unix socket path (e.g. /var/run/redis/redis.sock) to use for connecting to the redis server. This can be used instead of $hostname and $port to connect to the server using a unix socket. If a unix socket path is specified, $hostname and $port will be ignored.

public string $unixSocket null
$useSSL public property (available since version 2.0.12)

Send sockets over SSL protocol. Default state is false.

public boolean $useSSL false
$username public property (available since version 2.0.16)

Username for establishing DB connection. Defaults to null meaning AUTH command will be performed without username. Username was introduced in Redis 6.

public string|null $username null

Method Details

Hide inherited methods

__call() public method

Allows issuing all supported commands via magic methods.

$redis->hmset('test_collection', 'key1', 'val1', 'key2', 'val2')
public mixed __call ( $name, $params )
$name string

Name of the missing method to execute

$params array

Method call arguments

                public function __call($name, $params)
{
    $redisCommand = strtoupper(Inflector::camel2words($name, false));
    if (in_array($redisCommand, $this->redisCommands)) {
        return $this->executeCommand($redisCommand, $params);
    }
    return parent::__call($name, $params);
}

            
__sleep() public method

Closes the connection when this component is being serialized.

public array __sleep ( )

                public function __sleep()
{
    $this->close();
    return array_keys(get_object_vars($this));
}

            
append() public method

Append a value to a key.

https://redis.io/commands/append

public mixed append ( $key, $value )
$key
$value
return mixed
auth() public method

Authenticate to the server.

https://redis.io/commands/auth

public mixed auth ( $password )
$password
return mixed
bgrewriteaof() public method

Asynchronously rewrite the append-only file.

https://redis.io/commands/bgrewriteaof

public mixed bgrewriteaof ( )
return mixed
bgsave() public method

Asynchronously save the dataset to disk.

https://redis.io/commands/bgsave

public mixed bgsave ( )
return mixed
bitcount() public method

Count set bits in a string.

https://redis.io/commands/bitcount

public mixed bitcount ( $key, $start, $end )
$key
$start
$end
return mixed
bitfield() public method

Perform arbitrary bitfield integer operations on strings.

https://redis.io/commands/bitfield

public mixed bitfield ( $key, $operations )
$key
$operations
return mixed
bitop() public method

Perform bitwise operations between strings.

https://redis.io/commands/bitop

public mixed bitop ( $operation, $destkey, $keys )
$operation
$destkey
$keys
return mixed
bitpos() public method

Find first bit set or clear in a string.

https://redis.io/commands/bitpos

public mixed bitpos ( $key, $bit, $start, $end )
$key
$bit
$start
$end
return mixed
blpop() public method

Remove and get the first element in a list, or block until one is available.

https://redis.io/commands/blpop

public mixed blpop ( $keys, $timeout )
$keys
$timeout
return mixed
brpop() public method

Remove and get the last element in a list, or block until one is available.

https://redis.io/commands/brpop

public mixed brpop ( $keys, $timeout )
$keys
$timeout
return mixed
brpoplpush() public method

Pop a value from a list, push it to another list and return it; or block until one is available.

https://redis.io/commands/brpoplpush

public mixed brpoplpush ( $source, $destination, $timeout )
$source
$destination
$timeout
return mixed
clientGetname() public method

Get the current connection name.

https://redis.io/commands/client-getname

public mixed clientGetname ( )
return mixed
clientKill() public method

Kill the connection of a client.

https://redis.io/commands/client-kill

public mixed clientKill ( $filters )
$filters
return mixed
clientList() public method

Get the list of client connections.

https://redis.io/commands/client-list

public mixed clientList ( )
return mixed
clientPause() public method

Stop processing commands from clients for some time.

https://redis.io/commands/client-pause

public mixed clientPause ( $timeout )
$timeout
return mixed
clientReply() public method

Instruct the server whether to reply to commands.

https://redis.io/commands/client-reply

public mixed clientReply ( $option )
$option
return mixed
clientSetname() public method

Set the current connection name.

https://redis.io/commands/client-setname

public mixed clientSetname ( $connectionName )
$connectionName
return mixed
close() public method

Closes the currently active DB connection.

It does nothing if the connection is already closed.

public void close ( )

                public function close()
{
    foreach ($this->_pool as $socket) {
        $connection = $this->connectionString . ', database=' . $this->database;
        \Yii::trace('Closing DB connection: ' . $connection, __METHOD__);
        try {
            $this->executeCommand('QUIT');
        } catch (SocketException $e) {
            // ignore errors when quitting a closed connection
        }
        fclose($socket);
    }
    $this->_pool = [];
}

            
clusterAddslots() public method

Assign new hash slots to receiving node.

https://redis.io/commands/cluster-addslots

public mixed clusterAddslots ( $slots )
$slots
return mixed
clusterCountkeysinslot() public method

Return the number of local keys in the specified hash slot.

https://redis.io/commands/cluster-countkeysinslot

public mixed clusterCountkeysinslot ( $slot )
$slot
return mixed
clusterDelslots() public method

Set hash slots as unbound in receiving node.

https://redis.io/commands/cluster-delslots

public mixed clusterDelslots ( $slots )
$slots
return mixed
clusterFailover() public method

Forces a slave to perform a manual failover of its master..

https://redis.io/commands/cluster-failover

public mixed clusterFailover ( $option )
$option
return mixed
clusterForget() public method

Remove a node from the nodes table.

https://redis.io/commands/cluster-forget

public mixed clusterForget ( $nodeId )
$nodeId
return mixed
clusterGetkeysinslot() public method

Return local key names in the specified hash slot.

https://redis.io/commands/cluster-getkeysinslot

public mixed clusterGetkeysinslot ( $slot, $count )
$slot
$count
return mixed
clusterInfo() public method

Provides info about Redis Cluster node state.

https://redis.io/commands/cluster-info

public mixed clusterInfo ( )
return mixed
clusterKeyslot() public method

Returns the hash slot of the specified key.

https://redis.io/commands/cluster-keyslot

public mixed clusterKeyslot ( $key )
$key
return mixed
clusterMeet() public method

Force a node cluster to handshake with another node.

https://redis.io/commands/cluster-meet

public mixed clusterMeet ( $ip, $port )
$ip
$port
return mixed
clusterNodes() public method

Get Cluster config for the node.

https://redis.io/commands/cluster-nodes

public mixed clusterNodes ( )
return mixed
clusterReplicate() public method

Reconfigure a node as a slave of the specified master node.

https://redis.io/commands/cluster-replicate

public mixed clusterReplicate ( $nodeId )
$nodeId
return mixed
clusterReset() public method

Reset a Redis Cluster node.

https://redis.io/commands/cluster-reset

public mixed clusterReset ( $resetType )
$resetType
return mixed
clusterSaveconfig() public method

Forces the node to save cluster state on disk.

https://redis.io/commands/cluster-saveconfig

public mixed clusterSaveconfig ( )
return mixed
clusterSetslot() public method

Bind a hash slot to a specific node.

https://redis.io/commands/cluster-setslot

public mixed clusterSetslot ( $slot, $type, $nodeid )
$slot
$type
$nodeid
return mixed
clusterSlaves() public method

List slave nodes of the specified master node.

https://redis.io/commands/cluster-slaves

public mixed clusterSlaves ( $nodeId )
$nodeId
return mixed
clusterSlots() public method

Get array of Cluster slot to node mappings.

https://redis.io/commands/cluster-slots

public mixed clusterSlots ( )
return mixed
command() public method

Get array of Redis command details.

https://redis.io/commands/command

public mixed command ( )
return mixed
commandCount() public method

Get total number of Redis commands.

https://redis.io/commands/command-count

public mixed commandCount ( )
return mixed
commandGetkeys() public method

Extract keys given a full Redis command.

https://redis.io/commands/command-getkeys

public mixed commandGetkeys ( )
return mixed
commandInfo() public method

Get array of specific Redis command details.

https://redis.io/commands/command-info

public mixed commandInfo ( $commandNames )
$commandNames
return mixed
configGet() public method

Get the value of a configuration parameter.

https://redis.io/commands/config-get

public mixed configGet ( $parameter )
$parameter
return mixed
configResetstat() public method

Reset the stats returned by INFO.

https://redis.io/commands/config-resetstat

public mixed configResetstat ( )
return mixed
configRewrite() public method

Rewrite the configuration file with the in memory configuration.

https://redis.io/commands/config-rewrite

public mixed configRewrite ( )
return mixed
configSet() public method

Set a configuration parameter to the given value.

https://redis.io/commands/config-set

public mixed configSet ( $parameter, $value )
$parameter
$value
return mixed
dbsize() public method

Return the number of keys in the selected database.

https://redis.io/commands/dbsize

public mixed dbsize ( )
return mixed
debugObject() public method

Get debugging information about a key.

https://redis.io/commands/debug-object

public mixed debugObject ( $key )
$key
return mixed
debugSegfault() public method
public mixed debugSegfault ( )
return mixed
decr() public method

Decrement the integer value of a key by one.

https://redis.io/commands/decr

public mixed decr ( $key )
$key
return mixed
decrby() public method

Decrement the integer value of a key by the given number.

https://redis.io/commands/decrby

public mixed decrby ( $key, $decrement )
$key
$decrement
return mixed
del() public method
public mixed del ( $keys )
$keys
return mixed
discard() public method

Discard all commands issued after MULTI.

https://redis.io/commands/discard

public mixed discard ( )
return mixed
dump() public method

Return a serialized version of the value stored at the specified key..

https://redis.io/commands/dump

public mixed dump ( $key )
$key
return mixed
echo() public method

Echo the given string.

https://redis.io/commands/echo

public mixed echo ( $message )
$message
return mixed
eval() public method

Execute a Lua script server side.

https://redis.io/commands/eval

public mixed eval ( $script, $numkeys, $keys, $args )
$script
$numkeys
$keys
$args
return mixed
evalsha() public method

Execute a Lua script server side.

https://redis.io/commands/evalsha

public mixed evalsha ( $sha1, $numkeys, $keys, $args )
$sha1
$numkeys
$keys
$args
return mixed
exec() public method

Execute all commands issued after MULTI.

https://redis.io/commands/exec

public mixed exec ( )
return mixed
executeCommand() public method

Executes a redis command.

For a list of available commands and their parameters see https://redis.io/commands.

The params array should contain the params separated by white space, e.g. to execute SET mykey somevalue NX call the following:

$redis->executeCommand('SET', ['mykey', 'somevalue', 'NX']);
public array|boolean|null|string executeCommand ( $name, $params = [] )
$name string

The name of the command

$params array

List of parameters for the command

return array|boolean|null|string

Dependent on the executed command this method will return different data types:

  • true for commands that return "status reply" with the message 'OK' or 'PONG'.
  • string for commands that return "status reply" that does not have the message OK (since version 2.0.1).
  • string for commands that return "integer reply" as the value is in the range of a signed 64 bit integer.
  • string or null for commands that return "bulk reply".
  • array for commands that return "Multi-bulk replies".

See redis protocol description for details on the mentioned reply types.

throws \yii\db\Exception

for commands that return error reply.

                public function executeCommand($name, $params = [])
{
    $this->open();
    $params = array_merge(explode(' ', $name), $params);
    $command = '*' . count($params) . "\r\n";
    foreach ($params as $arg) {
        $command .= '$' . mb_strlen($arg, '8bit') . "\r\n" . $arg . "\r\n";
    }
    \Yii::trace("Executing Redis Command: {$name}", __METHOD__);
    if ($this->retries > 0) {
        $tries = $this->retries;
        while ($tries-- > 0) {
            try {
                return $this->sendRawCommand($command, $params);
            } catch (SocketException $e) {
                \Yii::error($e, __METHOD__);
                // backup retries, fail on commands that fail inside here
                $retries = $this->retries;
                $this->retries = 0;
                $this->close();
                if ($this->retryInterval > 0) {
                    usleep($this->retryInterval);
                }
                try {
                    $this->open();
                } catch (SocketException $exception) {
                    // Fail to run initial commands, skip current try
                    \Yii::error($exception, __METHOD__);
                    $this->close();
                } catch (Exception $exception) {
                    $this->close();
                }
                $this->retries = $retries;
            }
        }
    }
    return $this->sendRawCommand($command, $params);
}

            
exists() public method

Determine if a key exists.

https://redis.io/commands/exists

public mixed exists ( $keys )
$keys
return mixed
expire() public method

Set a key's time to live in seconds.

https://redis.io/commands/expire

public mixed expire ( $key, $seconds )
$key
$seconds
return mixed
expireat() public method

Set the expiration for a key as a UNIX timestamp.

https://redis.io/commands/expireat

public mixed expireat ( $key, $timestamp )
$key
$timestamp
return mixed
flushall() public method

Remove all keys from all databases.

https://redis.io/commands/flushall

public mixed flushall ( $ASYNC )
$ASYNC
return mixed
flushdb() public method

Remove all keys from the current database.

https://redis.io/commands/flushdb

public mixed flushdb ( $ASYNC )
$ASYNC
return mixed
geoadd() public method

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

https://redis.io/commands/geoadd

public mixed geoadd ( $key, $longitude, $latitude, $member, $more )
$key
$longitude
$latitude
$member
$more
return mixed
geodist() public method

Returns the distance between two members of a geospatial index.

https://redis.io/commands/geodist

public mixed geodist ( $key, $member1, $member2, $unit )
$key
$member1
$member2
$unit
return mixed
geohash() public method

Returns members of a geospatial index as standard geohash strings.

https://redis.io/commands/geohash

public mixed geohash ( $key, $members )
$key
$members
return mixed
geopos() public method

Returns longitude and latitude of members of a geospatial index.

https://redis.io/commands/geopos

public mixed geopos ( $key, $members )
$key
$members
return mixed
georadius() public method

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

https://redis.io/commands/georadius

public mixed georadius ( $key, $longitude, $latitude, $radius, $metric, $options )
$key
$longitude
$latitude
$radius
$metric
$options
return mixed
georadiusbymember() public method

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

https://redis.io/commands/georadiusbymember

public mixed georadiusbymember ( $key, $member, $radius, $metric, $options )
$key
$member
$radius
$metric
$options
return mixed
get() public method

Get the value of a key.

https://redis.io/commands/get

public mixed get ( $key )
$key
return mixed
getConnectionString() public method (available since version 2.0.11)

Return the connection string used to open a socket connection. During a redirect (cluster mode) this will be the target of the redirect.

public string getConnectionString ( )
return string

Socket connection string

                public function getConnectionString()
{
    if ($this->unixSocket) {
        return 'unix://' . $this->unixSocket;
    }
    return $this->scheme . '://' . ($this->redirectConnectionString ?: "$this->hostname:$this->port");
}

            
getDriverName() public method

Returns the name of the DB driver for the current dsn.

public string getDriverName ( )
return string

Name of the DB driver

                public function getDriverName()
{
    return 'redis';
}

            
getIsActive() public method

Returns a value indicating whether the DB connection is established.

public boolean getIsActive ( )
return boolean

Whether the DB connection is established

                public function getIsActive()
{
    return ArrayHelper::getValue($this->_pool, $this->connectionString, false) !== false;
}

            
getLuaScriptBuilder() public method

public yii\redis\LuaScriptBuilder getLuaScriptBuilder ( )

                public function getLuaScriptBuilder()
{
    return new LuaScriptBuilder();
}

            
getSocket() public method

Return the connection resource if a connection to the target has been established before, false otherwise.

public resource|false getSocket ( )

                public function getSocket()
{
    return ArrayHelper::getValue($this->_pool, $this->connectionString, false);
}

            
getbit() public method

Returns the bit value at offset in the string value stored at key.

https://redis.io/commands/getbit

public mixed getbit ( $key, $offset )
$key
$offset
return mixed
getrange() public method

Get a substring of the string stored at a key.

https://redis.io/commands/getrange

public mixed getrange ( $key, $start, $end )
$key
$start
$end
return mixed
getset() public method

Set the string value of a key and return its old value.

https://redis.io/commands/getset

public mixed getset ( $key, $value )
$key
$value
return mixed
hdel() public method

Delete one or more hash fields.

https://redis.io/commands/hdel

public mixed hdel ( $key, $fields )
$key
$fields
return mixed
hexists() public method

Determine if a hash field exists.

https://redis.io/commands/hexists

public mixed hexists ( $key, $field )
$key
$field
return mixed
hget() public method

Get the value of a hash field.

https://redis.io/commands/hget

public mixed hget ( $key, $field )
$key
$field
return mixed
hgetall() public method

Get all the fields and values in a hash.

https://redis.io/commands/hgetall

public mixed hgetall ( $key )
$key
return mixed
hincrby() public method

Increment the integer value of a hash field by the given number.

https://redis.io/commands/hincrby

public mixed hincrby ( $key, $field, $increment )
$key
$field
$increment
return mixed
hincrbyfloat() public method

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

https://redis.io/commands/hincrbyfloat

public mixed hincrbyfloat ( $key, $field, $increment )
$key
$field
$increment
return mixed
hkeys() public method

Get all the fields in a hash.

https://redis.io/commands/hkeys

public mixed hkeys ( $key )
$key
return mixed
hlen() public method

Get the number of fields in a hash.

https://redis.io/commands/hlen

public mixed hlen ( $key )
$key
return mixed
hmget() public method

Get the values of all the given hash fields.

https://redis.io/commands/hmget

public mixed hmget ( $key, $fields )
$key
$fields
return mixed
hmset() public method

Set multiple hash fields to multiple values.

https://redis.io/commands/hmset

public mixed hmset ( $key, $field, $value, $more )
$key
$field
$value
$more
return mixed
hscan() public method

Incrementally iterate hash fields and associated values.

https://redis.io/commands/hscan

public mixed hscan ( $key, $cursor, $MATCH, $pattern, $COUNT, $count )
$key
$cursor
$MATCH
$pattern
$COUNT
$count
return mixed
hset() public method

Set the string value of a hash field.

https://redis.io/commands/hset

public mixed hset ( $key, $field, $value )
$key
$field
$value
return mixed
hsetnx() public method

Set the value of a hash field, only if the field does not exist.

https://redis.io/commands/hsetnx

public mixed hsetnx ( $key, $field, $value )
$key
$field
$value
return mixed
hstrlen() public method

Get the length of the value of a hash field.

https://redis.io/commands/hstrlen

public mixed hstrlen ( $key, $field )
$key
$field
return mixed
hvals() public method

Get all the values in a hash.

https://redis.io/commands/hvals

public mixed hvals ( $key )
$key
return mixed
incr() public method

Increment the integer value of a key by one.

https://redis.io/commands/incr

public mixed incr ( $key )
$key
return mixed
incrby() public method

Increment the integer value of a key by the given amount.

https://redis.io/commands/incrby

public mixed incrby ( $key, $increment )
$key
$increment
return mixed
incrbyfloat() public method

Increment the float value of a key by the given amount.

https://redis.io/commands/incrbyfloat

public mixed incrbyfloat ( $key, $increment )
$key
$increment
return mixed
info() public method

Get information and statistics about the server.

https://redis.io/commands/info

public mixed info ( $section )
$section
return mixed
initConnection() protected method

Initializes the DB connection.

This method is invoked right after the DB connection is established. The default implementation triggers an EVENT_AFTER_OPEN event.

protected void initConnection ( )

                protected function initConnection()
{
    $this->trigger(self::EVENT_AFTER_OPEN);
}

            
keys() public method

Find all keys matching the given pattern.

https://redis.io/commands/keys

public mixed keys ( $pattern )
$pattern
return mixed
lastsave() public method

Get the UNIX time stamp of the last successful save to disk.

https://redis.io/commands/lastsave

public mixed lastsave ( )
return mixed
lindex() public method

Get an element from a list by its index.

https://redis.io/commands/lindex

public mixed lindex ( $key, $index )
$key
$index
return mixed
linsert() public method

Insert an element before or after another element in a list.

https://redis.io/commands/linsert

public mixed linsert ( $key, $where, $pivot, $value )
$key
$where
$pivot
$value
return mixed
llen() public method

Get the length of a list.

https://redis.io/commands/llen

public mixed llen ( $key )
$key
return mixed
lpop() public method

Remove and get the first element in a list.

https://redis.io/commands/lpop

public mixed lpop ( $key )
$key
return mixed
lpush() public method

Prepend one or multiple values to a list.

https://redis.io/commands/lpush

public mixed lpush ( $key, $values )
$key
$values
return mixed
lpushx() public method

Prepend a value to a list, only if the list exists.

https://redis.io/commands/lpushx

public mixed lpushx ( $key, $value )
$key
$value
return mixed
lrange() public method

Get a range of elements from a list.

https://redis.io/commands/lrange

public mixed lrange ( $key, $start, $stop )
$key
$start
$stop
return mixed
lrem() public method

Remove elements from a list.

https://redis.io/commands/lrem

public mixed lrem ( $key, $count, $value )
$key
$count
$value
return mixed
lset() public method

Set the value of an element in a list by its index.

https://redis.io/commands/lset

public mixed lset ( $key, $index, $value )
$key
$index
$value
return mixed
ltrim() public method

Trim a list to the specified range.

https://redis.io/commands/ltrim

public mixed ltrim ( $key, $start, $stop )
$key
$start
$stop
return mixed
mget() public method

Get the values of all the given keys.

https://redis.io/commands/mget

public mixed mget ( $keys )
$keys
return mixed
migrate() public method

Atomically transfer a key from a Redis instance to another one..

https://redis.io/commands/migrate

public mixed migrate ( $host, $port, $key, $destinationDb, $timeout, $options )
$host
$port
$key
$destinationDb
$timeout
$options
return mixed
monitor() public method

Listen for all requests received by the server in real time.

https://redis.io/commands/monitor

public mixed monitor ( )
return mixed
move() public method

Move a key to another database.

https://redis.io/commands/move

public mixed move ( $key, $db )
$key
$db
return mixed
mset() public method

Set multiple keys to multiple values.

https://redis.io/commands/mset

public mixed mset ( $keyValuePairs )
$keyValuePairs
return mixed
msetnx() public method

Set multiple keys to multiple values, only if none of the keys exist.

https://redis.io/commands/msetnx

public mixed msetnx ( $keyValuePairs )
$keyValuePairs
return mixed
multi() public method

Mark the start of a transaction block.

https://redis.io/commands/multi

public mixed multi ( )
return mixed
object() public method

Inspect the internals of Redis objects.

https://redis.io/commands/object

public mixed object ( $subcommand, $argumentss )
$subcommand
$argumentss
return mixed
open() public method

Establishes a DB connection.

It does nothing if a DB connection has already been established.

public void open ( )
throws \yii\db\Exception

if connection fails

                public function open()
{
    if ($this->socket !== false) {
        return;
    }
    $connection = $this->connectionString . ', database=' . $this->database;
    \Yii::trace('Opening redis DB connection: ' . $connection, __METHOD__);
    $socket = @stream_socket_client(
        $this->connectionString,
        $errorNumber,
        $errorDescription,
        $this->connectionTimeout ?: ini_get('default_socket_timeout'),
        $this->socketClientFlags,
        stream_context_create($this->contextOptions)
    );
    if ($socket) {
        $this->_pool[ $this->connectionString ] = $socket;
        if ($this->dataTimeout !== null) {
            stream_set_timeout($socket, $timeout = (int) $this->dataTimeout, (int) (($this->dataTimeout - $timeout) * 1000000));
        }
        if ($this->useSSL) {
            stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT);
        }
        if ($this->password !== null) {
            $this->executeCommand('AUTH', array_filter([$this->username, $this->password]));
        }
        if ($this->database !== null) {
            $this->executeCommand('SELECT', [$this->database]);
        }
        $this->initConnection();
    } else {
        \Yii::error("Failed to open redis DB connection ($connection): $errorNumber - $errorDescription", __CLASS__);
        $message = YII_DEBUG ? "Failed to open redis DB connection ($connection): $errorNumber - $errorDescription" : 'Failed to open DB connection.';
        throw new Exception($message, $errorDescription, $errorNumber);
    }
}

            
persist() public method

Remove the expiration from a key.

https://redis.io/commands/persist

public mixed persist ( $key )
$key
return mixed
pexpire() public method

Set a key's time to live in milliseconds.

https://redis.io/commands/pexpire

public mixed pexpire ( $key, $milliseconds )
$key
$milliseconds
return mixed
pexpireat() public method

Set the expiration for a key as a UNIX timestamp specified in milliseconds.

https://redis.io/commands/pexpireat

public mixed pexpireat ( $key, $millisecondsTimestamp )
$key
$millisecondsTimestamp
return mixed
pfadd() public method

Adds the specified elements to the specified HyperLogLog..

https://redis.io/commands/pfadd

public mixed pfadd ( $key, $elements )
$key
$elements
return mixed
pfcount() public method

Return the approximated cardinality of the set(s) observed by the HyperLogLog at key(s)..

https://redis.io/commands/pfcount

public mixed pfcount ( $keys )
$keys
return mixed
pfmerge() public method

Merge N different HyperLogLogs into a single one..

https://redis.io/commands/pfmerge

public mixed pfmerge ( $destkey, $sourcekeys )
$destkey
$sourcekeys
return mixed
ping() public method
public mixed ping ( $message )
$message
return mixed
psetex() public method

Set the value and expiration in milliseconds of a key.

https://redis.io/commands/psetex

public mixed psetex ( $key, $milliseconds, $value )
$key
$milliseconds
$value
return mixed
psubscribe() public method

Listen for messages published to channels matching the given patterns.

https://redis.io/commands/psubscribe

public mixed psubscribe ( $patterns )
$patterns
return mixed
pttl() public method

Get the time to live for a key in milliseconds.

https://redis.io/commands/pttl

public mixed pttl ( $key )
$key
return mixed
publish() public method

Post a message to a channel.

https://redis.io/commands/publish

public mixed publish ( $channel, $message )
$channel
$message
return mixed
pubsub() public method

Inspect the state of the Pub/Sub subsystem.

https://redis.io/commands/pubsub

public mixed pubsub ( $subcommand, $arguments )
$subcommand
$arguments
return mixed
punsubscribe() public method

Stop listening for messages posted to channels matching the given patterns.

https://redis.io/commands/punsubscribe

public mixed punsubscribe ( $patterns )
$patterns
return mixed
quit() public method

Close the connection.

https://redis.io/commands/quit

public mixed quit ( )
return mixed
randomkey() public method

Return a random key from the keyspace.

https://redis.io/commands/randomkey

public mixed randomkey ( )
return mixed
readonly() public method

Enables read queries for a connection to a cluster slave node.

https://redis.io/commands/readonly

public mixed readonly ( )
return mixed
readwrite() public method

Disables read queries for a connection to a cluster slave node.

https://redis.io/commands/readwrite

public mixed readwrite ( )
return mixed
rename() public method
public mixed rename ( $key, $newkey )
$key
$newkey
return mixed
renamenx() public method

Rename a key, only if the new key does not exist.

https://redis.io/commands/renamenx

public mixed renamenx ( $key, $newkey )
$key
$newkey
return mixed
restore() public method

Create a key using the provided serialized value, previously obtained using DUMP..

https://redis.io/commands/restore

public mixed restore ( $key, $ttl, $serializedValue, $REPLACE )
$key
$ttl
$serializedValue
$REPLACE
return mixed
role() public method

Return the role of the instance in the context of replication.

https://redis.io/commands/role

public mixed role ( )
return mixed
rpop() public method

Remove and get the last element in a list.

https://redis.io/commands/rpop

public mixed rpop ( $key )
$key
return mixed
rpoplpush() public method

Remove the last element in a list, prepend it to another list and return it.

https://redis.io/commands/rpoplpush

public mixed rpoplpush ( $source, $destination )
$source
$destination
return mixed
rpush() public method

Append one or multiple values to a list.

https://redis.io/commands/rpush

public mixed rpush ( $key, $values )
$key
$values
return mixed
rpushx() public method

Append a value to a list, only if the list exists.

https://redis.io/commands/rpushx

public mixed rpushx ( $key, $value )
$key
$value
return mixed
sadd() public method

Add one or more members to a set.

https://redis.io/commands/sadd

public mixed sadd ( $key, $members )
$key
$members
return mixed
save() public method

Synchronously save the dataset to disk.

https://redis.io/commands/save

public mixed save ( )
return mixed
scan() public method

Incrementally iterate the keys space.

https://redis.io/commands/scan

public mixed scan ( $cursor, $MATCH, $pattern, $COUNT, $count )
$cursor
$MATCH
$pattern
$COUNT
$count
return mixed
scard() public method

Get the number of members in a set.

https://redis.io/commands/scard

public mixed scard ( $key )
$key
return mixed
scriptDebug() public method

Set the debug mode for executed scripts..

https://redis.io/commands/script-debug

public mixed scriptDebug ( $option )
$option
return mixed
scriptExists() public method

Check existence of scripts in the script cache..

https://redis.io/commands/script-exists

public mixed scriptExists ( $sha1s )
$sha1s
return mixed
scriptFlush() public method

Remove all the scripts from the script cache..

https://redis.io/commands/script-flush

public mixed scriptFlush ( )
return mixed
scriptKill() public method

Kill the script currently in execution..

https://redis.io/commands/script-kill

public mixed scriptKill ( )
return mixed
scriptLoad() public method

Load the specified Lua script into the script cache..

https://redis.io/commands/script-load

public mixed scriptLoad ( $script )
$script
return mixed
sdiff() public method

Subtract multiple sets.

https://redis.io/commands/sdiff

public mixed sdiff ( $keys )
$keys
return mixed
sdiffstore() public method

Subtract multiple sets and store the resulting set in a key.

https://redis.io/commands/sdiffstore

public mixed sdiffstore ( $destination, $keys )
$destination
$keys
return mixed
select() public method

Change the selected database for the current connection.

https://redis.io/commands/select

public mixed select ( $index )
$index
return mixed
sendRawCommand() protected method

Sends RAW command string to the server.

protected array|boolean|null|string sendRawCommand ( $command, $params )
$command string

Command string

$params array

List of parameters for the command

return array|boolean|null|string

Dependent on the executed command this method will return different data types:

  • true for commands that return "status reply" with the message 'OK' or 'PONG'.
  • string for commands that return "status reply" that does not have the message OK (since version 2.0.1).
  • string for commands that return "integer reply" as the value is in the range of a signed 64 bit integer.
  • string or null for commands that return "bulk reply".
  • array for commands that return "Multi-bulk replies".

See redis protocol description for details on the mentioned reply types.

throws \yii\db\Exception

for commands that return error reply.

throws yii\redis\SocketException

on connection error.

                protected function sendRawCommand($command, $params)
{
    $written = @fwrite($this->socket, $command);
    if ($written === false) {
        throw new SocketException("Failed to write to socket.\nRedis command was: " . $command);
    }
    if ($written !== ($len = mb_strlen($command, '8bit'))) {
        throw new SocketException("Failed to write to socket. $written of $len bytes written.\nRedis command was: " . $command);
    }
    return $this->parseResponse($params, $command);
}

            
set() public method

Set the string value of a key.

https://redis.io/commands/set

public mixed set ( $key, $value, $options )
$key
$value
$options
return mixed
setbit() public method

Sets or clears the bit at offset in the string value stored at key.

https://redis.io/commands/setbit

public mixed setbit ( $key, $offset, $value )
$key
$offset
$value
return mixed
setex() public method

Set the value and expiration of a key.

https://redis.io/commands/setex

public mixed setex ( $key, $seconds, $value )
$key
$seconds
$value
return mixed
setnx() public method

Set the value of a key, only if the key does not exist.

https://redis.io/commands/setnx

public mixed setnx ( $key, $value )
$key
$value
return mixed
setrange() public method

Overwrite part of a string at key starting at the specified offset.

https://redis.io/commands/setrange

public mixed setrange ( $key, $offset, $value )
$key
$offset
$value
return mixed
shutdown() public method

Synchronously save the dataset to disk and then shut down the server.

https://redis.io/commands/shutdown

public mixed shutdown ( $saveOption )
$saveOption
return mixed
sinter() public method

Intersect multiple sets.

https://redis.io/commands/sinter

public mixed sinter ( $keys )
$keys
return mixed
sinterstore() public method

Intersect multiple sets and store the resulting set in a key.

https://redis.io/commands/sinterstore

public mixed sinterstore ( $destination, $keys )
$destination
$keys
return mixed
sismember() public method

Determine if a given value is a member of a set.

https://redis.io/commands/sismember

public mixed sismember ( $key, $member )
$key
$member
return mixed
slaveof() public method

Make the server a slave of another instance, or promote it as master.

https://redis.io/commands/slaveof

public mixed slaveof ( $host, $port )
$host
$port
return mixed
slowlog() public method

Manages the Redis slow queries log.

https://redis.io/commands/slowlog

public mixed slowlog ( $subcommand, $argument )
$subcommand
$argument
return mixed
smembers() public method

Get all the members in a set.

https://redis.io/commands/smembers

public mixed smembers ( $key )
$key
return mixed
smove() public method

Move a member from one set to another.

https://redis.io/commands/smove

public mixed smove ( $source, $destination, $member )
$source
$destination
$member
return mixed
sort() public method

Sort the elements in a list, set or sorted set.

https://redis.io/commands/sort

public mixed sort ( $key, $options )
$key
$options
return mixed
spop() public method

Remove and return one or multiple random members from a set.

https://redis.io/commands/spop

public mixed spop ( $key, $count )
$key
$count
return mixed
srandmember() public method

Get one or multiple random members from a set.

https://redis.io/commands/srandmember

public mixed srandmember ( $key, $count )
$key
$count
return mixed
srem() public method

Remove one or more members from a set.

https://redis.io/commands/srem

public mixed srem ( $key, $members )
$key
$members
return mixed
sscan() public method

Incrementally iterate Set elements.

https://redis.io/commands/sscan

public mixed sscan ( $key, $cursor, $MATCH, $pattern, $COUNT, $count )
$key
$cursor
$MATCH
$pattern
$COUNT
$count
return mixed
strlen() public method

Get the length of the value stored in a key.

https://redis.io/commands/strlen

public mixed strlen ( $key )
$key
return mixed
subscribe() public method

Listen for messages published to the given channels.

https://redis.io/commands/subscribe

public mixed subscribe ( $channels )
$channels
return mixed
sunion() public method
public mixed sunion ( $keys )
$keys
return mixed
sunionstore() public method

Add multiple sets and store the resulting set in a key.

https://redis.io/commands/sunionstore

public mixed sunionstore ( $destination, $keys )
$destination
$keys
return mixed
swapdb() public method

Swaps two Redis databases.

https://redis.io/commands/swapdb

public mixed swapdb ( $index, $index )
$index
$index
return mixed
sync() public method

Internal command used for replication.

https://redis.io/commands/sync

public mixed sync ( )
return mixed
time() public method

Return the current server time.

https://redis.io/commands/time

public mixed time ( )
return mixed
touch() public method

Alters the last access time of a key(s).

Returns the number of existing keys specified.. https://redis.io/commands/touch

public mixed touch ( $keys )
$keys
return mixed
ttl() public method

Get the time to live for a key.

https://redis.io/commands/ttl

public mixed ttl ( $key )
$key
return mixed
type() public method

Determine the type stored at key.

https://redis.io/commands/type

public mixed type ( $key )
$key
return mixed
unlink() public method

Delete a key asynchronously in another thread.

Otherwise it is just as DEL, but non blocking.. https://redis.io/commands/unlink

public mixed unlink ( $keys )
$keys
return mixed
unsubscribe() public method

Stop listening for messages posted to the given channels.

https://redis.io/commands/unsubscribe

public mixed unsubscribe ( $channels )
$channels
return mixed
unwatch() public method

Forget about all watched keys.

https://redis.io/commands/unwatch

public mixed unwatch ( )
return mixed
wait() public method

Wait for the synchronous replication of all the write commands sent in the context of the current connection.

https://redis.io/commands/wait

public mixed wait ( $numslaves, $timeout )
$numslaves
$timeout
return mixed
watch() public method

Watch the given keys to determine execution of the MULTI/EXEC block.

https://redis.io/commands/watch

public mixed watch ( $keys )
$keys
return mixed
xack() public method

Removes one or multiple messages from the pending entries list (PEL) of a stream consumer group https://redis.io/commands/xack

public mixed xack ( $stream, $group, $ids )
$stream
$group
$ids
return mixed
xadd() public method

Appends the specified stream entry to the stream at the specified key https://redis.io/commands/xadd

public mixed xadd ( $stream, $id, $field, $value, $fieldsValues )
$stream
$id
$field
$value
$fieldsValues
return mixed
xclaim() public method

Changes the ownership of a pending message, so that the new owner is the consumer specified as the command argument https://redis.io/commands/xclaim

public mixed xclaim ( $stream, $group, $consumer, $minIdleTimeMs, $id, $options )
$stream
$group
$consumer
$minIdleTimeMs
$id
$options
return mixed
xdel() public method

Removes the specified entries from a stream, and returns the number of entries deleted https://redis.io/commands/xdel

public mixed xdel ( $stream, $ids )
$stream
$ids
return mixed
xgroup() public method

Manages the consumer groups associated with a stream data structure https://redis.io/commands/xgroup

public mixed xgroup ( $subCommand, $stream, $group, $options )
$subCommand
$stream
$group
$options
return mixed
xinfo() public method

Retrieves different information about the streams and associated consumer groups https://redis.io/commands/xinfo

public mixed xinfo ( $subCommand, $stream, $options )
$subCommand
$stream
$options
return mixed
xlen() public method

Returns the number of entries inside a stream https://redis.io/commands/xlen

public mixed xlen ( $stream )
$stream
return mixed
xpending() public method

Fetching data from a stream via a consumer group, and not acknowledging such data, has the effect of creating pending entries https://redis.io/commands/xpending

public mixed xpending ( $stream, $group, $options )
$stream
$group
$options
return mixed
xrange() public method

Returns the stream entries matching a given range of IDs https://redis.io/commands/xrange

public mixed xrange ( $stream, $start, $end, $options )
$stream
$start
$end
$options
return mixed
xread() public method

Read data from one or multiple streams, only returning entries with an ID greater than the last received ID reported by the caller https://redis.io/commands/xread

public mixed xread ( $options )
$options
return mixed
xreadgroup() public method

Special version of the XREAD command with support for consumer groups https://redis.io/commands/xreadgroup

public mixed xreadgroup ( $subCommand, $group, $consumer, $options )
$subCommand
$group
$consumer
$options
return mixed
xrevrange() public method

Exactly like XRANGE, but with the notable difference of returning the entries in reverse order, and also taking the start-end range in reverse order https://redis.io/commands/xrevrange

public mixed xrevrange ( $stream, $end, $start, $options )
$stream
$end
$start
$options
return mixed
xtrim() public method

Trims the stream to a given number of items, evicting older items (items with lower IDs) if needed https://redis.io/commands/xtrim

public mixed xtrim ( $stream, $strategy, $options )
$stream
$strategy
$options
return mixed
zadd() public method

Add one or more members to a sorted set, or update its score if it already exists.

https://redis.io/commands/zadd

public mixed zadd ( $key, $options )
$key
$options
return mixed
zcard() public method

Get the number of members in a sorted set.

https://redis.io/commands/zcard

public mixed zcard ( $key )
$key
return mixed
zcount() public method

Count the members in a sorted set with scores within the given values.

https://redis.io/commands/zcount

public mixed zcount ( $key, $min, $max )
$key
$min
$max
return mixed
zincrby() public method

Increment the score of a member in a sorted set.

https://redis.io/commands/zincrby

public mixed zincrby ( $key, $increment, $member )
$key
$increment
$member
return mixed
zinterstore() public method

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

https://redis.io/commands/zinterstore

public mixed zinterstore ( $destination, $numkeys, $key, $options )
$destination
$numkeys
$key
$options
return mixed
zlexcount() public method

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

https://redis.io/commands/zlexcount

public mixed zlexcount ( $key, $min, $max )
$key
$min
$max
return mixed
zrange() public method

Return a range of members in a sorted set, by index.

https://redis.io/commands/zrange

public mixed zrange ( $key, $start, $stop, $WITHSCORES )
$key
$start
$stop
$WITHSCORES
return mixed
zrangebylex() public method

Return a range of members in a sorted set, by lexicographical range.

https://redis.io/commands/zrangebylex

public mixed zrangebylex ( $key, $min, $max, $LIMIT, $offset, $count )
$key
$min
$max
$LIMIT
$offset
$count
return mixed
zrangebyscore() public method

Return a range of members in a sorted set, by score.

https://redis.io/commands/zrangebyscore

public mixed zrangebyscore ( $key, $min, $max, $options )
$key
$min
$max
$options
return mixed
zrank() public method

Determine the index of a member in a sorted set.

https://redis.io/commands/zrank

public mixed zrank ( $key, $member )
$key
$member
return mixed
zrem() public method

Remove one or more members from a sorted set.

https://redis.io/commands/zrem

public mixed zrem ( $key, $members )
$key
$members
return mixed
zremrangebylex() public method

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

https://redis.io/commands/zremrangebylex

public mixed zremrangebylex ( $key, $min, $max )
$key
$min
$max
return mixed
zremrangebyrank() public method

Remove all members in a sorted set within the given indexes.

https://redis.io/commands/zremrangebyrank

public mixed zremrangebyrank ( $key, $start, $stop )
$key
$start
$stop
return mixed
zremrangebyscore() public method

Remove all members in a sorted set within the given scores.

https://redis.io/commands/zremrangebyscore

public mixed zremrangebyscore ( $key, $min, $max )
$key
$min
$max
return mixed
zrevrange() public method

Return a range of members in a sorted set, by index, with scores ordered from high to low.

https://redis.io/commands/zrevrange

public mixed zrevrange ( $key, $start, $stop, $WITHSCORES )
$key
$start
$stop
$WITHSCORES
return mixed
zrevrangebylex() public method

Return a range of members in a sorted set, by lexicographical range, ordered from higher to lower strings..

https://redis.io/commands/zrevrangebylex

public mixed zrevrangebylex ( $key, $max, $min, $LIMIT, $offset, $count )
$key
$max
$min
$LIMIT
$offset
$count
return mixed
zrevrangebyscore() public method

Return a range of members in a sorted set, by score, with scores ordered from high to low.

https://redis.io/commands/zrevrangebyscore

public mixed zrevrangebyscore ( $key, $max, $min, $WITHSCORES, $LIMIT, $offset, $count )
$key
$max
$min
$WITHSCORES
$LIMIT
$offset
$count
return mixed
zrevrank() public method

Determine the index of a member in a sorted set, with scores ordered from high to low.

https://redis.io/commands/zrevrank

public mixed zrevrank ( $key, $member )
$key
$member
return mixed
zscan() public method

Incrementally iterate sorted sets elements and associated scores.

https://redis.io/commands/zscan

public mixed zscan ( $key, $cursor, $MATCH, $pattern, $COUNT, $count )
$key
$cursor
$MATCH
$pattern
$COUNT
$count
return mixed
zscore() public method

Get the score associated with the given member in a sorted set.

https://redis.io/commands/zscore

public mixed zscore ( $key, $member )
$key
$member
return mixed
zunionstore() public method

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

https://redis.io/commands/zunionstore

public mixed zunionstore ( $destination, $numkeys, $key, $options )
$destination
$numkeys
$key
$options
return mixed

Event Details

Hide inherited properties

EVENT_AFTER_OPEN event of type yii\redis\Event

An event that is triggered after a DB connection is established