无为清净楼资源网 Design By www.qnjia.com
本文实例讲述了CI框架(CodeIgniter)操作redis的方法。分享给大家供大家参考,具体如下:
1. 在autoload.php 中加入 如下配置行
$autoload['libraries'] = array('redis');
2. 在/application/config 中加入文件 redis.php
文件内容如下:
<"_blank" href="https://github.com/joelcox/codeigniter-redis" rel="external nofollow" >redis库文件包文件内容:
<"\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('redis_host'), 'port' => $this->_ci->config->item('redis_port'), 'password' => $this->_ci->config->item('redis_password'), ); } // Connect to Redis $this->_connection = @fsockopen($config['host'], $config['port'], $errno, $errstr, 3); // Display an error message if connection failed if ( ! $this->_connection) { show_error('Could not connect to Redis at ' . $config['host'] . ':' . $config['port']); } // Authenticate when needed $this->_auth($config['password']); } /** * Call * * Catches all undefined methods * @param string method that was called * @param mixed arguments that were passed * @return mixed */ public function __call($method, $arguments) { $request = $this->_encode_request($method, $arguments); return $this->_write_request($request); } /** * Command * * Generic command function, just like redis-cli * @param string full command as a string * @return mixed */ public function command($string) { $slices = explode(' ', $string); $request = $this->_encode_request($slices[0], array_slice($slices, 1)); return $this->_write_request($request); } /** * Auth * * Runs the AUTH command when password is set * @param string password for the Redis server * @return void */ private function _auth($password = NULL) { // Authenticate when password is set if ( ! empty($password)) { // See if we authenticated successfully if ($this->command('AUTH ' . $password) !== 'OK') { show_error('Could not connect to Redis, invalid password'); } } } /** * Clear Socket * * Empty the socket buffer of theconnection so data does not bleed over * to the next message. * @return NULL */ public function _clear_socket() { // Read one character at a time fflush($this->_connection); return NULL; } /** * Write request * * Write the formatted request to the socket * @param string request to be written * @return mixed */ private function _write_request($request) { if ($this->debug === TRUE) { log_message('debug', 'Redis unified request: ' . $request); } // How long is the data we are sending"htmlcode"><"_blank" href="https://www.jb51.net/article/33887.htm">https://www.jb51.net/article/33887.htm需要注意的是:
(1)你的本地需要安装 redis服务(windows安装)
(2)并开启redis 服务
(3)不管是windows 还是linux 都需要装 php对应版本的 redis扩展更多关于CodeIgniter相关内容感兴趣的读者可查看本站专题:《codeigniter入门教程》、《CI(CodeIgniter)框架进阶教程》、《php优秀开发框架总结》、《ThinkPHP入门教程》、《ThinkPHP常用方法总结》、《Zend FrameWork框架入门教程》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》
希望本文所述对大家基于CodeIgniter框架的PHP程序设计有所帮助。
无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com
暂无评论...
更新日志
2024年09月25日
2024年09月25日
- 纯音入心系列纯音乐《天籁古筝》1CD[MP3][331MB]
- 男女对唱典藏天碟《发烧对唱·那个季节里的歌DSD》10CD[WAV]
- 群星2010-歌林精选辑[歌林][WAV+CUE]
- TrioZimbalist-PianoTriosofWeinberg,Auerbach,Dvorak(2024)[24-44,1]wav
- 群星.1992-滚石第一流台湾歌·12王牌大车拼【滚石】【WAV+CUE】
- 林子祥.1984-创作歌集【华纳】【WAV+CUE】
- 周汤豪.2010-周汤豪【华纳】【FLAC分轨】
- Mozart-TheStringQuintets-AmadeusQuartet,CecilAronowitz(2017)[24-44,1][WAV+CUE]
- JamesWilliamsDennisIrwin-Focus(2024,Red)[24-48]FLAC
- 藤泽麻衣《空みあげて》[WAV]
- 纯音入心系列纯音乐《中国古筝经典名曲》1CD[MP3][1.3GB]
- 纯音入心系列纯音乐《古筝新奏:岁月静好与筝语,细水流年与筝同》1CD[MP3][846.9MB]
- 670《脆弱敏感小女生》[320K/MP3][27.53MB]
- 曾琳.2011-好好爱我【南方】【WAV+CUE】
- 范晓萱.1995-RAIN【福茂】【WAV+CUE】