Sicaa/starter-kit-cache

语言: PHP

git: https://github.com/Sicaa/starter-kit-cache

用于Memcached的PHP单例
PHP singleton for Memcached
README.md (中文)

起动工具包高速缓冲存储器

用于Memcached / Redis的PHP单例

Latest Stable Version License

要求

  • PHP> = 5.3

建议

  • PHP Memcached扩展
  • PHP Redis扩展

安装

通过Composer直接安装:

$ composer require starter-kit/cache

基本用法

Memcached的

<?php

// Require your autoloading script (Composer autoload here) to use namespaces
require_once 'vendor/autoload.php';

use StarterKit\Cache\Memcached;

// First instanciation : pass your Memcached parameters
$mc = Memcached::getInstance('YOUR_SERVER_NAME', 'YOUR_SERVER_PORT');

// Later in your code : you can retrieve your instance at any time, without creating new Memcached connection
$res = Memcached::getInstance()->set('yolo', 'swag');

Redis的

<?php

// Require your autoloading script (Composer autoload here) to use namespaces
require_once 'vendor/autoload.php';

use StarterKit\Cache\Redis;

// First instanciation : pass your Redis parameters
$mc = Redis::getInstance('YOUR_SERVER_NAME', 'YOUR_SERVER_PORT');

// Later in your code : you can retrieve your instance at any time, without creating new Redis connection
$res = Redis::getInstance()->set('yolo', 'swag');

本文使用googletrans自动翻译,仅供参考, 原文来自github.com

en_README.md

starter-kit-cache

PHP singleton for Memcached/Redis

Latest Stable Version License

Requirements

  • PHP >= 5.3

Suggestions

  • PHP Memcached extension
  • PHP Redis extension

Installation

Install directly via Composer:

$ composer require starter-kit/cache

Basic Usage

Memcached

<?php

// Require your autoloading script (Composer autoload here) to use namespaces
require_once 'vendor/autoload.php';

use StarterKit\Cache\Memcached;

// First instanciation : pass your Memcached parameters
$mc = Memcached::getInstance('YOUR_SERVER_NAME', 'YOUR_SERVER_PORT');

// Later in your code : you can retrieve your instance at any time, without creating new Memcached connection
$res = Memcached::getInstance()->set('yolo', 'swag');

Redis

<?php

// Require your autoloading script (Composer autoload here) to use namespaces
require_once 'vendor/autoload.php';

use StarterKit\Cache\Redis;

// First instanciation : pass your Redis parameters
$mc = Redis::getInstance('YOUR_SERVER_NAME', 'YOUR_SERVER_PORT');

// Later in your code : you can retrieve your instance at any time, without creating new Redis connection
$res = Redis::getInstance()->set('yolo', 'swag');