dev-analysis-qv2aMV
dev-analysis-qv2aMV
MIT
The Development Requires
by qii404
dev-master
9999999-dev
MIT
The Development Requires
by qii404
dev-dev
dev-dev
MIT
The Requires
- php >=5.4
The Development Requires
by qii404
Wallogit.com
2017 © Pedro Peláez
Redis client for php, which supports single redis server, or redis Master-Slave clusters., (*1)
1.composer is recommended, (*2)
composer require shibo/redis, (*3)
or in your composer.json, (*4)
{
"require": {
"shibo/redis" : "^1.0"
}
}
2.if you do not use composer, you should include 'Autoload.php' in your code, (*5)
1.single redis server, (*6)
read & write operations are all executed in the single serve., (*7)
use \Redis\SingleClient;
use \Redis\Drivers\RedisFactory;
include 'Autoload.php';
$config = ['host' => '127.0.0.1', 'port' => 6379, 'weight' => 1];
// if need auth
// $config = ['host' => '127.0.0.1', 'port' => 6379, 'weight' => 1, 'auth' => 'qii'];
$redis = new SingleClient(
$config,
RedisFactory::PHPREDIS // this is optional param, default is PHPREDIS driver
);
$redis->set('name', 'qii404'); // true
$redis->get('name'); // 'qii404'
2.redis cluster without slaves, (*8)
read & write operations executed in the same one server of the cluster., (*9)
use Redis\Drivers\RedisFactory;
use Redis\WithoutSlavesClient;
use Redis\Hash;
use Redis\Key;
include 'Autoload.php';
$config = [
['host' => '127.0.0.1', 'port' => 6379, 'weight' => 1],
['host' => '127.0.0.1', 'port' => 6380],
];
// hash stragety, you can also define your stragety in Hash folder
$hash = new Hash\Consistant();
// key hasher, such as new Md5 or Cr32, you can add it in Key folder
$calculator = new Key\Cr32();
// $calculator = new Key\Md5();
$redis = new WithoutSlavesClient(
$config,
$hash,
$calculator,
RedisFactory::PHPREDIS // this is optional param, default is PHPREDIS driver
);
// when using the same key, both read & write operation executed in the same server, such as port 6379
$redis->hset('profile', 'name', 'qii44'); // true
$redis->hget('profile', 'name'); // 'qii404'
3.redis cluster with slaves, (*10)
read & write operations executed in the different servers, read from the slave servers, write from the master servers, (*11)
(You should config it right for 'm' & 's', such as 6381 is slave of 6379, 6382 is slave of 6380)., (*12)
use Redis\Drivers\RedisFactory;
use Redis\WithSlavesClient;
use Redis\Hash;
use Redis\Key;
include 'Autoload.php';
$config = [
'm' =>[
['host' => '127.0.0.1', 'port' => 6379, 'weight' => 1],
['host' => '127.0.0.1', 'port' => 6380],
],
's' =>[
['host' => '127.0.0.1', 'port' => 6381],
['host' => '127.0.0.1', 'port' => 6382],
]
];
// hash stragety, you can also define your stragety in Hash folder
$hash = new Hash\Consistant();
// key hasher, such as new Md5 or Cr32, you can add it in Key folder
$calculator = new Key\Cr32();
// $calculator = new Key\Md5();
$redis = new WithSlavesClient(
$config,
$hash,
$calculator,
RedisFactory::PHPREDIS // this is optional param, default is PHPREDIS driver
);
$redis->zadd('key', 99, 'qii404'); // true; executes in master server, such as port 6379
$redis->zscore('key', 'qii404'); // 99; executes in slave server, such as port 6381
MIT
MIT
MIT