1.创建配置redis配置文件:application/config/redis.php
$config['socket_type'] = 'tcp'; //`tcp` or `unix` $config['host'] = '127.0.0.1'; $config['password'] = NULL; $config['port'] = 6379; $config['timeout'] = 0;
2.在控制器中即可使用
$this->load->driver('cache');
$aaa = $this->cache->redis->get('aaa');
$this->cache->redis->del('aaa');
$this->cache->redis->save('aaa','ceshi',10);
方法1:
public function redis(){
$this->load->driver('cache');
$aaa = $this->cache->redis->get('aaa');
$this->cache->redis->del('aaa');
$this->cache->redis->save('aaa','ceshi',10);
}
方法2(RedisDb.php一个第三方类库):
public function redis2(){
$this->load->library('RedisDb.php');
echo $this->redisdb->get('aaa');
echo $this->redisdb->delete('aaa');
}