PHP singleton for Memcached/Redis
- PHP >= 5.3
- PHP Memcached extension
- PHP Redis extension
Install directly via Composer:
$ composer require starter-kit/cache
<?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');
<?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');