Example #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;
 }
Example #2
0
 public function testNamedInstance()
 {
     $application = new Zend_Application('tests', dirname(__FILE__) . '/application3.ini');
     $application->bootstrap()->getBootstrap()->getResource('session');
     $rediska = Zend_Session::getSaveHandler()->getRediska();
     $this->assertEquals('test', $rediska->getOption('name'));
     $this->assertFalse(Rediska_Manager::has('default'));
 }
Example #3
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'));
 }
Example #4
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'));
 }
Example #5
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');