Skip to content

Commit

Permalink
if memcache returns an numeric, cast it to a float
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidGoodwin committed Oct 22, 2024
1 parent 667cf12 commit bc6c930
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions src/Adapter/Memcached.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,18 @@ public function set(string $key, float $value, int $ttl): bool
}

public function get(string $key): float
{
$ret = $this->realGet($key);
if (is_float($ret)) {
return $ret;
}
throw new \InvalidArgumentException("Unexpected data type from memcache, expected float, got " . gettype($ret));
}

private function realGet(string $key): bool|float
{
$ret = $this->memcached->get($key);
if (is_float($ret) || is_bool($ret)) {
return $ret;
if (is_numeric($ret)) {
return (float) $ret;
}
throw new \InvalidArgumentException("Unsupported data type from memcache: " . gettype($ret));
throw new \InvalidArgumentException("Unexpected data type from memcache, expected float, got " . gettype($ret));
}

public function exists(string $key): bool
{
$val = $this->realGet($key);
return $val !== false;
$ret = $this->memcached->get($key);
return $ret !== false;
}

public function del(string $key): bool
Expand Down

0 comments on commit bc6c930

Please sign in to comment.