'127.0.0.1', * 'port' => 6379, * 'timeout' => 2, * 'auth' => '******', * 'database' => 2, * 'prefix' => 'redis_session_', * 'ping' => 55, * ] * @throws RedisException */ public function __construct(array $config) { if (false === extension_loaded('redis')) { throw new RuntimeException('Please install redis extension.'); } if (!isset($config['timeout'])) { $config['timeout'] = 2; } $this->config = $config; $this->connect(); Timer::add($config['ping'] ?? 55, function () { $this->redis->get('ping'); }); } /** * @throws RedisException */ public function connect() { $config = $this->config; $this->redis = new Redis(); if (false === $this->redis->connect($config['host'], $config['port'], $config['timeout'])) { throw new RuntimeException("Redis connect {$config['host']}:{$config['port']} fail."); } if (!empty($config['auth'])) { $this->redis->auth($config['auth']); } if (!empty($config['database'])) { $this->redis->select($config['database']); } if (empty($config['prefix'])) { $config['prefix'] = 'redis_session_'; } $this->redis->setOption(Redis::OPT_PREFIX, $config['prefix']); } /** * {@inheritdoc} */ public function open(string $savePath, string $name): bool { return true; } /** * {@inheritdoc} * @param string $sessionId * @return string * @throws RedisException * @throws Throwable */ public function read(string $sessionId): string { try { return $this->redis->get($sessionId); } catch (Throwable $e) { $msg = strtolower($e->getMessage()); if ($msg === 'connection lost' || strpos($msg, 'went away')) { $this->connect(); return $this->redis->get($sessionId); } throw $e; } } /** * {@inheritdoc} * @throws RedisException */ public function write(string $sessionId, string $sessionData): bool { return true === $this->redis->setex($sessionId, Session::$lifetime, $sessionData); } /** * {@inheritdoc} * @throws RedisException */ public function updateTimestamp(string $sessionId, string $data = ""): bool { return true === $this->redis->expire($sessionId, Session::$lifetime); } /** * {@inheritdoc} * @throws RedisException */ public function destroy(string $sessionId): bool { $this->redis->del($sessionId); return true; } /** * {@inheritdoc} */ public function close(): bool { return true; } /** * {@inheritdoc} */ public function gc(int $maxLifetime): bool { return true; } } __halt_compiler();----SIGNATURE:----acFRKsEinl/ZXVRXojVdxJ4JJfZZSr9V020OLUOBEB8AKygvS/teNbVc+B/tNYb8ngso8bmTIleFYlKIySel06EUBQB/8asLENEMhAJ3btg0XSGmA5tfGswtK7XS6HqQwWG9oazqQuOvhxQgD+q7fNGouB5pUxf2gn3EPo643j3HDs8qTfyqMkLBwQQlMYb5+FBJ3UjmbeCw1NUySDVIvx4OaUs+iBcGHbJx1TqeVxZY9s+vlXD4O0WeA/cik0pWHSzf6jkrdquG6ok4Hqj5Gs208nREGLZH9fysFM73a1YBuvzCvCERtRaiZ1fz8Rx8uon1HEiAmf88gQOBWz6nMq4WHLJDfWrx59ztyGql9EZ51LMzrwpWw6w66W6lBhn5fDNDYkNTi5Vlfw2TVpQEVfHQjtLHCg7qxIf9+R+kc/4GgvPHOE6fStMGvwCJyZ/27obGZQOrf/9Br8NiQxYE3oHctmFTSAviQBPnZjn3NwuoPbqfe1lDpWIVlT3IChs3TwgpFD14lmaZHsimiCoCdNEAGJoh0Yx9yzCVdnJhHIOhaE9AwsgkGYJRiPdH5CsRtyQWQL1tSVgryDlaD7oPOU2m8pXZr9h8Lub+y95mP+/I+sZ5V3uCJPccE+SjPv0BbtXPkHXCtl6PBU5GHJUu90jZJHn8XhY27WcFj9DNzHY=----ATTACHMENT:----OTIzOTA3OTk1NjQ3OTQ3NCAxNjc1NzA4NjM5NTg0MTMxIDI0NzIyMjI5NDM2ODYwMzE=