PHP code example of rayswoole / memcache-pool

1. Go to this page and download the library: Download rayswoole/memcache-pool 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/ */

    

rayswoole / memcache-pool example snippets


//初始化连接配置
$redisConfig = new \rayswoole\memcache\MemcacheConfig();
//设置最小闲置连接数
$redisConfig->withMin(20);
//设置最大连接数
$redisConfig->withMax(100);
//设置定时器执行频率(毫秒),创建最小空间连接、回收空闲连接
$redisConfig->withIntervalTime(15*1000);
//设置连接可空闲时间
$redisConfig->withIdleTime(30);
//获取连接池对象超时时间, 如果连接池占满在指定时间无法释放新的连接, 将输出Exception, 需要自行捕获
$redisConfig->withTimeout(3.0);
//数据库配置注入
$redisConfig->withExtraConf('memcache配置');
//初始化连接池
\rayswoole\memcache\facade\Memcache::init($redisConfig);

$config = [
    'server' => '127.0.0.1',
    'port' => 11211,
];

use rayswoole\memcache\facade\Memcache;

Memcache::getInstance()->set('aa',1234);

Memcache::getInstance()->get('aa');

Memcache::getInstance()->clear();

$config = [
    'server' => '127.0.0.1',
    'port' => 11211,
];

$memcache = \rayswoole\memcache\MemcacheClient::get($config);

$memcache->set('aa',1234);