Overview

Namespaces

  • Webmozart
    • KeyValueStore
      • Api
      • Decorator
      • Util

Classes

  • AbstractRedisStore
  • ArrayStore
  • DbalStore
  • JsonFileStore
  • MongoDbStore
  • NullStore
  • PhpRedisStore
  • PredisStore
  • RiakStore
  • SerializingArrayStore
  • Overview
  • Namespace
  • Class
  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: 
<?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 Predis\Client;
use Predis\ClientInterface;

/**
 * A key-value store that uses Predis to connect to a Redis instance.
 *
 * @since  1.0
 *
 * @author Bernhard Schussek <bschussek@gmail.com>
 * @author Titouan Galopin <galopintitouan@gmail.com>
 */
class PredisStore extends AbstractRedisStore
{
    /**
     * Creates a store backed by a Predis 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 ClientInterface|null $client The client used to connect to Redis.
     */
    public function __construct(ClientInterface $client = null)
    {
        $this->client = $client ?: new Client();
    }

    /**
     * {@inheritdoc}
     */
    protected function clientNotFoundValue()
    {
        return null;
    }

    /**
     * {@inheritdoc}
     */
    protected function clientGet($key)
    {
        return $this->client->get($key);
    }

    /**
     * {@inheritdoc}
     */
    protected function clientGetMultiple(array $keys)
    {
        return $this->client->mget($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('*');
    }
}
Webmozart Key-Value Store API API documentation generated by ApiGen