class PhpRedisConnection extends Connection implements Connection mixin Redis (View source)

Traits

Properties

static protected array $macros

The registered string macros.

from  Macroable
protected Redis $client

The Redis client.

from  Connection
protected string|null $name

The Redis connection name.

from  Connection
protected Dispatcher $events

The event dispatcher instance.

from  Connection
protected bool|null $supportsPacking

Indicates if Redis supports packing.

from  PacksPhpRedisValues
protected bool|null $supportsLzf

Indicates if Redis supports LZF compression.

from  PacksPhpRedisValues
protected bool|null $supportsZstd

Indicates if Redis supports Zstd compression.

from  PacksPhpRedisValues
protected callable $connector

The connection creation callback.

protected array $config

The connection configuration array.

Methods

static void
macro(string $name, object|callable $macro)

Register a custom macro.

static void
mixin(object $mixin, bool $replace = true)

Mix another object into the class.

static bool
hasMacro(string $name)

Checks if macro is registered.

static void
flushMacros()

Flush the existing macros.

static mixed
__callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

mixed
__call(string $method, array $parameters)

Pass other method calls down to the underlying client.

void
createSubscription(array|string $channels, Closure $callback, string $method = 'subscribe')

Subscribe to a set of given channels for messages.

funnel(string $name)

Funnel a callback for a maximum number of simultaneous executions.

throttle(string $name)

Throttle a callback for a maximum number of executions over a given duration.

mixed
client()

Get the underlying Redis client.

void
subscribe(array|string $channels, Closure $callback)

Subscribe to a set of given channels for messages.

void
psubscribe(array|string $channels, Closure $callback)

Subscribe to a set of given channels with wildcards.

mixed
command(string $method, array $parameters = [])

Run a command against the Redis database.

array
parseParametersForEvent(array $parameters)

Parse the command's parameters for event dispatching.

void
event(mixed $event)

Fire the given event if possible.

void
listen(Closure $callback)

Register a Redis command listener with the connection.

string|null
getName()

Get the connection name.

$this
setName(string $name)

Set the connections name.

getEventDispatcher()

Get the event dispatcher used by the connection.

void
setEventDispatcher(Dispatcher $events)

Set the event dispatcher instance on the connection.

void
unsetEventDispatcher()

Unset the event dispatcher instance on the connection.

array
pack(array $values)

Prepares the given values to be used with the eval command, including serialization and compression.

bool
compressed()

Determine if compression is enabled.

bool
lzfCompressed()

Determine if LZF compression is enabled.

bool
zstdCompressed()

Determine if ZSTD compression is enabled.

bool
lz4Compressed()

Determine if LZ4 compression is enabled.

bool
supportsPacking()

Determine if the current PhpRedis extension version supports packing.

bool
supportsLzf()

Determine if the current PhpRedis extension version supports LZF compression.

bool
supportsZstd()

Determine if the current PhpRedis extension version supports Zstd compression.

bool
phpRedisVersionAtLeast(string $version)

Determine if the PhpRedis extension version is at least the given version.

void
__construct(Redis $client, callable|null $connector = null, array $config = [])

Create a new PhpRedis connection.

string|null
get(string $key)

Returns the value of the given key.

array
mget(array $keys)

Get the values of all the given keys.

bool
set(string $key, mixed $value, string|null $expireResolution = null, int|null $expireTTL = null, string|null $flag = null)

Set the string value in the argument as the value of the key.

int
setnx(string $key, string $value)

Set the given key if it doesn't exist.

array
hmget(string $key, mixed ...$dictionary)

Get the value of the given hash fields.

int
hmset(string $key, mixed ...$dictionary)

Set the given hash fields to their respective values.

int
hsetnx(string $hash, string $key, string $value)

Set the given hash field if it doesn't exist.

int|false
lrem(string $key, int $count, mixed $value)

Removes the first count occurrences of the value element from the list.

array|null
blpop(mixed ...$arguments)

Removes and returns the first element of the list stored at key.

array|null
brpop(mixed ...$arguments)

Removes and returns the last element of the list stored at key.

mixed|false
spop(string $key, int|null $count = 1)

Removes and returns a random element from the set value at key.

int
zadd(string $key, mixed ...$dictionary)

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

array
zrangebyscore(string $key, mixed $min, mixed $max, array $options = [])

Return elements with score between $min and $max.

array
zrevrangebyscore(string $key, mixed $min, mixed $max, array $options = [])

Return elements with score between $min and $max.

int
zinterstore(string $output, array $keys, array $options = [])

Find the intersection between sets and store in a new set.

int
zunionstore(string $output, array $keys, array $options = [])

Find the union between sets and store in a new set.

mixed
scan(mixed $cursor, array $options = [])

Scans all keys based on options.

mixed
zscan(string $key, mixed $cursor, array $options = [])

Scans the given set for all values based on options.

mixed
hscan(string $key, mixed $cursor, array $options = [])

Scans the given hash for all values based on options.

mixed
sscan(string $key, mixed $cursor, array $options = [])

Scans the given set for all values based on options.

Redis|array
pipeline(callable|null $callback = null)

Execute commands in a pipeline.

Redis|array
transaction(callable|null $callback = null)

Execute commands in a transaction.

mixed
evalsha(string $script, int $numkeys, mixed ...$arguments)

Evaluate a LUA script serverside, from the SHA1 hash of the script instead of the script itself.

mixed
eval(string $script, int $numberOfKeys, mixed ...$arguments)

Evaluate a script and return its result.

mixed
flushdb()

Flush the selected Redis database.

mixed
executeRaw(array $parameters)

Execute a raw command.

void
disconnect()

Disconnects from the Redis instance.

Details

static void macro(string $name, object|callable $macro)

Register a custom macro.

Parameters

string $name
object|callable $macro

Return Value

void

static void mixin(object $mixin, bool $replace = true)

Mix another object into the class.

Parameters

object $mixin
bool $replace

Return Value

void

Exceptions

ReflectionException

static bool hasMacro(string $name)

Checks if macro is registered.

Parameters

string $name

Return Value

bool

static void flushMacros()

Flush the existing macros.

Return Value

void

static mixed __callStatic(string $method, array $parameters)

Dynamically handle calls to the class.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

mixed __call(string $method, array $parameters)

Pass other method calls down to the underlying client.

Parameters

string $method
array $parameters

Return Value

mixed

void createSubscription(array|string $channels, Closure $callback, string $method = 'subscribe')

Subscribe to a set of given channels for messages.

Parameters

array|string $channels
Closure $callback
string $method

Return Value

void

ConcurrencyLimiterBuilder funnel(string $name)

Funnel a callback for a maximum number of simultaneous executions.

Parameters

string $name

Return Value

ConcurrencyLimiterBuilder

DurationLimiterBuilder throttle(string $name)

Throttle a callback for a maximum number of executions over a given duration.

Parameters

string $name

Return Value

DurationLimiterBuilder

mixed client()

Get the underlying Redis client.

Return Value

mixed

void subscribe(array|string $channels, Closure $callback)

Subscribe to a set of given channels for messages.

Parameters

array|string $channels
Closure $callback

Return Value

void

void psubscribe(array|string $channels, Closure $callback)

Subscribe to a set of given channels with wildcards.

Parameters

array|string $channels
Closure $callback

Return Value

void

mixed command(string $method, array $parameters = [])

Run a command against the Redis database.

Parameters

string $method
array $parameters

Return Value

mixed

Exceptions

RedisException

protected array parseParametersForEvent(array $parameters)

Parse the command's parameters for event dispatching.

Parameters

array $parameters

Return Value

array

protected void event(mixed $event)

Fire the given event if possible.

Parameters

mixed $event

Return Value

void

void listen(Closure $callback)

Register a Redis command listener with the connection.

Parameters

Closure $callback

Return Value

void

string|null getName()

Get the connection name.

Return Value

string|null

$this setName(string $name)

Set the connections name.

Parameters

string $name

Return Value

$this

Dispatcher getEventDispatcher()

Get the event dispatcher used by the connection.

Return Value

Dispatcher

void setEventDispatcher(Dispatcher $events)

Set the event dispatcher instance on the connection.

Parameters

Dispatcher $events

Return Value

void

void unsetEventDispatcher()

Unset the event dispatcher instance on the connection.

Return Value

void

array pack(array $values)

Prepares the given values to be used with the eval command, including serialization and compression.

Parameters

array $values

Return Value

array

bool compressed()

Determine if compression is enabled.

Return Value

bool

bool lzfCompressed()

Determine if LZF compression is enabled.

Return Value

bool

bool zstdCompressed()

Determine if ZSTD compression is enabled.

Return Value

bool

bool lz4Compressed()

Determine if LZ4 compression is enabled.

Return Value

bool

protected bool supportsPacking()

Determine if the current PhpRedis extension version supports packing.

Return Value

bool

protected bool supportsLzf()

Determine if the current PhpRedis extension version supports LZF compression.

Return Value

bool

protected bool supportsZstd()

Determine if the current PhpRedis extension version supports Zstd compression.

Return Value

bool

protected bool phpRedisVersionAtLeast(string $version)

Determine if the PhpRedis extension version is at least the given version.

Parameters

string $version

Return Value

bool

void __construct(Redis $client, callable|null $connector = null, array $config = [])

Create a new PhpRedis connection.

Parameters

Redis $client
callable|null $connector
array $config

Return Value

void

string|null get(string $key)

Returns the value of the given key.

Parameters

string $key

Return Value

string|null

array mget(array $keys)

Get the values of all the given keys.

Parameters

array $keys

Return Value

array

bool set(string $key, mixed $value, string|null $expireResolution = null, int|null $expireTTL = null, string|null $flag = null)

Set the string value in the argument as the value of the key.

Parameters

string $key
mixed $value
string|null $expireResolution
int|null $expireTTL
string|null $flag

Return Value

bool

int setnx(string $key, string $value)

Set the given key if it doesn't exist.

Parameters

string $key
string $value

Return Value

int

array hmget(string $key, mixed ...$dictionary)

Get the value of the given hash fields.

Parameters

string $key
mixed ...$dictionary

Return Value

array

int hmset(string $key, mixed ...$dictionary)

Set the given hash fields to their respective values.

Parameters

string $key
mixed ...$dictionary

Return Value

int

int hsetnx(string $hash, string $key, string $value)

Set the given hash field if it doesn't exist.

Parameters

string $hash
string $key
string $value

Return Value

int

int|false lrem(string $key, int $count, mixed $value)

Removes the first count occurrences of the value element from the list.

Parameters

string $key
int $count
mixed $value

Return Value

int|false

array|null blpop(mixed ...$arguments)

Removes and returns the first element of the list stored at key.

Parameters

mixed ...$arguments

Return Value

array|null

array|null brpop(mixed ...$arguments)

Removes and returns the last element of the list stored at key.

Parameters

mixed ...$arguments

Return Value

array|null

mixed|false spop(string $key, int|null $count = 1)

Removes and returns a random element from the set value at key.

Parameters

string $key
int|null $count

Return Value

mixed|false

int zadd(string $key, mixed ...$dictionary)

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

Parameters

string $key
mixed ...$dictionary

Return Value

int

array zrangebyscore(string $key, mixed $min, mixed $max, array $options = [])

Return elements with score between $min and $max.

Parameters

string $key
mixed $min
mixed $max
array $options

Return Value

array

array zrevrangebyscore(string $key, mixed $min, mixed $max, array $options = [])

Return elements with score between $min and $max.

Parameters

string $key
mixed $min
mixed $max
array $options

Return Value

array

int zinterstore(string $output, array $keys, array $options = [])

Find the intersection between sets and store in a new set.

Parameters

string $output
array $keys
array $options

Return Value

int

int zunionstore(string $output, array $keys, array $options = [])

Find the union between sets and store in a new set.

Parameters

string $output
array $keys
array $options

Return Value

int

mixed scan(mixed $cursor, array $options = [])

Scans all keys based on options.

Parameters

mixed $cursor
array $options

Return Value

mixed

mixed zscan(string $key, mixed $cursor, array $options = [])

Scans the given set for all values based on options.

Parameters

string $key
mixed $cursor
array $options

Return Value

mixed

mixed hscan(string $key, mixed $cursor, array $options = [])

Scans the given hash for all values based on options.

Parameters

string $key
mixed $cursor
array $options

Return Value

mixed

mixed sscan(string $key, mixed $cursor, array $options = [])

Scans the given set for all values based on options.

Parameters

string $key
mixed $cursor
array $options

Return Value

mixed

Redis|array pipeline(callable|null $callback = null)

Execute commands in a pipeline.

Parameters

callable|null $callback

Return Value

Redis|array

Redis|array transaction(callable|null $callback = null)

Execute commands in a transaction.

Parameters

callable|null $callback

Return Value

Redis|array

mixed evalsha(string $script, int $numkeys, mixed ...$arguments)

Evaluate a LUA script serverside, from the SHA1 hash of the script instead of the script itself.

Parameters

string $script
int $numkeys
mixed ...$arguments

Return Value

mixed

mixed eval(string $script, int $numberOfKeys, mixed ...$arguments)

Evaluate a script and return its result.

Parameters

string $script
int $numberOfKeys
mixed ...$arguments

Return Value

mixed

mixed flushdb()

Flush the selected Redis database.

Return Value

mixed

mixed executeRaw(array $parameters)

Execute a raw command.

Parameters

array $parameters

Return Value

mixed

void disconnect()

Disconnects from the Redis instance.

Return Value

void