Ejemplo n.º 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;
 }
Ejemplo n.º 2
0
 public function testNewInstance()
 {
     $application = new Zend_Application('tests', dirname(__FILE__) . '/application4.ini');
     $application->bootstrap()->getBootstrap()->getResource('session');
     $rediska = Zend_Session::getSaveHandler()->getRediska();
     $this->assertEquals('default', $rediska->getOption('name'));
     $this->assertEquals(array(), Rediska_Manager::getAll());
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 4
0
 public function testNewInstance()
 {
     $application = new Zend_Application('tests', dirname(__FILE__) . '/application4.ini');
     $manager = $application->bootstrap()->getBootstrap()->getResource('cachemanager');
     $manager->getCache('test')->save('1', 'test');
     $rediska = new Rediska(array('redisVersion' => '2.0', 'addToManager' => false));
     $one = $rediska->get('test');
     $this->assertEquals('1', $one[0]);
     $this->assertEquals(array(), Rediska_Manager::getAll());
 }
Ejemplo n.º 5
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);
 }
Ejemplo n.º 6
0
 public function testNewInstance()
 {
     $application = new Zend_Application('tests', dirname(__FILE__) . '/application4.ini');
     $log = $application->bootstrap()->getBootstrap()->getResource('log');
     $log->err('123');
     $log->info('123');
     $rediska = new Rediska(array('redisVersion' => '2.0', 'addToManager' => false));
     $count = $rediska->getListLength('log');
     $this->assertEquals(2, $count);
     $this->assertEquals(array(), Rediska_Manager::getAll());
 }
Ejemplo n.º 7
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'));
 }
Ejemplo n.º 8
0
 /**
  * @group resource
  * @group auto_serialize
  */
 public function testNewInstanceWithAutoSerialization()
 {
     $application = new Zend_Application('tests', dirname(__FILE__) . '/application5.ini');
     /* @var Zend_Cache_Manager $manager */
     $manager = $application->bootstrap()->getBootstrap()->getResource('cachemanager');
     $manager->getCache('test')->save('321', 'test');
     $options = $manager->getCache('test')->getBackend()->getOption('storage');
     $rediska = new Rediska(array('redisVersion' => '2.0', 'addToManager' => false));
     $one = $rediska->getHashValues($options['prefix_key'] . 'test');
     $this->assertEquals('321', $one[0]);
     $this->assertEquals(array(), Rediska_Manager::getAll());
 }
Ejemplo n.º 9
0
 public function init()
 {
     $options = $this->getOptions();
     if (isset($options['instances'])) {
         foreach ($options['instances'] as $name => $instanceOptions) {
             if ($name == Rediska::DEFAULT_NAME) {
                 $options = $instanceOptions;
             } else {
                 $instanceOptions['name'] = $name;
                 Rediska_Manager::add($instanceOptions);
             }
         }
         unset($options['instances']);
     }
     if (!empty($options)) {
         $options['name'] = Rediska::DEFAULT_NAME;
         $rediska = new Rediska($options);
         Zend_Registry::set(self::DEFAULT_REGISTRY_KEY, $rediska);
         return $rediska;
     }
 }
Ejemplo n.º 10
0
 public function testGetRediskaByOptions()
 {
     $r = Rediska_Options_RediskaInstance::getRediskaInstance(array('namespace' => 'byOptions'));
     $this->assertEquals('byOptions', $r->getOption('namespace'));
     $this->assertEquals(array(), Rediska_Manager::getAll());
 }
Ejemplo n.º 11
0
 /**
  * Remove all rediska
  * Return count of removed instance
  *
  * @return integer
  */
 public static function removeAll()
 {
     $count = count(self::$_instances);
     self::$_instances = array();
     return $count;
 }
Ejemplo n.º 12
0
 /**
  * Set Rediska client name
  *
  * @param string $name
  * @return Rediska
  */
 public function setName($name)
 {
     $this->_options['name'] = $name;
     if ($this->_options['addToManager']) {
         Rediska_Manager::add($this);
     }
     return $this;
 }
Ejemplo n.º 13
0
<?php

defined('SYSPATH') or die('No direct script access.');
$config = Kohana::$config->load('rediska');
foreach ($config as $options) {
    Rediska_Manager::add($options);
}
Ejemplo n.º 14
0
<?php

$options = array('namespace' => 'Application_', 'servers' => array(array('host' => '127.0.0.1', 'port' => 6379, 'alias' => '9'), array('host' => '127.0.0.1', 'port' => 6380, 'alias' => '0')));
require_once '/vagrant_data/data/rediska/library/Rediska.php';
$rediska = new Rediska($options);
var_dump(Rediska_Manager::getAll());
// Initialize key with name 'keyName'
if (Rediska_Manager::has('default')) {
    echo "<br/>";
    echo "exist@@@@@@@@@@@@@@@";
    echo "<br/>";
}
if (Rediska_Manager::add($rediska)) {
    echo "add success";
} else {
    echo "add failed";
}
$rediska->flushdb();
#return;
for ($i = 0; $i < 10; $i++) {
    $keyName = "key{$i}";
    $key = new Rediska_Key($keyName);
    $keyValue = "value_{$i}" . "_first";
    echo "<br/>";
    $key->setValue($keyValue);
    print "key:{$keyName}" . " value:" . $key->getValue();
    #=> value
}
# $rediska->addServer('192.168.122.10', 6379);
$rediska->addServer('10.8.8.10', 6379);
$connection = $rediska->getConnectionByAlias('0');
Ejemplo n.º 15
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");