mirror of
https://github.com/danog/AsyncOrm.git
synced 2024-11-26 12:24:59 +01:00
Misc fixes
This commit is contained in:
parent
47f7a3a2d2
commit
73909971b0
@ -53,6 +53,7 @@ abstract class DbObject
|
||||
$this->onAfterSave();
|
||||
}
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
/**
|
||||
* Method invoked after loading the object.
|
||||
*/
|
||||
@ -74,4 +75,5 @@ abstract class DbObject
|
||||
{
|
||||
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
@ -85,32 +85,16 @@ final class RedisArray extends DriverArray
|
||||
$this->db = self::$connections[$dbKey];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get redis key name.
|
||||
*/
|
||||
private function rKey(string $key): string
|
||||
{
|
||||
return $this->config->table.':'.$key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get iterator key.
|
||||
*/
|
||||
private function itKey(): string
|
||||
{
|
||||
return $this->config->table.':*';
|
||||
}
|
||||
|
||||
public function set(string|int $key, mixed $value): void
|
||||
{
|
||||
$this->db->set($this->rKey((string) $key), $this->serializer->serialize($value));
|
||||
$this->db->set($this->config->table.':'.(string) $key, $this->serializer->serialize($value));
|
||||
}
|
||||
|
||||
public function get(mixed $key): mixed
|
||||
public function get(string|int $key): mixed
|
||||
{
|
||||
$key = (string) $key;
|
||||
|
||||
$value = $this->db->get($this->rKey($key));
|
||||
$value = $this->db->get($this->config->table.':'.$key);
|
||||
|
||||
if ($value !== null) {
|
||||
/** @var TValue */
|
||||
@ -122,7 +106,7 @@ final class RedisArray extends DriverArray
|
||||
|
||||
public function unset(string|int $key): void
|
||||
{
|
||||
$this->db->delete($this->rkey((string) $key));
|
||||
$this->db->delete($this->config->table.':'.(string) $key);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -132,9 +116,9 @@ final class RedisArray extends DriverArray
|
||||
*/
|
||||
public function getIterator(): \Traversable
|
||||
{
|
||||
$request = $this->db->scan($this->itKey());
|
||||
$request = $this->db->scan($this->config->table.':*');
|
||||
|
||||
$len = \strlen($this->rKey(''));
|
||||
$len = \strlen($this->config->table)+1;
|
||||
foreach ($request as $key) {
|
||||
$sub = \substr($key, $len);
|
||||
if ($this->castToInt) {
|
||||
@ -153,7 +137,7 @@ final class RedisArray extends DriverArray
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
return \iterator_count($this->db->scan($this->itKey()));
|
||||
return \iterator_count($this->db->scan($this->config->table.':*'));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -161,7 +145,7 @@ final class RedisArray extends DriverArray
|
||||
*/
|
||||
public function clear(): void
|
||||
{
|
||||
$request = $this->db->scan($this->itKey());
|
||||
$request = $this->db->scan($this->config->table.':*');
|
||||
|
||||
$keys = [];
|
||||
foreach ($request as $key) {
|
||||
|
Loading…
Reference in New Issue
Block a user