Skip to content

Instantly share code, notes, and snippets.

@ecitecm
Created December 6, 2012 21:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ecitecm/4228720 to your computer and use it in GitHub Desktop.
Save ecitecm/4228720 to your computer and use it in GitHub Desktop.
<?php
/*
* This file is part of the Predis package.
*
* (c) Daniele Alessandri <suppakilla@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
require 'SharedConfigurations.php';
// simple set and get scenario
function cloneOptions($options) {
$new = clone $options;
$refl = new ReflectionProperty($new, 'options');
$refl->setAccessible(true);
$inner = $refl->getValue($new);
foreach ($inner as $k => $v) {
if ($v) {
$inner[$k] = clone $v;
}
}
$refl->setValue($new, $inner);
return $new;
}
function prefix($client, $prefix) {
$options = cloneOptions($client->getOptions());
if ($old = $options->profile->getProcessor()) {
$prefix = $old->getPrefix() . $prefix;
}
$processor = new Predis\Command\Processor\KeyPrefixProcessor($prefix);
$options->profile->setProcessor($processor);
return new Predis\Client($client->getConnection(), $options);
}
$client = new Predis\Client($single_server);
$appClient = prefix($client, 'myapp:dev:');
$featureClient = prefix($appClient, 'feature:');
$client->get('original');
$appClient->get('prefixed');
$featureClient->get('cowbell');
/* KEYS ACCESSED
*
* original
* myapp:dev:prefixed
* myapp:dev:feature:cowbell
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment