Skip to content

Instantly share code, notes, and snippets.

@gsouf
Last active July 10, 2017 13:24
Show Gist options
  • Save gsouf/22795a9e3aa7acb4e72a5ad14f25219b to your computer and use it in GitHub Desktop.
Save gsouf/22795a9e3aa7acb4e72a5ad14f25219b to your computer and use it in GitHub Desktop.
phpcache-redis
<?php
include __DIR__ . '/vendor/autoload.php';
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
$pool = new \Cache\Adapter\Redis\RedisCachePool($redis);
$key = '|NS|foo|bar';
$time = 1000;
$item = $pool->getItem($key);
if (!$item->isHit()) {
echo 'miss';
$item->set('bar');
$item->expiresAfter($time);
$pool->save($item);
} else {
echo 'hit';
}
echo PHP_EOL;
<?php
include __DIR__ . '/vendor/autoload.php';
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
$pool = new \Cache\Adapter\Redis\RedisCachePool($redis);
$key = '|NS|foo';
$item = $pool->deleteItem($key);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment