php代码
<?php //if(!defined('BASEPATH')) exit('No direct script access allowed...'); /** * ---------------- redis.conf.php ------------------ * $redis_conf = array(); * $redis_conf['master'] = array();; * $redis_conf['master']['host'] = '127.0.0.1'; * $redis_conf['master']['port'] = 6379; * $redis_conf['master']['passwd'] = ''; * $redis_conf['master']['timeout'] = 1; * ---------------- author: simon ------------------ */ /** * Redis Client Interface * * ------------------- Usage --------------------- * $conf_dir = __DIR__ .'/../conf/redis.conf.php'; * $redis = RedisCli::getInstance($conf_dir, 'master'); * $ret = $redis->set('xxxxx', 'good'); * $ret = $redis->get('xxxxx'); * */ class RedisCli { private static $_instance = array(); private $_redis = false; /** * 单例模型,构造函数 */ public static function getInstance($conf_dir='/xxx/redis.conf.php', $serverName='master') { if (isset(self::$_instance[$serverName])) { return self::$_instance[$serverName]; } require_once($conf_dir); if (!isset($redis_conf[$serverName])) { throw new Exception("param serverName Or redis config error..."); } $conf = $redis_conf[$serverName]; if (!class_exists('Redis')) { throw new Exception("Class Redis not exists, please install the php Redis extension..."); } if (isset($conf['host']) && isset($conf['port']) && isset($conf['passwd']) && isset($conf['timeout'])) { self::$_instance[$serverName] = new self($conf['host'], $conf['port'], $conf['passwd'], $conf['timeout']); return self::$_instance[$serverName]; } return false; } /** * 私有, 单例模型,禁止外部构造 */ private function __construct($host, $port, $passwd, $timeout) { $this->_redis = new Redis(); if ($this->_redis->connect($host, $port, $timeout)) { if (!empty($passwd)) { $this->_redis->auth($passwd); } } } /** * 私有, 单例模型,禁止克隆 */ private function __clone() { } /** * 公有,调用对象函数 */ public function __call($method, $args) { if (!$this->_redis || !$method) { return false; } if (!method_exists($this->_redis, $method)) { throw new Exception("Class RedisCli not have method ($method) "); } return call_user_func_array(array($this->_redis, $method), $args); } } ?>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.
