VOOZH about

URL: https://deepwiki.com/hypervel/support/6.3-redis-operations

⇱ Redis Operations | hypervel/support | DeepWiki


Loading...
Menu

Redis Operations

Purpose and Scope

This document covers Redis operations through the Redis facade, including connection management, command execution, data structure operations, pipelines, transactions, and pub/sub functionality. The Redis facade provides direct access to Redis protocol commands for low-level data operations.

For cache-specific operations using Redis as a backend, see Cache Management. For queue operations that may use Redis as a driver, see Queue Operations.


Redis Facade Architecture

The Redis facade provides a static interface to the Redis client, resolving to Hypervel\Redis\Redis through the service container. The facade supports all native Redis commands and connection pooling.


Sources: src/Facades/Redis.php1-282


Connection Management

Connection Resolution

The Redis facade supports multiple named connections defined in the configuration. The default connection is used when no connection name is specified.


Connection API

MethodDescription
Redis::connection(string $name)Get a named connection
Redis::release()Release connection back to pool
Redis::reconnect()Reconnect if disconnected
Redis::close()Close connection
Redis::check()Check connection health
Redis::isConnected()Verify connection status

Sources: src/Facades/Redis.php10-26


Data Structure Operations

String Operations

The Redis facade provides methods for string data type operations, including basic get/set, atomic operations, and bitwise operations.

OperationMethodDescription
GetRedis::get(string $key)Retrieve value
SetRedis::set(string $key, mixed $value, ...)Set value with optional expiry
Set if not existsRedis::setnx(string $key, string $value)Atomic set operation
Multiple getRedis::mget(array $keys)Get multiple values
Multiple setRedis::mset(array $key_values)Set multiple key-value pairs
IncrementRedis::incr(string $key, int $by)Atomic increment
DecrementRedis::decr(string $key, int $by)Atomic decrement
AppendRedis::append(string $key, mixed $value)Append to value

Sources: src/Facades/Redis.php29-162

Hash Operations

Hash operations allow storing field-value pairs under a single key.

OperationMethodDescription
Set fieldRedis::hSet(string $key, mixed ...$fields)Set one or more fields
Get fieldRedis::hGet(string $key, string $field)Get field value
Get allRedis::hGetAll(string $key)Get all field-value pairs
Multiple getRedis::hmget(string $key, mixed ...$fields)Get multiple fields
Multiple setRedis::hmset(string $key, mixed ...$dictionary)Set multiple fields
DeleteRedis::hDel(string $key, string $field, ...)Delete fields
ExistsRedis::hExists(string $key, string $field)Check field existence
IncrementRedis::hIncrBy(string $key, string $field, int $value)Increment field

Sources: src/Facades/Redis.php33-137

List Operations

List operations provide queue and stack functionality with ordered element access.

OperationMethodDescription
Left pushRedis::lPush(string $key, mixed ...$elements)Push to head
Right pushRedis::rPush(string $key, mixed ...$elements)Push to tail
Left popRedis::lPop(string $key, int $count)Pop from head
Right popRedis::rPop(string $key, int $count)Pop from tail
Blocking popRedis::blpop(mixed ...$arguments)Block until element available
RangeRedis::lrange(string $key, int $start, int $end)Get range of elements
LengthRedis::lLen(string $key)Get list length
TrimRedis::ltrim(string $key, int $start, int $end)Trim to range

Sources: src/Facades/Redis.php36-158

Set Operations

Set operations manage unordered unique collections with support for union, intersection, and difference.

OperationMethodDescription
AddRedis::sAdd(string $key, mixed $value, ...)Add members
RemoveRedis::srem(string $key, mixed $value, ...)Remove members
MembersRedis::sMembers(string $key)Get all members
Is memberRedis::sismember(string $key, mixed $value)Check membership
UnionRedis::sUnion(string $key, string ...$other_keys)Union of sets
IntersectionRedis::sInter(array|string $key, ...)Intersection of sets
DifferenceRedis::sDiff(string $key, string ...$other_keys)Difference of sets
PopRedis::sPop(string $key, int $count)Remove and return random member

Sources: src/Facades/Redis.php39-216

Sorted Set Operations

Sorted sets maintain elements with scores for ordered retrieval and range queries.

OperationMethodDescription
AddRedis::zAdd(string $key, array|float $score, ...)Add with score
RangeRedis::zRange(string $key, int $start, int $end, ...)Get range by rank
Range by scoreRedis::zrangebyscore(string $key, $min, $max, ...)Get range by score
Reverse rangeRedis::zRevRange(string $key, int $start, int $end, ...)Reverse range
ScoreRedis::zScore(string $key, mixed $member)Get member score
RankRedis::zRank(string $key, mixed $member)Get member rank
RemoveRedis::zRem(mixed $key, mixed $member, ...)Remove members
CountRedis::zCount(string $key, $start, $end)Count members in score range

Sources: src/Facades/Redis.php40-266


Advanced Operations

Pipelines

Pipelines batch multiple commands into a single network round-trip, reducing latency for bulk operations.


Pipeline Method:

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

Returns an array of results corresponding to each command in the pipeline, or a \Redis instance for chaining if no callback provided.

Sources: src/Facades/Redis.php27

Transactions

Transactions execute commands atomically using Redis MULTI/EXEC protocol.


Transaction Method:

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

Returns an array of command results, or a \Redis|\RedisCluster instance if no callback provided.

Sources: src/Facades/Redis.php28

Lua Scripting

Execute Lua scripts for atomic server-side operations.

MethodDescription
Redis::eval(string $script, int $numberOfKeys, ...)Execute Lua script
Redis::evalsha(string $sha1, int $numkeys, ...)Execute cached script by SHA1
Redis::eval_ro(string $script, array $args, int $num_keys)Read-only script execution
Redis::evalsha_ro(string $sha1, array $args, int $num_keys)Read-only cached script
Redis::script(string $command, ...)Script management commands

Sources: src/Facades/Redis.php45-204


Pub/Sub Operations

Redis provides publish/subscribe messaging for real-time event distribution.


Pub/Sub API

OperationMethodDescription
PublishRedis::publish(string $channel, string $message)Publish message to channel
SubscribeRedis::subscribe(array|string $channels, \Closure $callback)Subscribe to channels
Pattern subscribeRedis::psubscribe(array|string $patterns, \Closure $callback)Subscribe with patterns
UnsubscribeRedis::unsubscribe(array $channels)Unsubscribe from channels
Pattern unsubscribeRedis::punsubscribe(array $patterns)Unsubscribe from patterns
Pub/sub infoRedis::pubsub(string $command, mixed $arg)Introspection commands

Sources: src/Facades/Redis.php174-220


Key Management

Key Operations

OperationMethodDescription
DeleteRedis::del(array|string $key, ...)Delete keys
UnlinkRedis::unlink(array|string $key, ...)Async delete
ExistsRedis::exists(mixed $key, ...)Check existence
ExpireRedis::expire(string $key, int $timeout, string|null $mode)Set expiration
Expire atRedis::expireAt(string $key, int $timestamp, ...)Set expiration timestamp
TTLRedis::ttl(string $key)Get time to live
PersistRedis::persist(string $key)Remove expiration
TypeRedis::type(string $key)Get key type
RenameRedis::rename(string $old, string $new)Rename key

Sources: src/Facades/Redis.php77-225

Scanning Operations

Iterate through keys without blocking using cursor-based iteration.

MethodDescription
Redis::scan(mixed $cursor, array ...$arguments)Scan keys
Redis::sscan(string $key, mixed $cursor, ...)Scan set members
Redis::hscan(string $key, mixed $cursor, ...)Scan hash fields
Redis::zscan(string $key, mixed $cursor, ...)Scan sorted set members

Sources: src/Facades/Redis.php14-17


Command Execution Patterns

Direct Command Invocation

The facade provides direct access to Redis commands through magic methods. Each command is mapped to its corresponding method.


Sources: src/Facades/Redis.php275-281

Transform Behavior

The Redis connection supports automatic transformation of responses.

MethodDescription
Redis::shouldTransform(bool $should)Enable/disable response transformation
Redis::getShouldTransform()Get transformation setting

Sources: src/Facades/Redis.php12-13


Database Selection

Redis supports multiple logical databases within a single server instance.

MethodDescription
Redis::select(int $db)Select database by index
Redis::setDatabase(int|null $database)Set database for connection
Redis::getDBNum()Get current database number
Redis::swapdb(int $src, int $dst)Swap two databases

Sources: src/Facades/Redis.php22-221


Geospatial Operations

Redis provides geospatial indexing for location-based queries.

OperationMethodDescription
AddRedis::geoadd(string $key, float $lng, float $lat, string $member, ...)Add location
DistanceRedis::geodist(string $key, string $src, string $dst, string|null $unit)Calculate distance
RadiusRedis::georadius(string $key, float $lng, float $lat, float $radius, string $unit, ...)Query by radius
SearchRedis::geosearch(string $key, array|string $position, ...)Geospatial search

Sources: src/Facades/Redis.php95-104


Stream Operations

Redis streams provide an append-only log data structure for event streaming.

OperationMethodDescription
AddRedis::xadd(string $key, string $id, array $values, ...)Add entry
RangeRedis::xrange(string $key, string $start, string $end, int $count)Read range
ReadRedis::xread(array $streams, int $count, int $block)Read from streams
Group createRedis::xgroup('CREATE', string $key, string $group, ...)Create consumer group
Group readRedis::xreadgroup(string $group, string $consumer, array $streams, ...)Read as consumer
AcknowledgeRedis::xack(string $key, string $group, array $ids)Acknowledge messages

Sources: src/Facades/Redis.php230-243


Server Management

Information and Statistics

MethodDescription
Redis::info(string ...$sections)Get server information
Redis::dbSize()Get database key count
Redis::time()Get server time
Redis::ping(string|null $message)Ping server
Redis::slowlog(string $operation, int $length)Query slow log

Sources: src/Facades/Redis.php73-222

Persistence Control

MethodDescription
Redis::save()Synchronous save
Redis::bgSave()Background save
Redis::bgrewriteaof()Background AOF rewrite
Redis::lastSave()Get last save timestamp

Sources: src/Facades/Redis.php52-202


Configuration and Options

Connection Configuration

MethodDescription
Redis::getHost()Get configured host
Redis::getPort()Get configured port
Redis::getTimeout()Get connection timeout
Redis::getReadTimeout()Get read timeout
Redis::getPersistentID()Get persistent connection ID

Sources: src/Facades/Redis.php110-120

Client Options

MethodDescription
Redis::setOption(int $option, mixed $value)Set Redis option
Redis::getOption(int $option)Get Redis option
Redis::getMode()Get connection mode

Sources: src/Facades/Redis.php112-208


Connection Lifecycle



































MethodDescription
Redis::connect(...)Establish connection
Redis::pconnect(...)Persistent connection
Redis::reconnect()Reconnect after disconnect
Redis::close()Close connection
Redis::release()Release to pool
Redis::isConnected()Check connection status

Sources: src/Facades/Redis.php11-165


Method Availability Reference

The Redis facade exposes over 270 methods corresponding to Redis protocol commands. The complete method signature list is documented as PHPDoc annotations on the facade class, enabling IDE autocompletion and static analysis.

All methods follow the convention of matching Redis command names, with camelCase transformations where applicable (e.g., HGETALLhGetAll).

Sources: src/Facades/Redis.php9-272