redis服务器搭建及CI中的使用方法

来源:互联网 发布:python开发入门详解 编辑:程序博客网 时间:2024/06/08 00:45

 参见:http://www.phpnotes.top/2017/11/24/php/codeigniter/46/


redis服务器搭建及CI中的使用方法

 

 

1、首先安装redis服务器,将文件夹下内容解压到相应目录

2、进入解压后的目录,输入redis-server.exe redis.conf开启redis服务器。密码在redis.conf中进行配置,打开redis.conf,找到requirepass 可配置密码

出现以下标识说明开启成功

3、命令行格式连接redis服务器查看是否连接成功。进入刚解压后的目录,输入

Redis-cli.php –p 6379 –a HykRedis,进入后随意测试命令,查看是否成功

4、php需要使用redis,需要安装phpredis扩展,在php.ini中加上或修改

extension=php_igbinary.dll

extension=php_redis.dll

将以下四个文件复制到php安装文件夹下的ext文件夹下,重启服务器。

 

5、CI配置redis缓存配置,在config文件夹下增加一个redis.conf文件,内容:

<?php

 

if (!defined('BASEPATH'))  exit('No direct script access allowed');

$config['host'] = '127.0.0.1';  // IP address or host

$config['port'] = '6379';   // Default Redis port is 6379

$config['password'] = 'youpassword';   // Can be left empty when the server does not require AUTH

 

6、在CI中进行使用,在相关控制器下引入缓存驱动,$this->load->driver(‘cache’);

 

7、实际用法,可参考手册

http://codeigniter.org.cn/user_guide/libraries/caching.html?highlight=redis#redis

手册中缓存的用法,皆可使用,例如

$this->cache->redis->save(‘csc’,’test’,100);

$this->cache->redis->get(‘csc’);

 

8、不使用CI的缓存驱动器,也可直接使用phpredis类,phpredis类相关操作方法可参考php-redis中文文档(部分方法注释有问题)

http://www.cnblogs.com/weafer/archive/2011/09/21/2184059.html

 

9、redis的命令行命令可参考http://doc.redisfans.com/

 

建议使用CI封装的缓存类方法

阅读全文
0 0
原创粉丝点击