HumHub Documentation (unofficial)

Connection extends Component
in package

The redis connection class is used to establish a connection to a [redis](https://redis.io/) 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()]].

Tags
author

Carsten Brandt mail@cebe.cc

since
2.0

Table of Contents

Constants

EVENT_AFTER_OPEN  = 'afterOpen'

Properties

$behaviors  : array<string|int, Behavior>
$connectionString  : string
$connectionTimeout  : float
$contextOptions  : array<string|int, mixed>
$database  : int
$dataTimeout  : float
$driverName  : string
$hostname  : string
$isActive  : bool
$luaScriptBuilder  : LuaScriptBuilder
$password  : string
$port  : int
$redirectConnectionString  : string
$redisCommands  : array<string|int, mixed>
$retries  : int
$retryInterval  : int
$scheme  : string
$socket  : resource|false
$socketClientFlags  : int
$unixSocket  : string
$username  : string|null
$useSSL  : bool
$_behaviors  : array<string|int, Behavior>|null
$_events  : array<string|int, mixed>
$_eventWildcards  : array<string|int, mixed>
$_pool  : array<string|int, mixed>

Methods

__call()  : mixed
Allows issuing all supported commands via magic methods.
__clone()  : mixed
This method is called after the object is created by cloning an existing one.
__construct()  : mixed
Constructor.
__get()  : mixed
Returns the value of a component property.
__isset()  : bool
Checks if a property is set, i.e. defined and not null.
__set()  : mixed
Sets the value of a component property.
__sleep()  : array<string|int, mixed>
Closes the connection when this component is being serialized.
__unset()  : mixed
Sets a component property to be null.
append()  : mixed
attachBehavior()  : Behavior
Attaches a behavior to this component.
attachBehaviors()  : mixed
Attaches a list of behaviors to the component.
auth()  : mixed
behaviors()  : array<string|int, mixed>
Returns a list of behaviors that this component should behave as.
bgrewriteaof()  : mixed
bgsave()  : mixed
bitcount()  : mixed
bitfield()  : mixed
bitop()  : mixed
bitpos()  : mixed
blpop()  : mixed
brpop()  : mixed
brpoplpush()  : mixed
canGetProperty()  : bool
Returns a value indicating whether a property can be read.
canSetProperty()  : bool
Returns a value indicating whether a property can be set.
className()  : string
Returns the fully qualified name of this class.
clientGetname()  : mixed
clientKill()  : mixed
clientList()  : mixed
clientPause()  : mixed
clientReply()  : mixed
clientSetname()  : mixed
close()  : mixed
Closes the currently active DB connection.
clusterAddslots()  : mixed
clusterCountkeysinslot()  : mixed
clusterDelslots()  : mixed
clusterFailover()  : mixed
clusterForget()  : mixed
clusterGetkeysinslot()  : mixed
clusterInfo()  : mixed
clusterKeyslot()  : mixed
clusterMeet()  : mixed
clusterNodes()  : mixed
clusterReplicate()  : mixed
clusterReset()  : mixed
clusterSaveconfig()  : mixed
clusterSetslot()  : mixed
clusterSlaves()  : mixed
clusterSlots()  : mixed
command()  : mixed
commandCount()  : mixed
commandGetkeys()  : mixed
commandInfo()  : mixed
configGet()  : mixed
configResetstat()  : mixed
configRewrite()  : mixed
configSet()  : mixed
dbsize()  : mixed
debugObject()  : mixed
debugSegfault()  : mixed
decr()  : mixed
decrby()  : mixed
del()  : mixed
detachBehavior()  : Behavior|null
Detaches a behavior from the component.
detachBehaviors()  : mixed
Detaches all behaviors from the component.
discard()  : mixed
dump()  : mixed
echo()  : mixed
ensureBehaviors()  : mixed
Makes sure that the behaviors declared in [[behaviors()]] are attached to this component.
eval()  : mixed
evalsha()  : mixed
exec()  : mixed
executeCommand()  : array<string|int, mixed>|bool|null|string
Executes a redis command.
exists()  : mixed
expire()  : mixed
expireat()  : mixed
flushall()  : mixed
flushdb()  : mixed
geoadd()  : mixed
geodist()  : mixed
geohash()  : mixed
geopos()  : mixed
georadius()  : mixed
georadiusbymember()  : mixed
get()  : mixed
getBehavior()  : Behavior|null
Returns the named behavior object.
getBehaviors()  : array<string|int, Behavior>
Returns all behaviors attached to this component.
getbit()  : mixed
getConnectionString()  : string
Return the connection string used to open a socket connection. During a redirect (cluster mode) this will be the target of the redirect.
getDriverName()  : string
Returns the name of the DB driver for the current [[dsn]].
getIsActive()  : bool
Returns a value indicating whether the DB connection is established.
getLuaScriptBuilder()  : LuaScriptBuilder
getrange()  : mixed
getset()  : mixed
getSocket()  : resource|false
Return the connection resource if a connection to the target has been established before, `false` otherwise.
hasEventHandlers()  : bool
Returns a value indicating whether there is any handler attached to the named event.
hasMethod()  : bool
Returns a value indicating whether a method is defined.
hasProperty()  : bool
Returns a value indicating whether a property is defined for this component.
hdel()  : mixed
hexists()  : mixed
hget()  : mixed
hgetall()  : mixed
hincrby()  : mixed
hincrbyfloat()  : mixed
hkeys()  : mixed
hlen()  : mixed
hmget()  : mixed
hmset()  : mixed
hscan()  : mixed
hset()  : mixed
hsetnx()  : mixed
hstrlen()  : mixed
hvals()  : mixed
incr()  : mixed
incrby()  : mixed
incrbyfloat()  : mixed
info()  : mixed
init()  : mixed
Initializes the object.
keys()  : mixed
lastsave()  : mixed
lindex()  : mixed
linsert()  : mixed
llen()  : mixed
lpop()  : mixed
lpush()  : mixed
lpushx()  : mixed
lrange()  : mixed
lrem()  : mixed
lset()  : mixed
ltrim()  : mixed
mget()  : mixed
migrate()  : mixed
monitor()  : mixed
move()  : mixed
mset()  : mixed
msetnx()  : mixed
multi()  : mixed
object()  : mixed
off()  : bool
Detaches an existing event handler from this component.
on()  : mixed
Attaches an event handler to an event.
open()  : mixed
Establishes a DB connection.
persist()  : mixed
pexpire()  : mixed
pexpireat()  : mixed
pfadd()  : mixed
pfcount()  : mixed
pfmerge()  : mixed
ping()  : mixed
psetex()  : mixed
psubscribe()  : mixed
pttl()  : mixed
publish()  : mixed
pubsub()  : mixed
punsubscribe()  : mixed
quit()  : mixed
randomkey()  : mixed
readonly()  : mixed
readwrite()  : mixed
rename()  : mixed
renamenx()  : mixed
restore()  : mixed
role()  : mixed
rpop()  : mixed
rpoplpush()  : mixed
rpush()  : mixed
rpushx()  : mixed
sadd()  : mixed
save()  : mixed
scan()  : mixed
scard()  : mixed
scriptDebug()  : mixed
scriptExists()  : mixed
scriptFlush()  : mixed
scriptKill()  : mixed
scriptLoad()  : mixed
sdiff()  : mixed
sdiffstore()  : mixed
select()  : mixed
set()  : mixed
setbit()  : mixed
setex()  : mixed
setnx()  : mixed
setrange()  : mixed
shutdown()  : mixed
sinter()  : mixed
sinterstore()  : mixed
sismember()  : mixed
slaveof()  : mixed
slowlog()  : mixed
smembers()  : mixed
smove()  : mixed
sort()  : mixed
spop()  : mixed
srandmember()  : mixed
srem()  : mixed
sscan()  : mixed
strlen()  : mixed
subscribe()  : mixed
sunion()  : mixed
sunionstore()  : mixed
swapdb()  : mixed
sync()  : mixed
time()  : mixed
touch()  : mixed
trigger()  : mixed
Triggers an event.
ttl()  : mixed
type()  : mixed
unlink()  : mixed
unsubscribe()  : mixed
unwatch()  : mixed
wait()  : mixed
watch()  : mixed
xack()  : mixed
xadd()  : mixed
xclaim()  : mixed
xdel()  : mixed
xgroup()  : mixed
xinfo()  : mixed
xlen()  : mixed
xpending()  : mixed
xrange()  : mixed
xread()  : mixed
xreadgroup()  : mixed
xrevrange()  : mixed
xtrim()  : mixed
zadd()  : mixed
zcard()  : mixed
zcount()  : mixed
zincrby()  : mixed
zinterstore()  : mixed
zlexcount()  : mixed
zrange()  : mixed
zrangebylex()  : mixed
zrangebyscore()  : mixed
zrank()  : mixed
zrem()  : mixed
zremrangebylex()  : mixed
zremrangebyrank()  : mixed
zremrangebyscore()  : mixed
zrevrange()  : mixed
zrevrangebylex()  : mixed
zrevrangebyscore()  : mixed
zrevrank()  : mixed
zscan()  : mixed
zscore()  : mixed
zunionstore()  : mixed
initConnection()  : mixed
Initializes the DB connection.
sendRawCommand()  : array<string|int, mixed>|bool|null|string
Sends RAW command string to the server.
attachBehaviorInternal()  : Behavior
Attaches a behavior to this component.
isRedirect()  : bool
parseResponse()  : mixed
redirect()  : mixed

Constants

EVENT_AFTER_OPEN

public mixed EVENT_AFTER_OPEN = 'afterOpen'
Tags
event

Event an event that is triggered after a DB connection is established

Properties

$behaviors read-only

public array<string|int, Behavior> $behaviors

List of behaviors attached to this component.

$connectionString read-only

public string $connectionString

Socket connection string.

$connectionTimeout

public float $connectionTimeout

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

$database

public int $database = 0

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.

$dataTimeout

public float $dataTimeout

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

$driverName read-only

public string $driverName

Name of the DB driver.

$hostname

public string $hostname = 'localhost'

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.

$isActive read-only

public bool $isActive

Whether the DB connection is established.

$password

public string $password

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

$port

public int $port = 6379

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

$redirectConnectionString

public string $redirectConnectionString

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

Tags
since
2.0.11

$redisCommands

public array<string|int, mixed> $redisCommands = [ 'APPEND', // Append a value to a key 'AUTH', // Authenticate to the server 'BGREWRITEAOF', // Asynchronously rewrite the append-only file 'BGSAVE', // Asynchronously save the dataset to disk 'BITCOUNT', // Count set bits in a string 'BITFIELD', // Perform arbitrary bitfield integer operations on strings 'BITOP', // Perform bitwise operations between strings 'BITPOS', // Find first bit set or clear in a string 'BLPOP', // Remove and get the first element in a list, or block until one is available 'BRPOP', // Remove and get the last element in a list, or block until one is available 'BRPOPLPUSH', // Pop a value from a list, push it to another list and return it; or block until one is available 'CLIENT KILL', // Kill the connection of a client 'CLIENT LIST', // Get the list of client connections 'CLIENT GETNAME', // Get the current connection name 'CLIENT PAUSE', // Stop processing commands from clients for some time 'CLIENT REPLY', // Instruct the server whether to reply to commands 'CLIENT SETNAME', // Set the current connection name 'CLUSTER ADDSLOTS', // Assign new hash slots to receiving node 'CLUSTER COUNTKEYSINSLOT', // Return the number of local keys in the specified hash slot 'CLUSTER DELSLOTS', // Set hash slots as unbound in receiving node 'CLUSTER FAILOVER', // Forces a slave to perform a manual failover of its master. 'CLUSTER FORGET', // Remove a node from the nodes table 'CLUSTER GETKEYSINSLOT', // Return local key names in the specified hash slot 'CLUSTER INFO', // Provides info about Redis Cluster node state 'CLUSTER KEYSLOT', // Returns the hash slot of the specified key 'CLUSTER MEET', // Force a node cluster to handshake with another node 'CLUSTER NODES', // Get Cluster config for the node 'CLUSTER REPLICATE', // Reconfigure a node as a slave of the specified master node 'CLUSTER RESET', // Reset a Redis Cluster node 'CLUSTER SAVECONFIG', // Forces the node to save cluster state on disk 'CLUSTER SETSLOT', // Bind a hash slot to a specific node 'CLUSTER SLAVES', // List slave nodes of the specified master node 'CLUSTER SLOTS', // Get array of Cluster slot to node mappings 'COMMAND', // Get array of Redis command details 'COMMAND COUNT', // Get total number of Redis commands 'COMMAND GETKEYS', // Extract keys given a full Redis command 'COMMAND INFO', // Get array of specific Redis command details 'CONFIG GET', // Get the value of a configuration parameter 'CONFIG REWRITE', // Rewrite the configuration file with the in memory configuration 'CONFIG SET', // Set a configuration parameter to the given value 'CONFIG RESETSTAT', // Reset the stats returned by INFO 'DBSIZE', // Return the number of keys in the selected database 'DEBUG OBJECT', // Get debugging information about a key 'DEBUG SEGFAULT', // Make the server crash 'DECR', // Decrement the integer value of a key by one 'DECRBY', // Decrement the integer value of a key by the given number 'DEL', // Delete a key 'DISCARD', // Discard all commands issued after MULTI 'DUMP', // Return a serialized version of the value stored at the specified key. 'ECHO', // Echo the given string 'EVAL', // Execute a Lua script server side 'EVALSHA', // Execute a Lua script server side 'EXEC', // Execute all commands issued after MULTI 'EXISTS', // Determine if a key exists 'EXPIRE', // Set a key's time to live in seconds 'EXPIREAT', // Set the expiration for a key as a UNIX timestamp 'FLUSHALL', // Remove all keys from all databases 'FLUSHDB', // Remove all keys from the current database 'GEOADD', // Add one or more geospatial items in the geospatial index represented using a sorted set 'GEOHASH', // Returns members of a geospatial index as standard geohash strings 'GEOPOS', // Returns longitude and latitude of members of a geospatial index 'GEODIST', // Returns the distance between two members of a geospatial index 'GEORADIUS', // Query a sorted set representing a geospatial index to fetch members matching a given maximum distance from a point 'GEORADIUSBYMEMBER', // Query a sorted set representing a geospatial index to fetch members matching a given maximum distance from a member 'GET', // Get the value of a key 'GETBIT', // Returns the bit value at offset in the string value stored at key 'GETRANGE', // Get a substring of the string stored at a key 'GETSET', // Set the string value of a key and return its old value 'HDEL', // Delete one or more hash fields 'HEXISTS', // Determine if a hash field exists 'HGET', // Get the value of a hash field 'HGETALL', // Get all the fields and values in a hash 'HINCRBY', // Increment the integer value of a hash field by the given number 'HINCRBYFLOAT', // Increment the float value of a hash field by the given amount 'HKEYS', // Get all the fields in a hash 'HLEN', // Get the number of fields in a hash 'HMGET', // Get the values of all the given hash fields 'HMSET', // Set multiple hash fields to multiple values 'HSET', // Set the string value of a hash field 'HSETNX', // Set the value of a hash field, only if the field does not exist 'HSTRLEN', // Get the length of the value of a hash field 'HVALS', // Get all the values in a hash 'INCR', // Increment the integer value of a key by one 'INCRBY', // Increment the integer value of a key by the given amount 'INCRBYFLOAT', // Increment the float value of a key by the given amount 'INFO', // Get information and statistics about the server 'KEYS', // Find all keys matching the given pattern 'LASTSAVE', // Get the UNIX time stamp of the last successful save to disk 'LINDEX', // Get an element from a list by its index 'LINSERT', // Insert an element before or after another element in a list 'LLEN', // Get the length of a list 'LPOP', // Remove and get the first element in a list 'LPUSH', // Prepend one or multiple values to a list 'LPUSHX', // Prepend a value to a list, only if the list exists 'LRANGE', // Get a range of elements from a list 'LREM', // Remove elements from a list 'LSET', // Set the value of an element in a list by its index 'LTRIM', // Trim a list to the specified range 'MGET', // Get the values of all the given keys 'MIGRATE', // Atomically transfer a key from a Redis instance to another one. 'MONITOR', // Listen for all requests received by the server in real time 'MOVE', // Move a key to another database 'MSET', // Set multiple keys to multiple values 'MSETNX', // Set multiple keys to multiple values, only if none of the keys exist 'MULTI', // Mark the start of a transaction block 'OBJECT', // Inspect the internals of Redis objects 'PERSIST', // Remove the expiration from a key 'PEXPIRE', // Set a key's time to live in milliseconds 'PEXPIREAT', // Set the expiration for a key as a UNIX timestamp specified in milliseconds 'PFADD', // Adds the specified elements to the specified HyperLogLog. 'PFCOUNT', // Return the approximated cardinality of the set(s) observed by the HyperLogLog at key(s). 'PFMERGE', // Merge N different HyperLogLogs into a single one. 'PING', // Ping the server 'PSETEX', // Set the value and expiration in milliseconds of a key 'PSUBSCRIBE', // Listen for messages published to channels matching the given patterns 'PUBSUB', // Inspect the state of the Pub/Sub subsystem 'PTTL', // Get the time to live for a key in milliseconds 'PUBLISH', // Post a message to a channel 'PUNSUBSCRIBE', // Stop listening for messages posted to channels matching the given patterns 'QUIT', // Close the connection 'RANDOMKEY', // Return a random key from the keyspace 'READONLY', // Enables read queries for a connection to a cluster slave node 'READWRITE', // Disables read queries for a connection to a cluster slave node 'RENAME', // Rename a key 'RENAMENX', // Rename a key, only if the new key does not exist 'RESTORE', // Create a key using the provided serialized value, previously obtained using DUMP. 'ROLE', // Return the role of the instance in the context of replication 'RPOP', // Remove and get the last element in a list 'RPOPLPUSH', // Remove the last element in a list, prepend it to another list and return it 'RPUSH', // Append one or multiple values to a list 'RPUSHX', // Append a value to a list, only if the list exists 'SADD', // Add one or more members to a set 'SAVE', // Synchronously save the dataset to disk 'SCARD', // Get the number of members in a set 'SCRIPT DEBUG', // Set the debug mode for executed scripts. 'SCRIPT EXISTS', // Check existence of scripts in the script cache. 'SCRIPT FLUSH', // Remove all the scripts from the script cache. 'SCRIPT KILL', // Kill the script currently in execution. 'SCRIPT LOAD', // Load the specified Lua script into the script cache. 'SDIFF', // Subtract multiple sets 'SDIFFSTORE', // Subtract multiple sets and store the resulting set in a key 'SELECT', // Change the selected database for the current connection 'SET', // Set the string value of a key 'SETBIT', // Sets or clears the bit at offset in the string value stored at key 'SETEX', // Set the value and expiration of a key 'SETNX', // Set the value of a key, only if the key does not exist 'SETRANGE', // Overwrite part of a string at key starting at the specified offset 'SHUTDOWN', // Synchronously save the dataset to disk and then shut down the server 'SINTER', // Intersect multiple sets 'SINTERSTORE', // Intersect multiple sets and store the resulting set in a key 'SISMEMBER', // Determine if a given value is a member of a set 'SLAVEOF', // Make the server a slave of another instance, or promote it as master 'SLOWLOG', // Manages the Redis slow queries log 'SMEMBERS', // Get all the members in a set 'SMOVE', // Move a member from one set to another 'SORT', // Sort the elements in a list, set or sorted set 'SPOP', // Remove and return one or multiple random members from a set 'SRANDMEMBER', // Get one or multiple random members from a set 'SREM', // Remove one or more members from a set 'STRLEN', // Get the length of the value stored in a key 'SUBSCRIBE', // Listen for messages published to the given channels 'SUNION', // Add multiple sets 'SUNIONSTORE', // Add multiple sets and store the resulting set in a key 'SWAPDB', // Swaps two Redis databases 'SYNC', // Internal command used for replication 'TIME', // Return the current server time 'TOUCH', // Alters the last access time of a key(s). Returns the number of existing keys specified. 'TTL', // Get the time to live for a key 'TYPE', // Determine the type stored at key 'UNSUBSCRIBE', // Stop listening for messages posted to the given channels 'UNLINK', // Delete a key asynchronously in another thread. Otherwise it is just as DEL, but non blocking. 'UNWATCH', // Forget about all watched keys 'WAIT', // Wait for the synchronous replication of all the write commands sent in the context of the current connection 'WATCH', // Watch the given keys to determine execution of the MULTI/EXEC block 'XACK', // Removes one or multiple messages from the pending entries list (PEL) of a stream consumer group 'XADD', // Appends the specified stream entry to the stream at the specified key 'XCLAIM', // Changes the ownership of a pending message, so that the new owner is the consumer specified as the command argument 'XDEL', // Removes the specified entries from a stream, and returns the number of entries deleted 'XGROUP', // Manages the consumer groups associated with a stream data structure 'XINFO', // Retrieves different information about the streams and associated consumer groups 'XLEN', // Returns the number of entries inside a stream 'XPENDING', // Fetching data from a stream via a consumer group, and not acknowledging such data, has the effect of creating pending entries 'XRANGE', // Returns the stream entries matching a given range of IDs 'XREAD', // Read data from one or multiple streams, only returning entries with an ID greater than the last received ID reported by the caller 'XREADGROUP', // Special version of the XREAD command with support for consumer groups '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 'XTRIM', // Trims the stream to a given number of items, evicting older items (items with lower IDs) if needed 'ZADD', // Add one or more members to a sorted set, or update its score if it already exists 'ZCARD', // Get the number of members in a sorted set 'ZCOUNT', // Count the members in a sorted set with scores within the given values 'ZINCRBY', // Increment the score of a member in a sorted set 'ZINTERSTORE', // Intersect multiple sorted sets and store the resulting sorted set in a new key 'ZLEXCOUNT', // Count the number of members in a sorted set between a given lexicographical range 'ZRANGE', // Return a range of members in a sorted set, by index 'ZRANGEBYLEX', // Return a range of members in a sorted set, by lexicographical range 'ZREVRANGEBYLEX', // Return a range of members in a sorted set, by lexicographical range, ordered from higher to lower strings. 'ZRANGEBYSCORE', // Return a range of members in a sorted set, by score 'ZRANK', // Determine the index of a member in a sorted set 'ZREM', // Remove one or more members from a sorted set 'ZREMRANGEBYLEX', // Remove all members in a sorted set between the given lexicographical range 'ZREMRANGEBYRANK', // Remove all members in a sorted set within the given indexes 'ZREMRANGEBYSCORE', // Remove all members in a sorted set within the given scores 'ZREVRANGE', // Return a range of members in a sorted set, by index, with scores ordered from high to low 'ZREVRANGEBYSCORE', // Return a range of members in a sorted set, by score, with scores ordered from high to low 'ZREVRANK', // Determine the index of a member in a sorted set, with scores ordered from high to low 'ZSCORE', // Get the score associated with the given member in a sorted set 'ZUNIONSTORE', // Add multiple sorted sets and store the resulting sorted set in a new key 'SCAN', // Incrementally iterate the keys space 'SSCAN', // Incrementally iterate Set elements 'HSCAN', // Incrementally iterate hash fields and associated values 'ZSCAN', ]

List of available redis commands.

Tags
see
https://redis.io/commands

$retries

public int $retries = 0

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

Tags
since
2.0.7

$retryInterval

public int $retryInterval = 0

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

Tags
since
2.0.10

$scheme

public string $scheme = 'tcp'

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

Tags
since
2.0.18

$socketClientFlags

public int $socketClientFlags = STREAM_CLIENT_CONNECT

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 [[$database|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'
Tags
see
https://www.php.net/manual/en/function.stream-socket-client.php
since
2.0.5

$unixSocket

public string $unixSocket

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.

Tags
since
2.0.1

$useSSL

public bool $useSSL = false

Send sockets over SSL protocol. Default state is false.

Tags
since
2.0.12

$_behaviors

private array<string|int, Behavior>|null $_behaviors

the attached behaviors (behavior name => behavior). This is null when not initialized.

$_events

private array<string|int, mixed> $_events = []

the attached event handlers (event name => handlers)

$_eventWildcards

private array<string|int, mixed> $_eventWildcards = []

the event handlers attached for wildcard patterns (event name wildcard => handlers)

Tags
since
2.0.14

$_pool

private array<string|int, mixed> $_pool = []

redis redirect socket connection pool

Methods

__call()

Allows issuing all supported commands via magic methods.

public __call(string $name, array<string|int, mixed> $params) : mixed
$redis->hmset('test_collection', 'key1', 'val1', 'key2', 'val2')
Parameters
$name : string

name of the missing method to execute

$params : array<string|int, mixed>

method call arguments

__clone()

This method is called after the object is created by cloning an existing one.

public __clone() : mixed

It removes all behaviors because they are attached to the old object.

__construct()

Constructor.

public __construct([array<string|int, mixed> $config = [] ]) : mixed

The default implementation does two things:

  • Initializes the object with the given configuration $config.
  • Call [[init()]].

If this method is overridden in a child class, it is recommended that

  • the last parameter of the constructor is a configuration array, like $config here.
  • call the parent implementation at the end of the constructor.
Parameters
$config : array<string|int, mixed> = []

name-value pairs that will be used to initialize the object properties

__get()

Returns the value of a component property.

public __get(string $name) : mixed

This method will check in the following order and act accordingly:

  • a property defined by a getter: return the getter result
  • a property of a behavior: return the behavior property value

Do not call this method directly as it is a PHP magic method that will be implicitly called when executing $value = $component->property;.

Parameters
$name : string

the property name

Tags
throws
UnknownPropertyException

if the property is not defined

throws
InvalidCallException

if the property is write-only.

see
__set()
Return values
mixed

the property value or the value of a behavior's property

__isset()

Checks if a property is set, i.e. defined and not null.

public __isset(string $name) : bool

This method will check in the following order and act accordingly:

  • a property defined by a setter: return whether the property is set
  • a property of a behavior: return whether the property is set
  • return false for non existing properties

Do not call this method directly as it is a PHP magic method that will be implicitly called when executing isset($component->property).

Parameters
$name : string

the property name or the event name

Tags
see
https://www.php.net/manual/en/function.isset.php
Return values
bool

whether the named property is set

__set()

Sets the value of a component property.

public __set(string $name, mixed $value) : mixed

This method will check in the following order and act accordingly:

  • a property defined by a setter: set the property value
  • an event in the format of "on xyz": attach the handler to the event "xyz"
  • a behavior in the format of "as xyz": attach the behavior named as "xyz"
  • a property of a behavior: set the behavior property value

Do not call this method directly as it is a PHP magic method that will be implicitly called when executing $component->property = $value;.

Parameters
$name : string

the property name or the event name

$value : mixed

the property value

Tags
throws
UnknownPropertyException

if the property is not defined

throws
InvalidCallException

if the property is read-only.

see
__get()

__sleep()

Closes the connection when this component is being serialized.

public __sleep() : array<string|int, mixed>
Return values
array<string|int, mixed>

__unset()

Sets a component property to be null.

public __unset(string $name) : mixed

This method will check in the following order and act accordingly:

  • a property defined by a setter: set the property value to be null
  • a property of a behavior: set the property value to be null

Do not call this method directly as it is a PHP magic method that will be implicitly called when executing unset($component->property).

Parameters
$name : string

the property name

Tags
throws
InvalidCallException

if the property is read only.

see
https://www.php.net/manual/en/function.unset.php

attachBehavior()

Attaches a behavior to this component.

public attachBehavior(string $name, string|array<string|int, mixed>|Behavior $behavior) : Behavior

This method will create the behavior object based on the given configuration. After that, the behavior object will be attached to this component by calling the [[Behavior::attach()]] method.

Parameters
$name : string

the name of the behavior.

$behavior : string|array<string|int, mixed>|Behavior

the behavior configuration. This can be one of the following:

  • a [[Behavior]] object
  • a string specifying the behavior class
  • an object configuration array that will be passed to [[Yii::createObject()]] to create the behavior object.
Tags
see
detachBehavior()
Return values
Behavior

the behavior object

attachBehaviors()

Attaches a list of behaviors to the component.

public attachBehaviors(array<string|int, mixed> $behaviors) : mixed

Each behavior is indexed by its name and should be a [[Behavior]] object, a string specifying the behavior class, or an configuration array for creating the behavior.

Parameters
$behaviors : array<string|int, mixed>

list of behaviors to be attached to the component

Tags
see
attachBehavior()

behaviors()

Returns a list of behaviors that this component should behave as.

public behaviors() : array<string|int, mixed>

Child classes may override this method to specify the behaviors they want to behave as.

The return value of this method should be an array of behavior objects or configurations indexed by behavior names. A behavior configuration can be either a string specifying the behavior class or an array of the following structure:

'behaviorName' => [
    'class' => 'BehaviorClass',
    'property1' => 'value1',
    'property2' => 'value2',
]

Note that a behavior class must extend from [[Behavior]]. Behaviors can be attached using a name or anonymously. When a name is used as the array key, using this name, the behavior can later be retrieved using [[getBehavior()]] or be detached using [[detachBehavior()]]. Anonymous behaviors can not be retrieved or detached.

Behaviors declared in this method will be attached to the component automatically (on demand).

Return values
array<string|int, mixed>

the behavior configurations.

bitcount()

public bitcount([mixed $key = ][, mixed $start = null ][, mixed $end = null ]) : mixed

Count set bits in a string. https://redis.io/commands/bitcount

Parameters
$key : mixed =
$start : mixed = null
$end : mixed = null

bitfield()

public bitfield([mixed $key = ][, mixed ...$operations = ]) : mixed

Perform arbitrary bitfield integer operations on strings. https://redis.io/commands/bitfield

Parameters
$key : mixed =
$operations : mixed =

bitop()

public bitop([mixed $operation = ][, mixed $destkey = ][, mixed ...$keys = ]) : mixed

Perform bitwise operations between strings. https://redis.io/commands/bitop

Parameters
$operation : mixed =
$destkey : mixed =
$keys : mixed =

bitpos()

public bitpos([mixed $key = ][, mixed $bit = ][, mixed $start = null ][, mixed $end = null ]) : mixed

Find first bit set or clear in a string. https://redis.io/commands/bitpos

Parameters
$key : mixed =
$bit : mixed =
$start : mixed = null
$end : mixed = null

blpop()

public blpop([mixed ...$keys = ][, mixed $timeout = ]) : mixed

Remove and get the first element in a list, or block until one is available. https://redis.io/commands/blpop

Parameters
$keys : mixed =
$timeout : mixed =

brpop()

public brpop([mixed ...$keys = ][, mixed $timeout = ]) : mixed

Remove and get the last element in a list, or block until one is available. https://redis.io/commands/brpop

Parameters
$keys : mixed =
$timeout : mixed =

brpoplpush()

public brpoplpush([mixed $source = ][, mixed $destination = ][, mixed $timeout = ]) : mixed

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

Parameters
$source : mixed =
$destination : mixed =
$timeout : mixed =

canGetProperty()

Returns a value indicating whether a property can be read.

public canGetProperty(string $name[, bool $checkVars = true ][, bool $checkBehaviors = true ]) : bool

A property can be read if:

  • the class has a getter method associated with the specified name (in this case, property name is case-insensitive);
  • the class has a member variable with the specified name (when $checkVars is true);
  • an attached behavior has a readable property of the given name (when $checkBehaviors is true).
Parameters
$name : string

the property name

$checkVars : bool = true

whether to treat member variables as properties

$checkBehaviors : bool = true

whether to treat behaviors' properties as properties of this component

Tags
see
canSetProperty()
Return values
bool

whether the property can be read

canSetProperty()

Returns a value indicating whether a property can be set.

public canSetProperty(string $name[, bool $checkVars = true ][, bool $checkBehaviors = true ]) : bool

A property can be written if:

  • the class has a setter method associated with the specified name (in this case, property name is case-insensitive);
  • the class has a member variable with the specified name (when $checkVars is true);
  • an attached behavior has a writable property of the given name (when $checkBehaviors is true).
Parameters
$name : string

the property name

$checkVars : bool = true

whether to treat member variables as properties

$checkBehaviors : bool = true

whether to treat behaviors' properties as properties of this component

Tags
see
canGetProperty()
Return values
bool

whether the property can be written

className()

Returns the fully qualified name of this class.

public static className() : string
Tags
deprecated

since 2.0.14. On PHP >=5.5, use ::class instead.

Return values
string

the fully qualified name of this class.

close()

Closes the currently active DB connection.

public close() : mixed

It does nothing if the connection is already closed.

clusterSetslot()

public clusterSetslot([mixed $slot = ][, mixed $type = ][, mixed $nodeid = null ]) : mixed

Bind a hash slot to a specific node. https://redis.io/commands/cluster-setslot

Parameters
$slot : mixed =
$type : mixed =
$nodeid : mixed = null

decrby()

public decrby([mixed $key = ][, mixed $decrement = ]) : mixed

Decrement the integer value of a key by the given number. https://redis.io/commands/decrby

Parameters
$key : mixed =
$decrement : mixed =

detachBehavior()

Detaches a behavior from the component.

public detachBehavior(string $name) : Behavior|null

The behavior's [[Behavior::detach()]] method will be invoked.

Parameters
$name : string

the behavior's name.

Return values
Behavior|null

the detached behavior. Null if the behavior does not exist.

detachBehaviors()

Detaches all behaviors from the component.

public detachBehaviors() : mixed

ensureBehaviors()

Makes sure that the behaviors declared in [[behaviors()]] are attached to this component.

public ensureBehaviors() : mixed

eval()

public eval([mixed $script = ][, mixed $numkeys = ][, mixed ...$keys = ][, mixed ...$args = ]) : mixed

Execute a Lua script server side. https://redis.io/commands/eval

Parameters
$script : mixed =
$numkeys : mixed =
$keys : mixed =
$args : mixed =

evalsha()

public evalsha([mixed $sha1 = ][, mixed $numkeys = ][, mixed ...$keys = ][, mixed ...$args = ]) : mixed

Execute a Lua script server side. https://redis.io/commands/evalsha

Parameters
$sha1 : mixed =
$numkeys : mixed =
$keys : mixed =
$args : mixed =

executeCommand()

Executes a redis command.

public executeCommand(string $name[, array<string|int, mixed> $params = [] ]) : array<string|int, mixed>|bool|null|string

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']);
Parameters
$name : string

the name of the command

$params : array<string|int, mixed> = []

list of parameters for the command

Tags
throws
Exception

for commands that return error reply.

Return values
array<string|int, mixed>|bool|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.

geoadd()

public geoadd([mixed $key = ][, mixed $longitude = ][, mixed $latitude = ][, mixed $member = ][, mixed ...$more = ]) : mixed

Add one or more geospatial items in the geospatial index represented using a sorted set. https://redis.io/commands/geoadd

Parameters
$key : mixed =
$longitude : mixed =
$latitude : mixed =
$member : mixed =
$more : mixed =

geodist()

public geodist([mixed $key = ][, mixed $member1 = ][, mixed $member2 = ][, mixed $unit = null ]) : mixed

Returns the distance between two members of a geospatial index. https://redis.io/commands/geodist

Parameters
$key : mixed =
$member1 : mixed =
$member2 : mixed =
$unit : mixed = null

geohash()

public geohash([mixed $key = ][, mixed ...$members = ]) : mixed

Returns members of a geospatial index as standard geohash strings. https://redis.io/commands/geohash

Parameters
$key : mixed =
$members : mixed =

geopos()

public geopos([mixed $key = ][, mixed ...$members = ]) : mixed

Returns longitude and latitude of members of a geospatial index. https://redis.io/commands/geopos

Parameters
$key : mixed =
$members : mixed =

georadius()

public georadius([mixed $key = ][, mixed $longitude = ][, mixed $latitude = ][, mixed $radius = ][, mixed $metric = ][, mixed ...$options = ]) : mixed

Query a sorted set representing a geospatial index to fetch members matching a given maximum distance from a point. https://redis.io/commands/georadius

Parameters
$key : mixed =
$longitude : mixed =
$latitude : mixed =
$radius : mixed =
$metric : mixed =
$options : mixed =

georadiusbymember()

public georadiusbymember([mixed $key = ][, mixed $member = ][, mixed $radius = ][, mixed $metric = ][, mixed ...$options = ]) : mixed

Query a sorted set representing a geospatial index to fetch members matching a given maximum distance from a member. https://redis.io/commands/georadiusbymember

Parameters
$key : mixed =
$member : mixed =
$radius : mixed =
$metric : mixed =
$options : mixed =

getBehavior()

Returns the named behavior object.

public getBehavior(string $name) : Behavior|null
Parameters
$name : string

the behavior name

Return values
Behavior|null

the behavior object, or null if the behavior does not exist

getBehaviors()

Returns all behaviors attached to this component.

public getBehaviors() : array<string|int, Behavior>
Return values
array<string|int, Behavior>

list of behaviors attached to this component

getbit()

public getbit([mixed $key = ][, mixed $offset = ]) : mixed

Returns the bit value at offset in the string value stored at key. https://redis.io/commands/getbit

Parameters
$key : mixed =
$offset : mixed =

getConnectionString()

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

public getConnectionString() : string
Tags
since
2.0.11
Return values
string

socket connection string

getDriverName()

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

public getDriverName() : string
Return values
string

name of the DB driver

getIsActive()

Returns a value indicating whether the DB connection is established.

public getIsActive() : bool
Return values
bool

whether the DB connection is established

getrange()

public getrange([mixed $key = ][, mixed $start = ][, mixed $end = ]) : mixed

Get a substring of the string stored at a key. https://redis.io/commands/getrange

Parameters
$key : mixed =
$start : mixed =
$end : mixed =

getSocket()

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

public getSocket() : resource|false
Return values
resource|false

hasEventHandlers()

Returns a value indicating whether there is any handler attached to the named event.

public hasEventHandlers(string $name) : bool
Parameters
$name : string

the event name

Return values
bool

whether there is any handler attached to the event.

hasMethod()

Returns a value indicating whether a method is defined.

public hasMethod(string $name[, bool $checkBehaviors = true ]) : bool

A method is defined if:

  • the class has a method with the specified name
  • an attached behavior has a method with the given name (when $checkBehaviors is true).
Parameters
$name : string

the property name

$checkBehaviors : bool = true

whether to treat behaviors' methods as methods of this component

Return values
bool

whether the method is defined

hasProperty()

Returns a value indicating whether a property is defined for this component.

public hasProperty(string $name[, bool $checkVars = true ][, bool $checkBehaviors = true ]) : bool

A property is defined if:

  • the class has a getter or setter method associated with the specified name (in this case, property name is case-insensitive);
  • the class has a member variable with the specified name (when $checkVars is true);
  • an attached behavior has a property of the given name (when $checkBehaviors is true).
Parameters
$name : string

the property name

$checkVars : bool = true

whether to treat member variables as properties

$checkBehaviors : bool = true

whether to treat behaviors' properties as properties of this component

Tags
see
canGetProperty()
see
canSetProperty()
Return values
bool

whether the property is defined

hincrby()

public hincrby([mixed $key = ][, mixed $field = ][, mixed $increment = ]) : mixed

Increment the integer value of a hash field by the given number. https://redis.io/commands/hincrby

Parameters
$key : mixed =
$field : mixed =
$increment : mixed =

hincrbyfloat()

public hincrbyfloat([mixed $key = ][, mixed $field = ][, mixed $increment = ]) : mixed

Increment the float value of a hash field by the given amount. https://redis.io/commands/hincrbyfloat

Parameters
$key : mixed =
$field : mixed =
$increment : mixed =

hmset()

public hmset([mixed $key = ][, mixed $field = ][, mixed $value = ][, mixed ...$more = ]) : mixed

Set multiple hash fields to multiple values. https://redis.io/commands/hmset

Parameters
$key : mixed =
$field : mixed =
$value : mixed =
$more : mixed =

hscan()

public hscan([mixed $key = ][, mixed $cursor = ][, mixed $MATCH = null ][, mixed $pattern = null ][, mixed $COUNT = null ][, mixed $count = null ]) : mixed

Incrementally iterate hash fields and associated values. https://redis.io/commands/hscan

Parameters
$key : mixed =
$cursor : mixed =
$MATCH : mixed = null
$pattern : mixed = null
$COUNT : mixed = null
$count : mixed = null

hset()

public hset([mixed $key = ][, mixed $field = ][, mixed $value = ]) : mixed

Set the string value of a hash field. https://redis.io/commands/hset

Parameters
$key : mixed =
$field : mixed =
$value : mixed =

hsetnx()

public hsetnx([mixed $key = ][, mixed $field = ][, mixed $value = ]) : mixed

Set the value of a hash field, only if the field does not exist. https://redis.io/commands/hsetnx

Parameters
$key : mixed =
$field : mixed =
$value : mixed =

incrby()

public incrby([mixed $key = ][, mixed $increment = ]) : mixed

Increment the integer value of a key by the given amount. https://redis.io/commands/incrby

Parameters
$key : mixed =
$increment : mixed =

init()

Initializes the object.

public init() : mixed

This method is invoked at the end of the constructor after the object is initialized with the given configuration.

linsert()

public linsert([mixed $key = ][, mixed $where = ][, mixed $pivot = ][, mixed $value = ]) : mixed

Insert an element before or after another element in a list. https://redis.io/commands/linsert

Parameters
$key : mixed =
$where : mixed =
$pivot : mixed =
$value : mixed =

lrange()

public lrange([mixed $key = ][, mixed $start = ][, mixed $stop = ]) : mixed

Get a range of elements from a list. https://redis.io/commands/lrange

Parameters
$key : mixed =
$start : mixed =
$stop : mixed =

lrem()

public lrem([mixed $key = ][, mixed $count = ][, mixed $value = ]) : mixed

Remove elements from a list. https://redis.io/commands/lrem

Parameters
$key : mixed =
$count : mixed =
$value : mixed =

lset()

public lset([mixed $key = ][, mixed $index = ][, mixed $value = ]) : mixed

Set the value of an element in a list by its index. https://redis.io/commands/lset

Parameters
$key : mixed =
$index : mixed =
$value : mixed =

ltrim()

public ltrim([mixed $key = ][, mixed $start = ][, mixed $stop = ]) : mixed

Trim a list to the specified range. https://redis.io/commands/ltrim

Parameters
$key : mixed =
$start : mixed =
$stop : mixed =

migrate()

public migrate([mixed $host = ][, mixed $port = ][, mixed $key = ][, mixed $destinationDb = ][, mixed $timeout = ][, mixed ...$options = ]) : mixed

Atomically transfer a key from a Redis instance to another one.. https://redis.io/commands/migrate

Parameters
$host : mixed =
$port : mixed =
$key : mixed =
$destinationDb : mixed =
$timeout : mixed =
$options : mixed =

object()

public object([mixed $subcommand = ][, mixed ...$argumentss = ]) : mixed

Inspect the internals of Redis objects. https://redis.io/commands/object

Parameters
$subcommand : mixed =
$argumentss : mixed =

off()

Detaches an existing event handler from this component.

public off(string $name[, callable|null $handler = null ]) : bool

This method is the opposite of [[on()]].

Note: in case wildcard pattern is passed for event name, only the handlers registered with this wildcard will be removed, while handlers registered with plain names matching this wildcard will remain.

Parameters
$name : string

event name

$handler : callable|null = null

the event handler to be removed. If it is null, all handlers attached to the named event will be removed.

Tags
see
on()
Return values
bool

if a handler is found and detached

on()

Attaches an event handler to an event.

public on(string $name, callable $handler[, mixed $data = null ][, bool $append = true ]) : mixed

The event handler must be a valid PHP callback. The following are some examples:

function ($event) { ... }         // anonymous function
[$object, 'handleClick']          // $object->handleClick()
['Page', 'handleClick']           // Page::handleClick()
'handleClick'                     // global function handleClick()

The event handler must be defined with the following signature,

function ($event)

where $event is an [[Event]] object which includes parameters associated with the event.

Since 2.0.14 you can specify event name as a wildcard pattern:

$component->on('event.group.*', function ($event) {
    Yii::trace($event->name . ' is triggered.');
});
Parameters
$name : string

the event name

$handler : callable

the event handler

$data : mixed = null

the data to be passed to the event handler when the event is triggered. When the event handler is invoked, this data can be accessed via [[Event::data]].

$append : bool = true

whether to append new event handler to the end of the existing handler list. If false, the new handler will be inserted at the beginning of the existing handler list.

Tags
see
off()

open()

Establishes a DB connection.

public open() : mixed

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

Tags
throws
Exception

if connection fails

pexpireat()

public pexpireat([mixed $key = ][, mixed $millisecondsTimestamp = ]) : mixed

Set the expiration for a key as a UNIX timestamp specified in milliseconds. https://redis.io/commands/pexpireat

Parameters
$key : mixed =
$millisecondsTimestamp : mixed =

pfadd()

public pfadd([mixed $key = ][, mixed ...$elements = ]) : mixed

Adds the specified elements to the specified HyperLogLog.. https://redis.io/commands/pfadd

Parameters
$key : mixed =
$elements : mixed =

pfmerge()

public pfmerge([mixed $destkey = ][, mixed ...$sourcekeys = ]) : mixed

Merge N different HyperLogLogs into a single one.. https://redis.io/commands/pfmerge

Parameters
$destkey : mixed =
$sourcekeys : mixed =

psetex()

public psetex([mixed $key = ][, mixed $milliseconds = ][, mixed $value = ]) : mixed

Set the value and expiration in milliseconds of a key. https://redis.io/commands/psetex

Parameters
$key : mixed =
$milliseconds : mixed =
$value : mixed =

pubsub()

public pubsub([mixed $subcommand = ][, mixed ...$arguments = ]) : mixed

Inspect the state of the Pub/Sub subsystem. https://redis.io/commands/pubsub

Parameters
$subcommand : mixed =
$arguments : mixed =

restore()

public restore([mixed $key = ][, mixed $ttl = ][, mixed $serializedValue = ][, mixed $REPLACE = null ]) : mixed

Create a key using the provided serialized value, previously obtained using DUMP.. https://redis.io/commands/restore

Parameters
$key : mixed =
$ttl : mixed =
$serializedValue : mixed =
$REPLACE : mixed = null

rpoplpush()

public rpoplpush([mixed $source = ][, mixed $destination = ]) : mixed

Remove the last element in a list, prepend it to another list and return it. https://redis.io/commands/rpoplpush

Parameters
$source : mixed =
$destination : mixed =

scan()

public scan([mixed $cursor = ][, mixed $MATCH = null ][, mixed $pattern = null ][, mixed $COUNT = null ][, mixed $count = null ]) : mixed

Incrementally iterate the keys space. https://redis.io/commands/scan

Parameters
$cursor : mixed =
$MATCH : mixed = null
$pattern : mixed = null
$COUNT : mixed = null
$count : mixed = null

sdiffstore()

public sdiffstore([mixed $destination = ][, mixed ...$keys = ]) : mixed

Subtract multiple sets and store the resulting set in a key. https://redis.io/commands/sdiffstore

Parameters
$destination : mixed =
$keys : mixed =

set()

public set([mixed $key = ][, mixed $value = ][, mixed ...$options = ]) : mixed

Set the string value of a key. https://redis.io/commands/set

Parameters
$key : mixed =
$value : mixed =
$options : mixed =

setbit()

public setbit([mixed $key = ][, mixed $offset = ][, mixed $value = ]) : mixed

Sets or clears the bit at offset in the string value stored at key. https://redis.io/commands/setbit

Parameters
$key : mixed =
$offset : mixed =
$value : mixed =

setex()

public setex([mixed $key = ][, mixed $seconds = ][, mixed $value = ]) : mixed

Set the value and expiration of a key. https://redis.io/commands/setex

Parameters
$key : mixed =
$seconds : mixed =
$value : mixed =

setrange()

public setrange([mixed $key = ][, mixed $offset = ][, mixed $value = ]) : mixed

Overwrite part of a string at key starting at the specified offset. https://redis.io/commands/setrange

Parameters
$key : mixed =
$offset : mixed =
$value : mixed =

sinterstore()

public sinterstore([mixed $destination = ][, mixed ...$keys = ]) : mixed

Intersect multiple sets and store the resulting set in a key. https://redis.io/commands/sinterstore

Parameters
$destination : mixed =
$keys : mixed =

slaveof()

public slaveof([mixed $host = ][, mixed $port = ]) : mixed

Make the server a slave of another instance, or promote it as master. https://redis.io/commands/slaveof

Parameters
$host : mixed =
$port : mixed =

smove()

public smove([mixed $source = ][, mixed $destination = ][, mixed $member = ]) : mixed

Move a member from one set to another. https://redis.io/commands/smove

Parameters
$source : mixed =
$destination : mixed =
$member : mixed =

spop()

public spop([mixed $key = ][, mixed $count = null ]) : mixed

Remove and return one or multiple random members from a set. https://redis.io/commands/spop

Parameters
$key : mixed =
$count : mixed = null

sscan()

public sscan([mixed $key = ][, mixed $cursor = ][, mixed $MATCH = null ][, mixed $pattern = null ][, mixed $COUNT = null ][, mixed $count = null ]) : mixed

Incrementally iterate Set elements. https://redis.io/commands/sscan

Parameters
$key : mixed =
$cursor : mixed =
$MATCH : mixed = null
$pattern : mixed = null
$COUNT : mixed = null
$count : mixed = null

trigger()

Triggers an event.

public trigger(string $name[, Event|null $event = null ]) : mixed

This method represents the happening of an event. It invokes all attached handlers for the event including class-level handlers.

Parameters
$name : string

the event name

$event : Event|null = null

the event instance. If not set, a default [[Event]] object will be created.

wait()

public wait([mixed $numslaves = ][, mixed $timeout = ]) : mixed

Wait for the synchronous replication of all the write commands sent in the context of the current connection. https://redis.io/commands/wait

Parameters
$numslaves : mixed =
$timeout : mixed =

xack()

public xack([mixed $stream = ][, mixed $group = ][, mixed ...$ids = ]) : mixed

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

Parameters
$stream : mixed =
$group : mixed =
$ids : mixed =

xadd()

public xadd([mixed $stream = ][, mixed $id = ][, mixed $field = ][, mixed $value = ][, mixed ...$fieldsValues = ]) : mixed

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

Parameters
$stream : mixed =
$id : mixed =
$field : mixed =
$value : mixed =
$fieldsValues : mixed =

xclaim()

public xclaim([mixed $stream = ][, mixed $group = ][, mixed $consumer = ][, mixed $minIdleTimeMs = ][, mixed $id = ][, mixed ...$options = ]) : 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

Parameters
$stream : mixed =
$group : mixed =
$consumer : mixed =
$minIdleTimeMs : mixed =
$id : mixed =
$options : mixed =

xdel()

public xdel([mixed $stream = ][, mixed ...$ids = ]) : mixed

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

Parameters
$stream : mixed =
$ids : mixed =

xgroup()

public xgroup([mixed $subCommand = ][, mixed $stream = ][, mixed $group = ][, mixed ...$options = ]) : mixed

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

Parameters
$subCommand : mixed =
$stream : mixed =
$group : mixed =
$options : mixed =

xinfo()

public xinfo([mixed $subCommand = ][, mixed $stream = ][, mixed ...$options = ]) : mixed

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

Parameters
$subCommand : mixed =
$stream : mixed =
$options : mixed =

xpending()

public xpending([mixed $stream = ][, mixed $group = ][, mixed ...$options = ]) : 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

Parameters
$stream : mixed =
$group : mixed =
$options : mixed =

xrange()

public xrange([mixed $stream = ][, mixed $start = ][, mixed $end = ][, mixed ...$options = ]) : mixed

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

Parameters
$stream : mixed =
$start : mixed =
$end : mixed =
$options : mixed =

xread()

public xread([mixed ...$options = ]) : 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

Parameters
$options : mixed =

xreadgroup()

public xreadgroup([mixed $subCommand = ][, mixed $group = ][, mixed $consumer = ][, mixed ...$options = ]) : mixed

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

Parameters
$subCommand : mixed =
$group : mixed =
$consumer : mixed =
$options : mixed =

xrevrange()

public xrevrange([mixed $stream = ][, mixed $end = ][, mixed $start = ][, mixed ...$options = ]) : 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

Parameters
$stream : mixed =
$end : mixed =
$start : mixed =
$options : mixed =

xtrim()

public xtrim([mixed $stream = ][, mixed $strategy = ][, mixed ...$options = ]) : mixed

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

Parameters
$stream : mixed =
$strategy : mixed =
$options : mixed =

zadd()

public zadd([mixed $key = ][, mixed ...$options = ]) : mixed

Add one or more members to a sorted set, or update its score if it already exists. https://redis.io/commands/zadd

Parameters
$key : mixed =
$options : mixed =

zcount()

public zcount([mixed $key = ][, mixed $min = ][, mixed $max = ]) : mixed

Count the members in a sorted set with scores within the given values. https://redis.io/commands/zcount

Parameters
$key : mixed =
$min : mixed =
$max : mixed =

zincrby()

public zincrby([mixed $key = ][, mixed $increment = ][, mixed $member = ]) : mixed

Increment the score of a member in a sorted set. https://redis.io/commands/zincrby

Parameters
$key : mixed =
$increment : mixed =
$member : mixed =

zinterstore()

public zinterstore([mixed $destination = ][, mixed $numkeys = ][, mixed $key = ][, mixed ...$options = ]) : mixed

Intersect multiple sorted sets and store the resulting sorted set in a new key. https://redis.io/commands/zinterstore

Parameters
$destination : mixed =
$numkeys : mixed =
$key : mixed =
$options : mixed =

zlexcount()

public zlexcount([mixed $key = ][, mixed $min = ][, mixed $max = ]) : mixed

Count the number of members in a sorted set between a given lexicographical range. https://redis.io/commands/zlexcount

Parameters
$key : mixed =
$min : mixed =
$max : mixed =

zrange()

public zrange([mixed $key = ][, mixed $start = ][, mixed $stop = ][, mixed $WITHSCORES = null ]) : mixed

Return a range of members in a sorted set, by index. https://redis.io/commands/zrange

Parameters
$key : mixed =
$start : mixed =
$stop : mixed =
$WITHSCORES : mixed = null

zrangebylex()

public zrangebylex([mixed $key = ][, mixed $min = ][, mixed $max = ][, mixed $LIMIT = null ][, mixed $offset = null ][, mixed $count = null ]) : mixed

Return a range of members in a sorted set, by lexicographical range. https://redis.io/commands/zrangebylex

Parameters
$key : mixed =
$min : mixed =
$max : mixed =
$LIMIT : mixed = null
$offset : mixed = null
$count : mixed = null

zrangebyscore()

public zrangebyscore([mixed $key = ][, mixed $min = ][, mixed $max = ][, mixed ...$options = ]) : mixed

Return a range of members in a sorted set, by score. https://redis.io/commands/zrangebyscore

Parameters
$key : mixed =
$min : mixed =
$max : mixed =
$options : mixed =

zremrangebylex()

public zremrangebylex([mixed $key = ][, mixed $min = ][, mixed $max = ]) : mixed

Remove all members in a sorted set between the given lexicographical range. https://redis.io/commands/zremrangebylex

Parameters
$key : mixed =
$min : mixed =
$max : mixed =

zremrangebyrank()

public zremrangebyrank([mixed $key = ][, mixed $start = ][, mixed $stop = ]) : mixed

Remove all members in a sorted set within the given indexes. https://redis.io/commands/zremrangebyrank

Parameters
$key : mixed =
$start : mixed =
$stop : mixed =

zremrangebyscore()

public zremrangebyscore([mixed $key = ][, mixed $min = ][, mixed $max = ]) : mixed

Remove all members in a sorted set within the given scores. https://redis.io/commands/zremrangebyscore

Parameters
$key : mixed =
$min : mixed =
$max : mixed =

zrevrange()

public zrevrange([mixed $key = ][, mixed $start = ][, mixed $stop = ][, mixed $WITHSCORES = null ]) : mixed

Return a range of members in a sorted set, by index, with scores ordered from high to low. https://redis.io/commands/zrevrange

Parameters
$key : mixed =
$start : mixed =
$stop : mixed =
$WITHSCORES : mixed = null

zrevrangebylex()

public zrevrangebylex([mixed $key = ][, mixed $max = ][, mixed $min = ][, mixed $LIMIT = null ][, mixed $offset = null ][, mixed $count = null ]) : mixed

Return a range of members in a sorted set, by lexicographical range, ordered from higher to lower strings.. https://redis.io/commands/zrevrangebylex

Parameters
$key : mixed =
$max : mixed =
$min : mixed =
$LIMIT : mixed = null
$offset : mixed = null
$count : mixed = null

zrevrangebyscore()

public zrevrangebyscore([mixed $key = ][, mixed $max = ][, mixed $min = ][, mixed $WITHSCORES = null ][, mixed $LIMIT = null ][, mixed $offset = null ][, mixed $count = null ]) : mixed

Return a range of members in a sorted set, by score, with scores ordered from high to low. https://redis.io/commands/zrevrangebyscore

Parameters
$key : mixed =
$max : mixed =
$min : mixed =
$WITHSCORES : mixed = null
$LIMIT : mixed = null
$offset : mixed = null
$count : mixed = null

zrevrank()

public zrevrank([mixed $key = ][, mixed $member = ]) : mixed

Determine the index of a member in a sorted set, with scores ordered from high to low. https://redis.io/commands/zrevrank

Parameters
$key : mixed =
$member : mixed =

zscan()

public zscan([mixed $key = ][, mixed $cursor = ][, mixed $MATCH = null ][, mixed $pattern = null ][, mixed $COUNT = null ][, mixed $count = null ]) : mixed

Incrementally iterate sorted sets elements and associated scores. https://redis.io/commands/zscan

Parameters
$key : mixed =
$cursor : mixed =
$MATCH : mixed = null
$pattern : mixed = null
$COUNT : mixed = null
$count : mixed = null

zscore()

public zscore([mixed $key = ][, mixed $member = ]) : mixed

Get the score associated with the given member in a sorted set. https://redis.io/commands/zscore

Parameters
$key : mixed =
$member : mixed =

zunionstore()

public zunionstore([mixed $destination = ][, mixed $numkeys = ][, mixed $key = ][, mixed ...$options = ]) : mixed

Add multiple sorted sets and store the resulting sorted set in a new key. https://redis.io/commands/zunionstore

Parameters
$destination : mixed =
$numkeys : mixed =
$key : mixed =
$options : mixed =

initConnection()

Initializes the DB connection.

protected initConnection() : mixed

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

sendRawCommand()

Sends RAW command string to the server.

protected sendRawCommand(string $command, array<string|int, mixed> $params) : array<string|int, mixed>|bool|null|string
Parameters
$command : string

command string

$params : array<string|int, mixed>

list of parameters for the command

Tags
throws
Exception

for commands that return error reply.

throws
SocketException

on connection error.

Return values
array<string|int, mixed>|bool|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.

attachBehaviorInternal()

Attaches a behavior to this component.

private attachBehaviorInternal(string|int $name, string|array<string|int, mixed>|Behavior $behavior) : Behavior
Parameters
$name : string|int

the name of the behavior. If this is an integer, it means the behavior is an anonymous one. Otherwise, the behavior is a named one and any existing behavior with the same name will be detached first.

$behavior : string|array<string|int, mixed>|Behavior

the behavior to be attached

Return values
Behavior

the attached behavior.

isRedirect()

private isRedirect(string $line) : bool
Parameters
$line : string
Return values
bool

parseResponse()

private parseResponse(array<string|int, mixed> $params[, string|null $command = null ]) : mixed
Parameters
$params : array<string|int, mixed>
$command : string|null = null
Tags
throws
Exception

on error

throws
SocketException

redirect()

private redirect(string $redirect, string $command, array<string|int, mixed> $params) : mixed
Parameters
$redirect : string
$command : string
$params : array<string|int, mixed>
Tags
throws
Exception
throws
SocketException

        
On this page

Search results