Skip to content

Commit 0ce2e73

Browse files
Merge pull request #5 from Memcrab/add-ttl-method
add new methods
2 parents bc7c2c8 + 4b426b8 commit 0ce2e73

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

src/CachePool.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,4 +273,58 @@ public function hVals($key): bool|array|Redis
273273

274274
return $result;
275275
}
276+
277+
/**
278+
* @param $key
279+
* @return int|false|Redis
280+
*/
281+
public function getTTL($key): bool|int|Redis
282+
{
283+
try {
284+
$Redis = $this->getRedis();
285+
$result = $Redis->ttl($key);
286+
$this->putRedis($Redis);
287+
} catch (\Exception $e) {
288+
$this->addError($e->getMessage());
289+
return false;
290+
}
291+
292+
return $result;
293+
}
294+
295+
/**
296+
* @return string|false|Redis
297+
*/
298+
public function getLastError(): bool|string|Redis
299+
{
300+
try {
301+
$Redis = $this->getRedis();
302+
$result = $Redis->getLastError();
303+
$this->putRedis($Redis);
304+
} catch (\Exception $e) {
305+
$this->addError($e->getMessage());
306+
return false;
307+
}
308+
309+
return $result;
310+
}
311+
312+
/**
313+
* @param $key
314+
* @param int $ttl
315+
* @return int|false|Redis
316+
*/
317+
public function setExpire($key, int $ttl): bool|Redis
318+
{
319+
try {
320+
$Redis = $this->getRedis();
321+
$result = $Redis->expire($key, $ttl);
322+
$this->putRedis($Redis);
323+
} catch (\Exception $e) {
324+
$this->addError($e->getMessage());
325+
return false;
326+
}
327+
328+
return $result;
329+
}
276330
}

0 commit comments

Comments
 (0)