$value) { $this->persistence[$key][self::HPREFIX . $hashkey] = $value; } return true; } public function hExists($key, $field) { return $this->hGet($key, $field) !== false; } public function hSet($key, $field, $value) { $result = !isset($this->persistence[$key][self::HPREFIX . $field]); $this->persistence[$key][self::HPREFIX . $field] = $value; return $result; } public function hGet($key, $field) { if ( ! isset($this->persistence[$key]) || ! isset($this->persistence[$key][self::HPREFIX . $field]) ) { return false; } return $this->persistence[$key][self::HPREFIX . $field]; } public function hDel($key, $field): bool { if (!isset($this->persistence[$key]) || !isset($this->persistence[$key][self::HPREFIX . $field])) { return false; } unset($this->persistence[$key][self::HPREFIX . $field]); return true; } public function hGetAll($key) { if (! isset($this->persistence[$key])) { return []; } $data = []; $prefixLength = strlen(self::HPREFIX); foreach ($this->persistence[$key] as $hash => $attributes) { if (mb_substr($hash, 0, $prefixLength) === self::HPREFIX) { $data[mb_substr($hash, $prefixLength)] = $this->persistence[$key][$hash]; } } return $data; } public function keys($pattern) { if ($pattern == '*') { return array_keys($this->persistence); } return []; } }