1. Go to this page and download the library: Download shibo/redis library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
shibo / redis example snippets
use \Redis\SingleClient;
use \Redis\Drivers\RedisFactory;
' => 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'
use Redis\Drivers\RedisFactory;
use Redis\WithoutSlavesClient;
use Redis\Hash;
use Redis\Key;
.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'
use Redis\Drivers\RedisFactory;
use Redis\WithSlavesClient;
use Redis\Hash;
use Redis\Key;
['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
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.