1. 在autoload.php 中加入 如下配置行
$autoload['libraries'] = array('redis');
2. 在/application/config 中加入文件 redis.php
文件内容如下:
<?php
// Default connection group
$config['redis_default']['host'] = 'localhost'; // IP address or host
$config['redis_default']['port'] = '6379'; // Default Redis port is 6379
$config['redis_default']['password'] = ''; // Can be left empty when the server does not require AUTH
$config['redis_slave']['host'] = '';
$config['redis_slave']['port'] = '6379';
$config['redis_slave']['password'] = '';
?>
3. 在 /application/libraries 中加入文件 Redis.php
文件来源: redis库文件包
文件内容:
<?php defined('BASEPATH') OR exit('No direct script access allowed');
/**
* CodeIgniter Redis
*
* A CodeIgniter library to interact with Redis
*
* @package CodeIgniter
* @category Libraries
* @author Joël Cox
* @version v0.4
* @link https://github.com/joelcox/codeigniter-redis
* @link http://joelcox.nl
* @license http://www.opensource.org/licenses/mit-license.html
*/
class CI_Redis {
/**
* CI
*
* CodeIgniter instance
* @var object
*/
private $_ci;
/**
* Connection
*
* Socket handle to the Redis server
* @var handle
*/
private $_connection;
/**
* Debug
*
* Whether we're in debug mode
* @var bool
*/
public $debug = FALSE;
/**
* CRLF
*
* User to delimiter arguments in the Redis unified request protocol
* @var string
*/
const CRLF = "\r\n";
/**
* Constructor
*/
public function __construct($params = array())
{
log_message('debug', 'Redis Class Initialized');
$this->_ci = get_instance();
$this->_ci->load->config('redis');
// Check for the different styles of configs
if (isset($params['connection_group']))
{
// Specific connection group
$config = $this->_ci->config->item('redis_' . $params['connection_group']);
}
elseif (is_array($this->_ci->config->item('redis_default')))
{
// Default connection group
$config = $this->_ci->config->item('redis_default');
}
else
{
// Original config style
$config = array(
'host' => $this->_ci->config->item