\Framework\SessionRedisGroupSessionHandler

RedisGroupSessionHandler.

  • 支持 group_prefix(不会传递给父类)
  • 实现 Redis 分布式锁(SET NX PX + Lua 释放)以保证高并发安全写入

Options 支持(兼容 Symfony 的常规选项):

  • prefix (string) : 键前缀(父类支持)
  • ttl (int) : session TTL(秒)
  • locking (bool) : 是否启用显式锁(默认 true)
  • spin_lock_wait (int) : 自旋每次等待,单位微秒(默认 150000)
  • lock_ttl (int) : 锁过期时间,单位毫秒(默认 30000)
  • group_prefix (string) : 自定义分组前缀(会拼接到 prefix 前面)

Summary

Methods
Properties
Constants
__construct()
write()
read()
destroy()
gc()
No public properties found
No constants found
sessionKey()
lockKey()
acquireLock()
releaseLock()
$redis
$ttlLocal
$locking
$spinLockWait
$lockTtl
$prefix
$groupPrefix
N/A
No private methods found
No private properties found
N/A

Properties

$redis

$redis : object

Type

object

$ttlLocal

$ttlLocal : int

Type

int

$locking

$locking : bool

Type

bool

$spinLockWait

$spinLockWait : int

Type

int

$lockTtl

$lockTtl : int

Type

int

$prefix

$prefix : string

Type

string

$groupPrefix

$groupPrefix : string

Type

string

Methods

__construct()

__construct(object  $redis, array  $options = []) : mixed

Parameters

object $redis
array $options

Returns

mixed —

write()

write(string  $sessionId, string  $data) : bool

重写 write() —— 使用分布式锁保护写入(高并发安全).

Parameters

string $sessionId
string $data

Returns

bool —

read()

read(string  $sessionId) : string

read 保持简单与健壮.

Parameters

string $sessionId

Returns

string —

destroy()

destroy(string  $sessionId) : bool

destroy.

Parameters

string $sessionId

Returns

bool —

gc()

gc(int  $maxlifetime) : false|int

gc: Redis TTL 自管理.

Parameters

int $maxlifetime

Returns

false|int —

sessionKey()

sessionKey(string  $sessionId) : string

make session key.

Parameters

string $sessionId

Returns

string —

lockKey()

lockKey(string  $sessionId) : string

lock key for this session id.

Parameters

string $sessionId

Returns

string —

acquireLock()

acquireLock(string  $sessionId) : false|string

Acquire lock using SET NX PX, return token string on success, false on fail.

Parameters

string $sessionId

Returns

false|string —

releaseLock()

releaseLock(string  $sessionId, string  $token) : bool

Release lock only if token matches (atomic via Lua).

Parameters

string $sessionId
string $token

Returns

bool —