예제 #1
0
 public static function getRediskaInstance($rediska, $exceptionClassName = 'Rediska_Exception', $optionName = 'rediska')
 {
     if (is_string($rediska)) {
         // Rediska instance name
         if ($rediska == Rediska::DEFAULT_NAME) {
             // Default name
             if (Rediska_Manager::has($rediska)) {
                 $rediska = Rediska_Manager::get($rediska);
             } else {
                 throw new $exceptionClassName("You must instance '" . Rediska::DEFAULT_NAME . "' Rediska before or use '{$optionName}' option for specify another");
             }
         } else {
             // Another name
             $rediska = Rediska_Manager::get($rediska);
         }
     } else {
         if (is_array($rediska)) {
             // Rediska options
             $options = $rediska;
             $options['addToManager'] = false;
             $rediska = new Rediska($options);
         } else {
             if (!$rediska instanceof Rediska) {
                 throw new $exceptionClassName("'{$optionName}' option must be instance name, Rediska object or rediska options for new instance");
             }
         }
     }
     return $rediska;
 }
예제 #2
0
 public function testNamedInstance()
 {
     $application = new Zend_Application('tests', dirname(__FILE__) . '/application3.ini');
     $manager = $application->bootstrap()->getBootstrap()->getResource('cachemanager');
     $manager->getCache('test')->save('1', 'test');
     $one = Rediska_Manager::get('test')->get('test');
     $this->assertEquals('1', $one[0]);
     $this->assertFalse(Rediska_Manager::has('default'));
 }
예제 #3
0
 /**
  * Constructs the redis Kohana_Cache object
  *
  * @param   array     configuration
  * @throws  Kohana_Cache_Exception
  */
 public function __construct(array $config)
 {
     // Check for the Rediska module
     if (!class_exists('Rediska')) {
         throw new Kohana_Cache_Exception('Rediska module not loaded');
     }
     parent::__construct($config);
     $instance = Arr::get($this->_config, 'instance', Rediska::DEFAULT_NAME);
     $this->_rediska = Rediska_Manager::get($instance);
 }
예제 #4
0
 /**
  *
  * @param array $config
  * @param string $id
  */
 public function __construct(array $config = NULL, $id = NULL)
 {
     // Check for the Rediska module
     if (!class_exists('Rediska')) {
         throw new Kohana_Exception('Rediska module not loaded');
     }
     $instance = Arr::get($config, 'instance', Rediska::DEFAULT_NAME);
     $this->_cookie_name = Arr::get($config, 'cookie_name', $this->_cookie_name);
     $this->_rediska = Rediska_Manager::get($instance);
     parent::__construct($config, $id);
 }
예제 #5
0
 public function testNamedInstance()
 {
     $application = new Zend_Application('tests', dirname(__FILE__) . '/application3.ini');
     $log = $application->bootstrap()->getBootstrap()->getResource('log');
     $log->err('123');
     $log->info('123');
     $rediska = Rediska_Manager::get('test');
     $count = $rediska->getListLength('log');
     $this->assertEquals(2, $count);
     $this->assertFalse(Rediska_Manager::has('default'));
 }
예제 #6
0
 public function testDefaultAndAnother()
 {
     $application = new Zend_Application('tests', dirname(__FILE__) . '/application4.ini');
     $application->bootstrap()->getBootstrap()->getResource('rediska');
     $default = Rediska_Manager::get('default');
     $this->assertEquals('defaultInstance', $default->getOption('namespace'));
     $another = Rediska_Manager::get('another');
     $this->assertEquals('anotherInstance', $another->getOption('namespace'));
     $this->assertEquals(2, count(Rediska_Manager::getAll()));
     $this->assertEquals($default, Zend_Registry::get('rediska'));
 }
예제 #7
0
<?php

require_once '/vagrant_data/data/rediska/library/Rediska.php';
// Initialize Rediska
$options = array('namespace' => 'Cache_', 'name' => 'cache');
$rediska = new Rediska($options);
$rediska = Rediska_Manager::get('default');
print $rediska->getName();
#=> cache
$keyName = "key0";
$key = new Rediska_Key($keyName);
$key->setValue("zzzzzzzzzzzzz");