1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111:
<?php
/*
* This file is part of the webmozart/key-value-store package.
*
* (c) Bernhard Schussek <bschussek@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Webmozart\KeyValueStore;
use Redis;
/**
* A key-value store that uses the PhpRedis extension to connect to a Redis instance.
*
* @since 1.0
*
* @author Bernhard Schussek <bschussek@gmail.com>
* @author Philipp Wahala <philipp.wahala@gmail.com>
* @author Titouan Galopin <galopintitouan@gmail.com>
*
* @link https://github.com/phpredis/phpredis
*/
class PhpRedisStore extends AbstractRedisStore
{
/**
* Creates a store backed by a PhpRedis client.
*
* If no client is passed, a new one is created using the default server
* "127.0.0.1" and the default port 6379.
*
* @param Redis|null $client The client used to connect to Redis.
*/
public function __construct(Redis $client = null)
{
if (null === $client) {
$client = new Redis();
$client->connect('127.0.0.1', 6379);
}
$this->client = $client;
}
/**
* {@inheritdoc}
*/
protected function clientNotFoundValue()
{
return false;
}
/**
* {@inheritdoc}
*/
protected function clientGet($key)
{
return $this->client->get($key);
}
/**
* {@inheritdoc}
*/
protected function clientGetMultiple(array $keys)
{
return $this->client->getMultiple($keys);
}
/**
* {@inheritdoc}
*/
protected function clientSet($key, $value)
{
$this->client->set($key, $value);
}
/**
* {@inheritdoc}
*/
protected function clientRemove($key)
{
return (bool) $this->client->del($key);
}
/**
* {@inheritdoc}
*/
protected function clientExists($key)
{
return (bool) $this->client->exists($key);
}
/**
* {@inheritdoc}
*/
protected function clientClear()
{
$this->client->flushdb();
}
/**
* {@inheritdoc}
*/
protected function clientKeys()
{
return $this->client->keys('*');
}
}