memcached學習筆記5--socke操作memcached 緩衝系統

來源:互聯網
上載者:User

標籤:style   blog   http   color   使用   檔案   資料   2014   

使用條件:當我們沒有許可權或者不能使用伺服器的時候,我們需要用socket操作memcached

memcached-client操作

特點:

  無需開啟memcache擴充

  使用fsocketopen()通訊端串連memcached 

  同樣執行CRUD

 

        require_once(CLASS_PATH.‘memcached-client.php‘);//CLASS_PATH 是我定義的類檔案檔案夾路徑        $mc = new memcached(                array(                    ‘servers‘ => array(                        ‘127.0.0.1:11211‘,                        ‘127.0.0.1:11222‘ //這裡我在本機同時開啟了2個memcached服務,服務名不同。                        ),//如果有多個Memcached伺服器,那麼用,號間隔開                    ‘debug‘   => false,//是否開啟偵錯模式                    ‘compress_threshold‘ => 10240,//壓縮率,預設值即可                    ‘persistant‘ => false//是否開啟長串連,一般不開啟長串連,改設為false                    )                );
     //資料 $user = array( array( ‘u1‘ => ‘admin1‘, ‘age1‘ => 23, ‘email‘ => ‘[email protected]‘ ), array( ‘u2‘ => ‘admin2‘, ‘age1‘ => 25, ‘email‘ => ‘[email protected]‘ ), ); $user = json_encode($user); $mc->add(‘user‘, $user, 60); // $mc->replace(‘user‘, ‘String replace the Array Of User‘); $user = object2array(json_decode($mc->get(‘user‘))); dump($user); $mc->add(‘user3‘, ‘Laijun_ttx‘, 60); $user3 = $mc->get(‘user3‘); dump($user3);

結果

沒有報錯,正常運行!測試成功!

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.