Permalink
Browse files

Added prefix_key and expire_timeout options

  • Loading branch information...
1 parent 5a90523 commit abd2f52f81165c40788b9ad07c4626ac326df8df @jeremyFreeAgent jeremyFreeAgent committed Nov 23, 2012
View
@@ -9,4 +9,8 @@
*/
class Bitter extends BaseBitter
{
+ public function __construct($redisClient, $prefixKey, $expireTimeout)
+ {
+ parent:: __construct($redisClient, $prefixKey . ':', $prefixKey . '_temp:', $expireTimeout);
+ }
}
@@ -23,6 +23,12 @@ public function getConfigTreeBuilder()
->isRequired()
->cannotBeEmpty()
->end()
+ ->scalarNode('prefix_key')
+ ->defaultValue('bitter')
+ ->end()
+ ->scalarNode('expire_timeout')
+ ->defaultValue(60)
+ ->end()
->end()
;
@@ -21,6 +21,8 @@ public function load(array $configs, ContainerBuilder $container)
$config = $this->processConfiguration($configuration, $configs);
$container->setAlias('rezzza_bitter.redis_client', $config['redis_client']);
+ $container->setParameter('rezzza_bitter.prefix_key', $config['prefix_key']);
+ $container->setParameter('rezzza_bitter.expire_timeout', $config['expire_timeout']);
$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('bitter.xml');
View
@@ -50,6 +50,18 @@ Using custom redis client:
rezzza_bitter:
redis_client: your.very.best.redis.client
+You can also configure custom values for `prefix_key` and `expire_timeout`:
+
+.. code-block:: yaml
+
+ rezzza_bitter:
+ redis_client: snc_redis.default
+ prefix_key: jack_bauer
+ expire_timeout: 404
+
+.. note::
+ Default values for `prefix_key` and `expire_timeout` are **bitter** and **60**.
+
Basic usage
-----------
Get Bitter:
@@ -4,12 +4,14 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
<parameters>
- <parameter key="rezzza.bitter.class">Rezzza\BitterBundle\Bitter\Bitter</parameter>
+ <parameter key="rezzza_bitter.class">Rezzza\BitterBundle\Bitter\Bitter</parameter>
</parameters>
<services>
- <service id="rezzza.bitter" class="%rezzza.bitter.class%">
+ <service id="rezzza.bitter" class="%rezzza_bitter.class%">
<argument type="service" id="rezzza_bitter.redis_client" />
+ <argument>%rezzza_bitter.prefix_key%</argument>
+ <argument>%rezzza_bitter.expire_timeout%</argument>
</service>
</services>
@@ -10,15 +10,16 @@
class RezzzaBitterExtension extends Test
{
- public function testDefault()
+ public function testNoClient()
{
$this->if($loader = new Extension())
->and($config = array())
->exception(function() use ($loader, $config) {
$loader->load(array($config), new ContainerBuilder());
})
->isInstanceOf('\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException')
- ->hasMessage('The child node "redis_client" at path "rezzza_bitter" must be configured.');
+ ->hasMessage('The child node "redis_client" at path "rezzza_bitter" must be configured.')
+ ;
}
public function testEmptyClient()
@@ -31,10 +32,11 @@ public function testEmptyClient()
$loader->load(array($config), new ContainerBuilder());
})
->isInstanceOf('\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException')
- ->hasMessage('The path "rezzza_bitter.redis_client" cannot contain an empty value, but got "".');
+ ->hasMessage('The path "rezzza_bitter.redis_client" cannot contain an empty value, but got "".')
+ ;
}
- public function testClient()
+ public function testDefaultClient()
{
$this->if($loader = new Extension())
->and($container = new ContainerBuilder())
@@ -45,7 +47,30 @@ public function testClient()
->object($alias = $container->getAlias('rezzza_bitter.redis_client'))
->toString()
->isEqualTo('redis.client')
- ;
+ ->string($prefix_key = $container->getParameter('rezzza_bitter.prefix_key'))
+ ->isEqualTo('bitter')
+ ->integer($expire_timeout = $container->getParameter('rezzza_bitter.expire_timeout'))
+ ->isEqualTo(60)
+ ;
}
+ public function testFullyConfiguredClient()
+ {
+ $this->if($loader = new Extension())
+ ->and($container = new ContainerBuilder())
+ ->and($config = array(
+ 'redis_client' => 'redis.client',
+ 'prefix_key' => 'jack_bauer',
+ 'expire_timeout' => 404,
+ ))
+ ->then($loader->load(array($config), $container))
+ ->object($alias = $container->getAlias('rezzza_bitter.redis_client'))
+ ->toString()
+ ->isEqualTo('redis.client')
+ ->string($prefix_key = $container->getParameter('rezzza_bitter.prefix_key'))
+ ->isEqualTo('jack_bauer')
+ ->integer($expire_timeout = $container->getParameter('rezzza_bitter.expire_timeout'))
+ ->isEqualTo(404)
+ ;
+ }
}

0 comments on commit abd2f52

Please sign in to comment.