PHP code example of flatphp / memstore
1. Go to this page and download the library: Download flatphp/memstore 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/ */
flatphp / memstore example snippets
composer
use Flatphp\Memstore\Conn;
// single
Conn::init(array(
'memcache' => ['host' => '127.0.0.1', 'port' => 11211],
'memcached' => ['host' => '127.0.0.1', 'port' => 11211],
'redis' => ['host' => '127.0.0.1', 'port' => '6379'],
'redis_cluster' => ['seeds' => ['host1:7001', 'host2:7002']],
'predis' => ['host' => '127.0.0.1', 'port' => '6379'],
));
$memcache = Conn::getMemcache();
$memcached = Conn::getMemcached();
$redis = Conn::getRedis();
$redis_cluster = Conn::getRedisCluster();
$predis = Conn::getPredis();
$redis->set('test', 1);
......
// single:
array(
'host' => '127.0.0.1', // > true,
'weight' => 1,
# 'timeout' => 1,
# 'retry_interval' => 15,
# 'status' => true,
# 'failure_callback' => null
)
// multi:
array(
array('host' => 'host1', ......),
array('host' => 'host2', ......)
)
......
array(
'options' = [],
'persistent_id' => 'mc',
'host' => 'localhost', //
'persistent_id' => '',
array('host' => 'host1', 'port' => 11211, 'weight' => 1),
array('host' => 'host2', 'port' => 11211, 'weight' => 1)
)
array(
'options' => [],
'host' => '127.0.0.1', // 'persistent' => false,
'database' => 0,
'timeout' => 0
)
array(
'options' => [],
//'name' => 'mycluster'
'seeds' => ['host1:7000', 'host2:7001'] // name or seeds is
array(
'options' => [],
'host' => '127.0.0.1',
'port' => '6379',
'password' => 'xxx',
'persistent' => false,
'database' => 0,
'timeout' => 0
)
array(
'options' => [],
array(
'host' => '127.0.0.1',
'port' => '6379',
'password' => 'xxx',
'persistent' => false,
'database' => 0,
'timeout' => 0
),
array(
'host' => '127.0.0.1',
......
)
)