五月天激情丁香,国产精品2019,国产成人精品亚洲2020,国产精品免费视频一区二区三区,开心久久婷婷综合中文字幕,天堂视频在线观看免费完整版

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);
});
主站蜘蛛池模板: 色一色在线观看视频网站 | 99精品影视 | 男女视频网址 | 国产在线一区精品对白麻豆 | 成人欧美精品一区二区不卡 | 国产一级高清视频免费看 | 欧美自拍偷拍 | 五月玖玖 | 丁香六月综合激情 | 免费在线观看黄视频 | 五月激情婷婷网 | 免费视频一区二区三区四区 | 免费国产午夜高清在线视频 | 日本亚洲国产精品久久 | 精品视频一区二区三区免费 | 暖暖喜欢你电视剧免费观看完整版高清 | 欧美高清日韩 | 蜜臀免费视频 | 久久久无码精品亚洲日韩按摩 | 国产二区三区毛片 | 久青草国产高清在线视频 | 国产成人区 | 免费视频不卡一区二区三区 | 奇妙的沙龙 | 97综合| 激情欧美色图 | 黄色大片影院视频免费 | 国产一级毛片视频在线! | 美女被爆羞羞网站免费 | 免费一区二区三区毛片10分钟 | 精品亚洲成a人片在线观看 精品小视频在线 | 视频一区在线播放 | 日本中文字幕精品理论在线 | 国产精品免费视频一区一 | 李丽珍电影免费观看全集 | 国产男女免费视频 | 九九九国产 | 人人狠狠综合久久亚洲婷婷 | 免费亚洲视频 | 99热官网| 久久久99精品久久久久久 |