中文在线一区二区_欧美在线综合_久久久久久综合_欧美一区二区三区视频_国产免费看_国产福利精品一区

memcache協程客戶端

memcache協程客戶端,由swoole 協程client實現

組件要求

  • easyswoole/spl: ^1.1

安裝方法

composer require easyswoole/memcache

倉庫地址

easyswoole/memcache

客戶端調用

$config = new \EasySwoole\Memcache\Config([
    'host' => '127.0.0.1',
    'port' => 11211
]);
$client = new EasySwoole\Memcache\Memcache($config);

使用示例:

$config = new \EasySwoole\Memcache\Config([
    'host' => '127.0.0.1',
    'port' => 11211
]);
$client = new EasySwoole\Memcache\Memcache($config);
$client->set('a',1);
$client->get('a');

使用方法:

touch摸一下(刷新有效期)

touch($key, $expiration, $timeout = null)

increment自增KEY

increment($key, $offset = 1, $initialValue = 0, $expiration = 0, $timeout = null)

decrement自減KEY

decrement($key, $offset = 1, $initialValue = 0, $expiration = 0, $timeout = null)

set設置KEY(覆蓋)

set($key, $value, $expiration = 0, $timeout = null)

add增加KEY(非覆蓋)

add($key, $value, $expiration = 0, $timeout = null)

replace替換一個KEY

replace($key, $value, $expiration = 0, $timeout = null)

append追加數據到末尾

append($key, $value, $timeout = null)

prepend追加數據到開頭

prepend($key, $value, $timeout = null)

get獲取KEY

get($key, $timeout = null)

delete刪除一個key

delete($key, $timeout = null)

stats獲取服務器狀態

stats($type = null, $timeout = null)

version獲取服務器版本

version(int $timeout = null)

flush 清空緩存

flush(int $expiration = null, int $timeout = null)

setMulti 存儲多個元素

public function setMulti(array $items, $expiration = null, $timeout = null)

getMulti 檢索多個元素

public function getMulti(array $keys, bool $isCas = false, $timeout = null)

cas 檢查并設置

public function cas(float $casToken, string $key, $value, int $expiration = null, $timeout = null)

進階使用

Memcache連接池示例

安裝 easyswoole/pool 組件

composer require easyswoole/pool

具體pool相關詳細用法可查看 連接池

新增MemcachePool管理器

新增文件/App/Pool/MemcachePool.php

<?php
/**
 * Created by PhpStorm.
 * User: Tioncico
 * Date: 2019/10/15 0015
 * Time: 14:46
 */

namespace App\Pool;

use EasySwoole\Memcache\Memcache;
use EasySwoole\Pool\Config;
use EasySwoole\Pool\AbstractPool;
use EasySwoole\Memcache\Config as MemcacheConfig;

class MemcachePool extends AbstractPool
{
    protected $memcacheConfig;

    /**
     * 重寫構造函數,為了傳入memcache配置
     * RedisPool constructor.
     * @param Config      $conf
     * @param MemcacheConfig $memcacheConfig
     * @throws \EasySwoole\Pool\Exception\Exception
     */
    public function __construct(Config $conf,MemcacheConfig $memcacheConfig)
    {
        parent::__construct($conf);
        $this->memcacheConfig = $memcacheConfig;
    }

    protected function createObject():Memcache
    {
        //根據傳入的memcache配置進行new 一個memcache客戶端
        $memcache = new Memcache($this->memcacheConfig);
        return $memcache;
    }
}

注冊到Manager中(在initialize事件中注冊):


$config = new \EasySwoole\Pool\Config();

$memcacheConfig1 = new \EasySwoole\Memcache\Config(Config::getInstance()->getConf('MEMCACHE1'));
\EasySwoole\Pool\Manager::getInstance()->register(new \App\Pool\MemcachePool($config,$memcacheConfig1),'memcache1');

$memcacheConfig2 = new \EasySwoole\Memcache\Config(Config::getInstance()->getConf('MEMCACHE2'));
\EasySwoole\Pool\Manager::getInstance()->register(new \App\Pool\MemcachePool($config,$memcacheConfig2),'memcache2');

調用(可在控制器中全局調用):

go(function (){
    $memcachePool1 = Manager::getInstance()->get('memcache1');
    $memcachePool2 = Manager::getInstance()->get('memcache2');
    $memcache1 = $memcachePool1->getObj();
    $memcache2 = $memcachePool2->getObj();

    var_dump($memcache1->set('name', '仙士可1'));
    $this->response()->write($memcache1->get('name'));
    var_dump($memcache2->set('name', '仙士可2'));
    $this->response()->write($memcache2->get('name'));

    //回收對象
    $memcachePool1->recycleObj($memcache1);
    $memcachePool2->recycleObj($memcache2);
});
主站蜘蛛池模板: 欧美在线亚洲 | 五月天一区二区 | 久久精品免费观看 | 极品女神高潮呻吟av久久 | 久久久精品一区 | 九一视频在线免费观看 | 国产日韩精品一区 | 欧美精品欧美精品系列 | 五月天综合网 | 一区二区精品在线视频 | 亚洲一区二区三区在线免费观看 | 精品国产欧美一区二区三区成人 | 国产精品一码二码三码在线 | 欧美国产精品一区二区三区 | 亚洲国产精品人人爽夜夜爽 | 黄视频免费 | 午夜资源 | 一区二区久久 | 羞羞影视| 青草成人免费视频 | 国产在线91 | av日韩在线播放 | 久久只有精品 | 亚洲第一福利视频 | 欧美成年黄网站色视频 | 求av网址 | 亚洲一区二区三区免费观看 | 婷婷丁香激情网 | 日韩中文在线视频 | 中文字幕高清 | 中文字幕在线电影 | 欧美激情综合五月色丁香小说 | 欧美成人免费在线 | 91精品久久久久久综合五月天 | 亚洲国产成人av好男人在线观看 | 精品国产一二三区 | 狠狠干av| 黄色小视频免费 | 成人福利免费在线观看 | 成人在线小视频 | 91五月天|