Class yii\redis\Connection
Inheritance | yii\redis\Connection » yii\base\Component |
---|---|
Available since extension's version | 2.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
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
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
Method | Description | Defined By |
---|---|---|
initConnection() | Initializes the DB connection. | yii\redis\Connection |
sendRawCommand() | Sends RAW command string to the server. | yii\redis\Connection |
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
Timeout to use for connection to redis. If not set the timeout set in php.ini will be used: ini_get("default_socket_timeout")
.
PHP context options which are used in the Redis connection stream.
Timeout to use for redis socket when reading and writing data. If not set the php default value will be used.
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
.
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.
The password for establishing DB connection. Defaults to null meaning no AUTH command is sent. See https://redis.io/commands/auth
The port to use for connecting to the redis server. Default port is 6379. If $unixSocket is specified, $hostname and port will be ignored.
If the query gets redirected, use this as the temporary new hostname
List of available redis commands.
See also https://redis.io/commands.
'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',
]
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.
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.
The connection scheme used for connecting to the redis server. Defaults to 'tcp'.
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.
Send sockets over SSL protocol. Default state is false.
Method Details
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);
}
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 a value to a key.
public mixed append ( $key, $value ) | ||
$key | ||
$value | ||
return | mixed |
---|
Authenticate to the server.
public mixed auth ( $password ) | ||
$password | ||
return | mixed |
---|
Asynchronously rewrite the append-only file.
public mixed bgrewriteaof ( ) | ||
return | mixed |
---|
Asynchronously save the dataset to disk.
public mixed bgsave ( ) | ||
return | mixed |
---|
Count set bits in a string.
public mixed bitcount ( $key, $start, $end ) | ||
$key | ||
$start | ||
$end | ||
return | mixed |
---|
Perform arbitrary bitfield integer operations on strings.
public mixed bitfield ( $key, $operations ) | ||
$key | ||
$operations | ||
return | mixed |
---|
Perform bitwise operations between strings.
public mixed bitop ( $operation, $destkey, $keys ) | ||
$operation | ||
$destkey | ||
$keys | ||
return | mixed |
---|
Find first bit set or clear in a string.
public mixed bitpos ( $key, $bit, $start, $end ) | ||
$key | ||
$bit | ||
$start | ||
$end | ||
return | mixed |
---|
Remove and get the first element in a list, or block until one is available.
public mixed blpop ( $keys, $timeout ) | ||
$keys | ||
$timeout | ||
return | mixed |
---|
Remove and get the last element in a list, or block until one is available.
public mixed brpop ( $keys, $timeout ) | ||
$keys | ||
$timeout | ||
return | mixed |
---|
Pop a value from a list, push it to another list and return it; or block until one is available.
public mixed brpoplpush ( $source, $destination, $timeout ) | ||
$source | ||
$destination | ||
$timeout | ||
return | mixed |
---|
Get the current connection name.
public mixed clientGetname ( ) | ||
return | mixed |
---|
Kill the connection of a client.
public mixed clientKill ( $filters ) | ||
$filters | ||
return | mixed |
---|
Get the list of client connections.
public mixed clientList ( ) | ||
return | mixed |
---|
Stop processing commands from clients for some time.
public mixed clientPause ( $timeout ) | ||
$timeout | ||
return | mixed |
---|
Instruct the server whether to reply to commands.
public mixed clientReply ( $option ) | ||
$option | ||
return | mixed |
---|
Set the current connection name.
public mixed clientSetname ( $connectionName ) | ||
$connectionName | ||
return | mixed |
---|
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 = [];
}
Assign new hash slots to receiving node.
public mixed clusterAddslots ( $slots ) | ||
$slots | ||
return | mixed |
---|
Return the number of local keys in the specified hash slot.
public mixed clusterCountkeysinslot ( $slot ) | ||
$slot | ||
return | mixed |
---|
Set hash slots as unbound in receiving node.
public mixed clusterDelslots ( $slots ) | ||
$slots | ||
return | mixed |
---|
Forces a slave to perform a manual failover of its master..
public mixed clusterFailover ( $option ) | ||
$option | ||
return | mixed |
---|
Remove a node from the nodes table.
public mixed clusterForget ( $nodeId ) | ||
$nodeId | ||
return | mixed |
---|
Return local key names in the specified hash slot.
public mixed clusterGetkeysinslot ( $slot, $count ) | ||
$slot | ||
$count | ||
return | mixed |
---|
Provides info about Redis Cluster node state.
public mixed clusterInfo ( ) | ||
return | mixed |
---|
Returns the hash slot of the specified key.
public mixed clusterKeyslot ( $key ) | ||
$key | ||
return | mixed |
---|
Force a node cluster to handshake with another node.
public mixed clusterMeet ( $ip, $port ) | ||
$ip | ||
$port | ||
return | mixed |
---|
Get Cluster config for the node.
public mixed clusterNodes ( ) | ||
return | mixed |
---|
Reconfigure a node as a slave of the specified master node.
public mixed clusterReplicate ( $nodeId ) | ||
$nodeId | ||
return | mixed |
---|
Reset a Redis Cluster node.
public mixed clusterReset ( $resetType ) | ||
$resetType | ||
return | mixed |
---|
Forces the node to save cluster state on disk.
public mixed clusterSaveconfig ( ) | ||
return | mixed |
---|
Bind a hash slot to a specific node.
public mixed clusterSetslot ( $slot, $type, $nodeid ) | ||
$slot | ||
$type | ||
$nodeid | ||
return | mixed |
---|
List slave nodes of the specified master node.
public mixed clusterSlaves ( $nodeId ) | ||
$nodeId | ||
return | mixed |
---|
Get array of Cluster slot to node mappings.
public mixed clusterSlots ( ) | ||
return | mixed |
---|
Get array of Redis command details.
public mixed command ( ) | ||
return | mixed |
---|
Get total number of Redis commands.
public mixed commandCount ( ) | ||
return | mixed |
---|
Extract keys given a full Redis command.
public mixed commandGetkeys ( ) | ||
return | mixed |
---|
Get array of specific Redis command details.
public mixed commandInfo ( $commandNames ) | ||
$commandNames | ||
return | mixed |
---|
Get the value of a configuration parameter.
public mixed configGet ( $parameter ) | ||
$parameter | ||
return | mixed |
---|
Reset the stats returned by INFO.
public mixed configResetstat ( ) | ||
return | mixed |
---|
Rewrite the configuration file with the in memory configuration.
public mixed configRewrite ( ) | ||
return | mixed |
---|
Set a configuration parameter to the given value.
public mixed configSet ( $parameter, $value ) | ||
$parameter | ||
$value | ||
return | mixed |
---|
Return the number of keys in the selected database.
public mixed dbsize ( ) | ||
return | mixed |
---|
Get debugging information about a key.
public mixed debugObject ( $key ) | ||
$key | ||
return | mixed |
---|
Make the server crash.
public mixed debugSegfault ( ) | ||
return | mixed |
---|
Decrement the integer value of a key by one.
public mixed decr ( $key ) | ||
$key | ||
return | mixed |
---|
Decrement the integer value of a key by the given number.
public mixed decrby ( $key, $decrement ) | ||
$key | ||
$decrement | ||
return | mixed |
---|
Delete a key.
public mixed del ( $keys ) | ||
$keys | ||
return | mixed |
---|
Discard all commands issued after MULTI.
public mixed discard ( ) | ||
return | mixed |
---|
Return a serialized version of the value stored at the specified key..
public mixed dump ( $key ) | ||
$key | ||
return | mixed |
---|
Echo the given string.
public mixed echo ( $message ) | ||
$message | ||
return | mixed |
---|
Execute a Lua script server side.
public mixed eval ( $script, $numkeys, $keys, $args ) | ||
$script | ||
$numkeys | ||
$keys | ||
$args | ||
return | mixed |
---|
Execute a Lua script server side.
public mixed evalsha ( $sha1, $numkeys, $keys, $args ) | ||
$sha1 | ||
$numkeys | ||
$keys | ||
$args | ||
return | mixed |
---|
Execute all commands issued after MULTI.
public mixed exec ( ) | ||
return | mixed |
---|
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:
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);
}
Determine if a key exists.
public mixed exists ( $keys ) | ||
$keys | ||
return | mixed |
---|
Set a key's time to live in seconds.
public mixed expire ( $key, $seconds ) | ||
$key | ||
$seconds | ||
return | mixed |
---|
Set the expiration for a key as a UNIX timestamp.
public mixed expireat ( $key, $timestamp ) | ||
$key | ||
$timestamp | ||
return | mixed |
---|
Remove all keys from all databases.
public mixed flushall ( $ASYNC ) | ||
$ASYNC | ||
return | mixed |
---|
Remove all keys from the current database.
public mixed flushdb ( $ASYNC ) | ||
$ASYNC | ||
return | mixed |
---|
Add one or more geospatial items in the geospatial index represented using a sorted set.
public mixed geoadd ( $key, $longitude, $latitude, $member, $more ) | ||
$key | ||
$longitude | ||
$latitude | ||
$member | ||
$more | ||
return | mixed |
---|
Returns the distance between two members of a geospatial index.
public mixed geodist ( $key, $member1, $member2, $unit ) | ||
$key | ||
$member1 | ||
$member2 | ||
$unit | ||
return | mixed |
---|
Returns members of a geospatial index as standard geohash strings.
public mixed geohash ( $key, $members ) | ||
$key | ||
$members | ||
return | mixed |
---|
Returns longitude and latitude of members of a geospatial index.
public mixed geopos ( $key, $members ) | ||
$key | ||
$members | ||
return | mixed |
---|
Query a sorted set representing a geospatial index to fetch members matching a given maximum distance from a point.
public mixed georadius ( $key, $longitude, $latitude, $radius, $metric, $options ) | ||
$key | ||
$longitude | ||
$latitude | ||
$radius | ||
$metric | ||
$options | ||
return | mixed |
---|
Query a sorted set representing a geospatial index to fetch members matching a given maximum distance from a member.
public mixed georadiusbymember ( $key, $member, $radius, $metric, $options ) | ||
$key | ||
$member | ||
$radius | ||
$metric | ||
$options | ||
return | mixed |
---|
Get the value of a key.
public mixed get ( $key ) | ||
$key | ||
return | mixed |
---|
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");
}
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';
}
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;
}
public yii\redis\LuaScriptBuilder getLuaScriptBuilder ( ) |
public function getLuaScriptBuilder()
{
return new LuaScriptBuilder();
}
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);
}
Returns the bit value at offset in the string value stored at key.
public mixed getbit ( $key, $offset ) | ||
$key | ||
$offset | ||
return | mixed |
---|
Get a substring of the string stored at a key.
public mixed getrange ( $key, $start, $end ) | ||
$key | ||
$start | ||
$end | ||
return | mixed |
---|
Set the string value of a key and return its old value.
public mixed getset ( $key, $value ) | ||
$key | ||
$value | ||
return | mixed |
---|
Delete one or more hash fields.
public mixed hdel ( $key, $fields ) | ||
$key | ||
$fields | ||
return | mixed |
---|
Determine if a hash field exists.
public mixed hexists ( $key, $field ) | ||
$key | ||
$field | ||
return | mixed |
---|
Get the value of a hash field.
public mixed hget ( $key, $field ) | ||
$key | ||
$field | ||
return | mixed |
---|
Get all the fields and values in a hash.
public mixed hgetall ( $key ) | ||
$key | ||
return | mixed |
---|
Increment the integer value of a hash field by the given number.
public mixed hincrby ( $key, $field, $increment ) | ||
$key | ||
$field | ||
$increment | ||
return | mixed |
---|
Increment the float value of a hash field by the given amount.
public mixed hincrbyfloat ( $key, $field, $increment ) | ||
$key | ||
$field | ||
$increment | ||
return | mixed |
---|
Get all the fields in a hash.
public mixed hkeys ( $key ) | ||
$key | ||
return | mixed |
---|
Get the number of fields in a hash.
public mixed hlen ( $key ) | ||
$key | ||
return | mixed |
---|
Get the values of all the given hash fields.
public mixed hmget ( $key, $fields ) | ||
$key | ||
$fields | ||
return | mixed |
---|
Set multiple hash fields to multiple values.
public mixed hmset ( $key, $field, $value, $more ) | ||
$key | ||
$field | ||
$value | ||
$more | ||
return | mixed |
---|
Incrementally iterate hash fields and associated values.
public mixed hscan ( $key, $cursor, $MATCH, $pattern, $COUNT, $count ) | ||
$key | ||
$cursor | ||
$MATCH | ||
$pattern | ||
$COUNT | ||
$count | ||
return | mixed |
---|
Set the string value of a hash field.
public mixed hset ( $key, $field, $value ) | ||
$key | ||
$field | ||
$value | ||
return | mixed |
---|
Set the value of a hash field, only if the field does not exist.
public mixed hsetnx ( $key, $field, $value ) | ||
$key | ||
$field | ||
$value | ||
return | mixed |
---|
Get the length of the value of a hash field.
public mixed hstrlen ( $key, $field ) | ||
$key | ||
$field | ||
return | mixed |
---|
Get all the values in a hash.
public mixed hvals ( $key ) | ||
$key | ||
return | mixed |
---|
Increment the integer value of a key by one.
public mixed incr ( $key ) | ||
$key | ||
return | mixed |
---|
Increment the integer value of a key by the given amount.
public mixed incrby ( $key, $increment ) | ||
$key | ||
$increment | ||
return | mixed |
---|
Increment the float value of a key by the given amount.
public mixed incrbyfloat ( $key, $increment ) | ||
$key | ||
$increment | ||
return | mixed |
---|
Get information and statistics about the server.
public mixed info ( $section ) | ||
$section | ||
return | mixed |
---|
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);
}
Find all keys matching the given pattern.
public mixed keys ( $pattern ) | ||
$pattern | ||
return | mixed |
---|
Get the UNIX time stamp of the last successful save to disk.
public mixed lastsave ( ) | ||
return | mixed |
---|
Get an element from a list by its index.
public mixed lindex ( $key, $index ) | ||
$key | ||
$index | ||
return | mixed |
---|
Insert an element before or after another element in a list.
public mixed linsert ( $key, $where, $pivot, $value ) | ||
$key | ||
$where | ||
$pivot | ||
$value | ||
return | mixed |
---|
Get the length of a list.
public mixed llen ( $key ) | ||
$key | ||
return | mixed |
---|
Remove and get the first element in a list.
public mixed lpop ( $key ) | ||
$key | ||
return | mixed |
---|
Prepend one or multiple values to a list.
public mixed lpush ( $key, $values ) | ||
$key | ||
$values | ||
return | mixed |
---|
Prepend a value to a list, only if the list exists.
public mixed lpushx ( $key, $value ) | ||
$key | ||
$value | ||
return | mixed |
---|
Get a range of elements from a list.
public mixed lrange ( $key, $start, $stop ) | ||
$key | ||
$start | ||
$stop | ||
return | mixed |
---|
Remove elements from a list.
public mixed lrem ( $key, $count, $value ) | ||
$key | ||
$count | ||
$value | ||
return | mixed |
---|
Set the value of an element in a list by its index.
public mixed lset ( $key, $index, $value ) | ||
$key | ||
$index | ||
$value | ||
return | mixed |
---|
Trim a list to the specified range.
public mixed ltrim ( $key, $start, $stop ) | ||
$key | ||
$start | ||
$stop | ||
return | mixed |
---|
Get the values of all the given keys.
public mixed mget ( $keys ) | ||
$keys | ||
return | mixed |
---|
Atomically transfer a key from a Redis instance to another one..
public mixed migrate ( $host, $port, $key, $destinationDb, $timeout, $options ) | ||
$host | ||
$port | ||
$key | ||
$destinationDb | ||
$timeout | ||
$options | ||
return | mixed |
---|
Listen for all requests received by the server in real time.
public mixed monitor ( ) | ||
return | mixed |
---|
Move a key to another database.
public mixed move ( $key, $db ) | ||
$key | ||
$db | ||
return | mixed |
---|
Set multiple keys to multiple values.
public mixed mset ( $keyValuePairs ) | ||
$keyValuePairs | ||
return | mixed |
---|
Set multiple keys to multiple values, only if none of the keys exist.
public mixed msetnx ( $keyValuePairs ) | ||
$keyValuePairs | ||
return | mixed |
---|
Mark the start of a transaction block.
public mixed multi ( ) | ||
return | mixed |
---|
Inspect the internals of Redis objects.
public mixed object ( $subcommand, $argumentss ) | ||
$subcommand | ||
$argumentss | ||
return | mixed |
---|
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);
}
}
Remove the expiration from a key.
public mixed persist ( $key ) | ||
$key | ||
return | mixed |
---|
Set a key's time to live in milliseconds.
public mixed pexpire ( $key, $milliseconds ) | ||
$key | ||
$milliseconds | ||
return | mixed |
---|
Set the expiration for a key as a UNIX timestamp specified in milliseconds.
public mixed pexpireat ( $key, $millisecondsTimestamp ) | ||
$key | ||
$millisecondsTimestamp | ||
return | mixed |
---|
Adds the specified elements to the specified HyperLogLog..
public mixed pfadd ( $key, $elements ) | ||
$key | ||
$elements | ||
return | mixed |
---|
Return the approximated cardinality of the set(s) observed by the HyperLogLog at key(s)..
public mixed pfcount ( $keys ) | ||
$keys | ||
return | mixed |
---|
Merge N different HyperLogLogs into a single one..
public mixed pfmerge ( $destkey, $sourcekeys ) | ||
$destkey | ||
$sourcekeys | ||
return | mixed |
---|
Ping the server.
public mixed ping ( $message ) | ||
$message | ||
return | mixed |
---|
Set the value and expiration in milliseconds of a key.
public mixed psetex ( $key, $milliseconds, $value ) | ||
$key | ||
$milliseconds | ||
$value | ||
return | mixed |
---|
Listen for messages published to channels matching the given patterns.
public mixed psubscribe ( $patterns ) | ||
$patterns | ||
return | mixed |
---|
Get the time to live for a key in milliseconds.
public mixed pttl ( $key ) | ||
$key | ||
return | mixed |
---|
Post a message to a channel.
public mixed publish ( $channel, $message ) | ||
$channel | ||
$message | ||
return | mixed |
---|
Inspect the state of the Pub/Sub subsystem.
public mixed pubsub ( $subcommand, $arguments ) | ||
$subcommand | ||
$arguments | ||
return | mixed |
---|
Stop listening for messages posted to channels matching the given patterns.
public mixed punsubscribe ( $patterns ) | ||
$patterns | ||
return | mixed |
---|
Close the connection.
public mixed quit ( ) | ||
return | mixed |
---|
Return a random key from the keyspace.
public mixed randomkey ( ) | ||
return | mixed |
---|
Enables read queries for a connection to a cluster slave node.
public mixed readonly ( ) | ||
return | mixed |
---|
Disables read queries for a connection to a cluster slave node.
public mixed readwrite ( ) | ||
return | mixed |
---|
Rename a key.
public mixed rename ( $key, $newkey ) | ||
$key | ||
$newkey | ||
return | mixed |
---|
Rename a key, only if the new key does not exist.
public mixed renamenx ( $key, $newkey ) | ||
$key | ||
$newkey | ||
return | mixed |
---|
Create a key using the provided serialized value, previously obtained using DUMP..
public mixed restore ( $key, $ttl, $serializedValue, $REPLACE ) | ||
$key | ||
$ttl | ||
$serializedValue | ||
$REPLACE | ||
return | mixed |
---|
Return the role of the instance in the context of replication.
public mixed role ( ) | ||
return | mixed |
---|
Remove and get the last element in a list.
public mixed rpop ( $key ) | ||
$key | ||
return | mixed |
---|
Remove the last element in a list, prepend it to another list and return it.
public mixed rpoplpush ( $source, $destination ) | ||
$source | ||
$destination | ||
return | mixed |
---|
Append one or multiple values to a list.
public mixed rpush ( $key, $values ) | ||
$key | ||
$values | ||
return | mixed |
---|
Append a value to a list, only if the list exists.
public mixed rpushx ( $key, $value ) | ||
$key | ||
$value | ||
return | mixed |
---|
Add one or more members to a set.
public mixed sadd ( $key, $members ) | ||
$key | ||
$members | ||
return | mixed |
---|
Synchronously save the dataset to disk.
public mixed save ( ) | ||
return | mixed |
---|
Incrementally iterate the keys space.
public mixed scan ( $cursor, $MATCH, $pattern, $COUNT, $count ) | ||
$cursor | ||
$MATCH | ||
$pattern | ||
$COUNT | ||
$count | ||
return | mixed |
---|
Get the number of members in a set.
public mixed scard ( $key ) | ||
$key | ||
return | mixed |
---|
Set the debug mode for executed scripts..
public mixed scriptDebug ( $option ) | ||
$option | ||
return | mixed |
---|
Check existence of scripts in the script cache..
public mixed scriptExists ( $sha1s ) | ||
$sha1s | ||
return | mixed |
---|
Remove all the scripts from the script cache..
public mixed scriptFlush ( ) | ||
return | mixed |
---|
Kill the script currently in execution..
public mixed scriptKill ( ) | ||
return | mixed |
---|
Load the specified Lua script into the script cache..
public mixed scriptLoad ( $script ) | ||
$script | ||
return | mixed |
---|
Subtract multiple sets.
public mixed sdiff ( $keys ) | ||
$keys | ||
return | mixed |
---|
Subtract multiple sets and store the resulting set in a key.
public mixed sdiffstore ( $destination, $keys ) | ||
$destination | ||
$keys | ||
return | mixed |
---|
Change the selected database for the current connection.
public mixed select ( $index ) | ||
$index | ||
return | mixed |
---|
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:
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 the string value of a key.
public mixed set ( $key, $value, $options ) | ||
$key | ||
$value | ||
$options | ||
return | mixed |
---|
Sets or clears the bit at offset in the string value stored at key.
public mixed setbit ( $key, $offset, $value ) | ||
$key | ||
$offset | ||
$value | ||
return | mixed |
---|
Set the value and expiration of a key.
public mixed setex ( $key, $seconds, $value ) | ||
$key | ||
$seconds | ||
$value | ||
return | mixed |
---|
Set the value of a key, only if the key does not exist.
public mixed setnx ( $key, $value ) | ||
$key | ||
$value | ||
return | mixed |
---|
Overwrite part of a string at key starting at the specified offset.
public mixed setrange ( $key, $offset, $value ) | ||
$key | ||
$offset | ||
$value | ||
return | mixed |
---|
Synchronously save the dataset to disk and then shut down the server.
public mixed shutdown ( $saveOption ) | ||
$saveOption | ||
return | mixed |
---|
Intersect multiple sets.
public mixed sinter ( $keys ) | ||
$keys | ||
return | mixed |
---|
Intersect multiple sets and store the resulting set in a key.
public mixed sinterstore ( $destination, $keys ) | ||
$destination | ||
$keys | ||
return | mixed |
---|
Determine if a given value is a member of a set.
public mixed sismember ( $key, $member ) | ||
$key | ||
$member | ||
return | mixed |
---|
Make the server a slave of another instance, or promote it as master.
public mixed slaveof ( $host, $port ) | ||
$host | ||
$port | ||
return | mixed |
---|
Manages the Redis slow queries log.
public mixed slowlog ( $subcommand, $argument ) | ||
$subcommand | ||
$argument | ||
return | mixed |
---|
Get all the members in a set.
public mixed smembers ( $key ) | ||
$key | ||
return | mixed |
---|
Move a member from one set to another.
public mixed smove ( $source, $destination, $member ) | ||
$source | ||
$destination | ||
$member | ||
return | mixed |
---|
Sort the elements in a list, set or sorted set.
public mixed sort ( $key, $options ) | ||
$key | ||
$options | ||
return | mixed |
---|
Remove and return one or multiple random members from a set.
public mixed spop ( $key, $count ) | ||
$key | ||
$count | ||
return | mixed |
---|
Get one or multiple random members from a set.
public mixed srandmember ( $key, $count ) | ||
$key | ||
$count | ||
return | mixed |
---|
Remove one or more members from a set.
public mixed srem ( $key, $members ) | ||
$key | ||
$members | ||
return | mixed |
---|
Incrementally iterate Set elements.
public mixed sscan ( $key, $cursor, $MATCH, $pattern, $COUNT, $count ) | ||
$key | ||
$cursor | ||
$MATCH | ||
$pattern | ||
$COUNT | ||
$count | ||
return | mixed |
---|
Get the length of the value stored in a key.
public mixed strlen ( $key ) | ||
$key | ||
return | mixed |
---|
Listen for messages published to the given channels.
public mixed subscribe ( $channels ) | ||
$channels | ||
return | mixed |
---|
Add multiple sets.
public mixed sunion ( $keys ) | ||
$keys | ||
return | mixed |
---|
Add multiple sets and store the resulting set in a key.
public mixed sunionstore ( $destination, $keys ) | ||
$destination | ||
$keys | ||
return | mixed |
---|
Swaps two Redis databases.
public mixed swapdb ( $index, $index ) | ||
$index | ||
$index | ||
return | mixed |
---|
Internal command used for replication.
public mixed sync ( ) | ||
return | mixed |
---|
Return the current server time.
public mixed time ( ) | ||
return | mixed |
---|
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 |
---|
Get the time to live for a key.
public mixed ttl ( $key ) | ||
$key | ||
return | mixed |
---|
Determine the type stored at key.
public mixed type ( $key ) | ||
$key | ||
return | mixed |
---|
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 |
---|
Stop listening for messages posted to the given channels.
public mixed unsubscribe ( $channels ) | ||
$channels | ||
return | mixed |
---|
Forget about all watched keys.
public mixed unwatch ( ) | ||
return | mixed |
---|
Wait for the synchronous replication of all the write commands sent in the context of the current connection.
public mixed wait ( $numslaves, $timeout ) | ||
$numslaves | ||
$timeout | ||
return | mixed |
---|
Watch the given keys to determine execution of the MULTI/EXEC block.
public mixed watch ( $keys ) | ||
$keys | ||
return | mixed |
---|
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 |
---|
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 |
---|
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 |
---|
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 |
---|
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 |
---|
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 |
---|
Returns the number of entries inside a stream https://redis.io/commands/xlen
public mixed xlen ( $stream ) | ||
$stream | ||
return | mixed |
---|
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 |
---|
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 |
---|
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 |
---|
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 |
---|
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 |
---|
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 |
---|
Add one or more members to a sorted set, or update its score if it already exists.
public mixed zadd ( $key, $options ) | ||
$key | ||
$options | ||
return | mixed |
---|
Get the number of members in a sorted set.
public mixed zcard ( $key ) | ||
$key | ||
return | mixed |
---|
Count the members in a sorted set with scores within the given values.
public mixed zcount ( $key, $min, $max ) | ||
$key | ||
$min | ||
$max | ||
return | mixed |
---|
Increment the score of a member in a sorted set.
public mixed zincrby ( $key, $increment, $member ) | ||
$key | ||
$increment | ||
$member | ||
return | mixed |
---|
Intersect multiple sorted sets and store the resulting sorted set in a new key.
public mixed zinterstore ( $destination, $numkeys, $key, $options ) | ||
$destination | ||
$numkeys | ||
$key | ||
$options | ||
return | mixed |
---|
Count the number of members in a sorted set between a given lexicographical range.
public mixed zlexcount ( $key, $min, $max ) | ||
$key | ||
$min | ||
$max | ||
return | mixed |
---|
Return a range of members in a sorted set, by index.
public mixed zrange ( $key, $start, $stop, $WITHSCORES ) | ||
$key | ||
$start | ||
$stop | ||
$WITHSCORES | ||
return | mixed |
---|
Return a range of members in a sorted set, by lexicographical range.
public mixed zrangebylex ( $key, $min, $max, $LIMIT, $offset, $count ) | ||
$key | ||
$min | ||
$max | ||
$LIMIT | ||
$offset | ||
$count | ||
return | mixed |
---|
Return a range of members in a sorted set, by score.
public mixed zrangebyscore ( $key, $min, $max, $options ) | ||
$key | ||
$min | ||
$max | ||
$options | ||
return | mixed |
---|
Determine the index of a member in a sorted set.
public mixed zrank ( $key, $member ) | ||
$key | ||
$member | ||
return | mixed |
---|
Remove one or more members from a sorted set.
public mixed zrem ( $key, $members ) | ||
$key | ||
$members | ||
return | mixed |
---|
Remove all members in a sorted set between the given lexicographical range.
public mixed zremrangebylex ( $key, $min, $max ) | ||
$key | ||
$min | ||
$max | ||
return | mixed |
---|
Remove all members in a sorted set within the given indexes.
public mixed zremrangebyrank ( $key, $start, $stop ) | ||
$key | ||
$start | ||
$stop | ||
return | mixed |
---|
Remove all members in a sorted set within the given scores.
public mixed zremrangebyscore ( $key, $min, $max ) | ||
$key | ||
$min | ||
$max | ||
return | mixed |
---|
Return a range of members in a sorted set, by index, with scores ordered from high to low.
public mixed zrevrange ( $key, $start, $stop, $WITHSCORES ) | ||
$key | ||
$start | ||
$stop | ||
$WITHSCORES | ||
return | mixed |
---|
Return a range of members in a sorted set, by lexicographical range, ordered from higher to lower strings..
public mixed zrevrangebylex ( $key, $max, $min, $LIMIT, $offset, $count ) | ||
$key | ||
$max | ||
$min | ||
$LIMIT | ||
$offset | ||
$count | ||
return | mixed |
---|
Return a range of members in a sorted set, by score, with scores ordered from high to low.
public mixed zrevrangebyscore ( $key, $max, $min, $WITHSCORES, $LIMIT, $offset, $count ) | ||
$key | ||
$max | ||
$min | ||
$WITHSCORES | ||
$LIMIT | ||
$offset | ||
$count | ||
return | mixed |
---|
Determine the index of a member in a sorted set, with scores ordered from high to low.
public mixed zrevrank ( $key, $member ) | ||
$key | ||
$member | ||
return | mixed |
---|
Incrementally iterate sorted sets elements and associated scores.
public mixed zscan ( $key, $cursor, $MATCH, $pattern, $COUNT, $count ) | ||
$key | ||
$cursor | ||
$MATCH | ||
$pattern | ||
$COUNT | ||
$count | ||
return | mixed |
---|
Get the score associated with the given member in a sorted set.
public mixed zscore ( $key, $member ) | ||
$key | ||
$member | ||
return | mixed |
---|
Add multiple sorted sets and store the resulting sorted set in a new key.
public mixed zunionstore ( $destination, $numkeys, $key, $options ) | ||
$destination | ||
$numkeys | ||
$key | ||
$options | ||
return | mixed |
---|