add dredis files

This commit is contained in:
Guobao Jiang 2014-03-18 18:38:19 +08:00
parent 0c324a186d
commit f85a400ef1
3 changed files with 118 additions and 0 deletions

49
redis/dredis/dmanager.php Normal file
View File

@ -0,0 +1,49 @@
<?php
/***
* CLASS NAME
* dmanager
* this class is used for manage the distributed system.
*
* DATE
* 2014-03-18
*
***/
class dmanager
{
private $rediska;
private $options = array(
'namespace' => 'Application_',
'servers' => array(
array('host' => '127.0.0.1', 'port' => 6379, 'alias' => 'mas01'),
array('host' => '127.0.0.1', 'port' => 6380, 'alias' => 'ins01'),
array('host' => '127.0.0.1', 'port' => 6381, 'alias' => 'ins02'),
array('host' => '192.168.122.10', 'port' => 6379, 'alias' => 'sla01'),
array('host' => '192.168.122.10', 'port' => 6380, 'alias' => 'ins03'),
array('host' => '192.168.122.10', 'port' => 6381, 'alias' => 'ins04'),
)
);
public function __construct()
{
$this->rediska = new Rediska($this->options);
}
public function getOptions()
{
return $this->options;
}
public function addServer($serverIp,$serverPort)
{
return $this->rediska->addServer($serverIp, $serverPort);
}
public function removeServer($aliasOrConnection)
{
return $this->rediska->removeServer($aliasOrConnection);
}
}
?>

56
redis/dredis/dredis.php Normal file
View File

@ -0,0 +1,56 @@
<?php
/***
*
* INTRO
* The class provides an universal interface
* for call distributed redis system.
*
* NOTE
* function name begin with t_, only use for test
*
* DATE
* 2014-03-18
*
***/
require_once '/vagrant_data/data/rediska/library/Rediska.php';
require_once '/vagrant_data/data/rediska/dmanager.php';
class dredis
{
private $rediska;
private $options;
public function __construct()
{
$dm = new dmanager();
$this->options = $dm->getOptions();
$this->rediska = new Rediska($this->options);
}
public function __destruct()
{
## destruct function
}
public function set($keyName, $keyValue)
{
$key = new Rediska_Key($keyName);
$key->setValue($keyValue);
}
public function get($keyName)
{
$key = new Rediska_Key($keyName);
return $key->getValue();
}
public function t_print($keyName)
{
echo "<br/>";
print "key:$keyName"." value:".$this->get($keyName);
}
}
?>

13
redis/dredis/hello.php Normal file
View File

@ -0,0 +1,13 @@
<?php
require_once 'dredis.php';
// Initialize Rediska
echo "<br/>";
echo "dredis test.";
$redis = new dredis();
//$redis->set('linux','is a os');
$redis->t_print('linux');
?>