Created
December 6, 2012 21:38
-
-
Save ecitecm/4228720 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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