亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 語言 > PHP > 正文

CI框架中redis緩存相關操作文件示例代碼

2024-05-04 23:46:18
字體:
來源:轉載
供稿:網友
這篇文章主要介紹了CI框架中redis緩存相關操作文件,結合完整示例演示了CI框架redis緩存相關操作技巧,需要的朋友可以參考下
 

本文實例講述了CI框架中redis緩存相關操作文件。分享給大家供大家參考,具體如下:

redis緩存類文件位置:

'ci/system/libraries/Cache/drivers/Cache_redis.php'

<?php/** * CodeIgniter * * An open source application development framework for PHP 5.2.4 or newer * * NOTICE OF LICENSE * * Licensed under the Open Software License version 3.0 * * This source file is subject to the Open Software License (OSL 3.0) that is * bundled with this package in the files license.txt / license.rst. It is * also available through the world wide web at this URL: * http://opensource.org/licenses/OSL-3.0 * If you did not receive a copy of the license and are unable to obtain it * through the world wide web, please send an email to * licensing@ellislab.com so we can send you a copy immediately. * * @package   CodeIgniter * @author   EllisLab Dev Team * @copyright  Copyright (c) 2008 - 2014, EllisLab, Inc. (http://ellislab.com/) * @license   http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link    http://codeigniter.com * @since    Version 3.0 * @filesource */defined('BASEPATH') OR exit('No direct script access allowed');/** * CodeIgniter Redis Caching Class * * @package  CodeIgniter * @subpackage Libraries * @category  Core * @author   Anton Lindqvist <anton@qvister.se> * @link */class CI_Cache_redis extends CI_Driver{  /**   * Default config   *   * @static   * @var array   */  protected static $_default_config = array(    /*    'socket_type' => 'tcp',    'host' => '127.0.0.1',    'password' => NULL,    'port' => 6379,    'timeout' => 0    */  );  /**   * Redis connection   *   * @var Redis   */  protected $_redis;  /**   * Get cache   *   * @param  string like *$key*   * @return array(hash)   */  public function keys($key)  {    return $this->_redis->keys($key);  }  /**   * Get cache   *   * @param  string Cache ID   * @return mixed   */  public function get($key)  {    return $this->_redis->get($key);  }  /**   * mGet cache   *   * @param  array  Cache ID Array   * @return mixed   */  public function mget($keys)  {    return $this->_redis->mget($keys);  }  /**   * Save cache   *   * @param  string $id Cache ID   * @param  mixed  $data  Data to save   * @param  int $ttl  Time to live in seconds   * @param  bool  $raw  Whether to store the raw value (unused)   * @return bool  TRUE on success, FALSE on failure   */  public function save($id, $data, $ttl = 60, $raw = FALSE)  {    return ($ttl)      ? $this->_redis->setex($id, $ttl, $data)      : $this->_redis->set($id, $data);  }  /**   * Delete from cache   *   * @param  string Cache key   * @return bool   */  public function delete($key)  {    return ($this->_redis->delete($key) === 1);  }  /**   * hIncrBy a raw value   *   * @param  string $id Cache ID   * @param  string $field Cache ID   * @param  int $offset Step/value to add   * @return mixed  New value on success or FALSE on failure   */  public function hincrby($key, $field, $value = 1)  {    return $this->_redis->hIncrBy($key, $field, $value);  }  /**   * hIncrByFloat a raw value   *   * @param  string $id Cache ID   * @param  string $field Cache ID   * @param  int $offset Step/value to add   * @return mixed  New value on success or FALSE on failure   */  public function hincrbyfloat($key, $field, $value = 1)  {    return $this->_redis->hIncrByFloat($key, $field, $value);  }  /**   * lpush a raw value   *   * @param  string $key  Cache ID   * @param  string $value value   * @return mixed  New value on success or FALSE on failure   */  public function lpush($key, $value)  {    return $this->_redis->lPush($key, $value);  }   /**   * rpush a raw value   *   * @param  string $key  Cache ID   * @param  string $value value   * @return mixed  New value on success or FALSE on failure   */  public function rpush($key, $value)  {    return $this->_redis->rPush($key, $value);  }  /**   * rpop a raw value   *   * @param  string $key  Cache ID   * @param  string $value value   * @return mixed  New value on success or FALSE on failure   */  public function rpop($key)  {    return $this->_redis->rPop($key);  }   /**   * brpop a raw value   *   * @param  string $key  Cache ID   * @param  string $ontime 阻塞等待時間   * @return mixed  New value on success or FALSE on failure   */  public function brpop($key,$ontime=0)  {    return $this->_redis->brPop($key,$ontime);  }  /**   * lLen a raw value   *   * @param  string $key  Cache ID   * @return mixed  Value on success or FALSE on failure   */  public function llen($key)  {    return $this->_redis->lLen($key);  }  /**   * Increment a raw value   *   * @param  string $id Cache ID   * @param  int $offset Step/value to add   * @return mixed  New value on success or FALSE on failure   */  public function increment($id, $offset = 1)  {    return $this->_redis->exists($id)      ? $this->_redis->incr($id, $offset)      : FALSE;  }  /**   * incrby a raw value   *   * @param  string $key Cache ID   * @param  int $offset Step/value to add   * @return mixed  New value on success or FALSE on failure   */  public function incrby($key, $value = 1)  {    return $this->_redis->incrby($key, $value);  }  /**   * set a value expire time   *   * @param  string $key Cache ID   * @param  int $seconds expire seconds   * @return mixed  New value on success or FALSE on failure   */  public function expire($key, $seconds)  {    return $this->_redis->expire($key, $seconds);  }  /**   * Increment a raw value   *   * @param  string $id Cache ID   * @param  int $offset Step/value to add   * @return mixed  New value on success or FALSE on failure   */  public function hset($alias,$key, $value)  {    return $this->_redis->hset($alias,$key, $value);  }  /**   * Increment a raw value   *   * @param  string $id Cache ID   * @param  int $offset Step/value to add   * @return mixed  New value on success or FALSE on failure   */  public function hget($alias,$key)  {    return $this->_redis->hget($alias,$key);  }  /**   * Increment a raw value   *   * @param  string $id Cache ID   * @return mixed  New value on success or FALSE on failure   */  public function hkeys($alias)  {    return $this->_redis->hkeys($alias);  }  /**   * Increment a raw value   *   * @param  string $id Cache ID   * @param  int $offset Step/value to add   * @return mixed  New value on success or FALSE on failure   */  public function hgetall($alias)  {    return $this->_redis->hgetall($alias);  }  /**   * Increment a raw value   *   * @param  string $id Cache ID   * @param  int $offset Step/value to add   * @return mixed  New value on success or FALSE on failure   */  public function hmget($alias,$key)  {    return $this->_redis->hmget($alias,$key);  }  /**   * del a key value   *   * @param  string $id Cache ID   * @param  int $offset Step/value to add   * @return mixed  New value on success or FALSE on failure   */  public function hdel($alias,$key)  {    return $this->_redis->hdel($alias,$key);  }  /**   * del a key value   *   * @param  string $id Cache ID   * @return mixed  New value on success or FALSE on failure   */  public function hvals($alias)  {    return $this->_redis->hvals($alias);  }  /**   * Increment a raw value   *   * @param  string $id Cache ID   * @param  int $offset Step/value to add   * @return mixed  New value on success or FALSE on failure   */  public function hmset($alias,$array)  {    return $this->_redis->hmset($alias,$array);  }  /**   * Decrement a raw value   *   * @param  string $id Cache ID   * @param  int $offset Step/value to reduce by   * @return mixed  New value on success or FALSE on failure   */  public function decrement($id, $offset = 1)  {    return $this->_redis->exists($id)      ? $this->_redis->decr($id, $offset)      : FALSE;  }  /**   * Clean cache   *   * @return bool   * @see   Redis::flushDB()   */  public function clean()  {    return $this->_redis->flushDB();  }  /**   * Get cache driver info   *   * @param  string Not supported in Redis.   *     Only included in order to offer a   *     consistent cache API.   * @return array   * @see   Redis::info()   */  public function cache_info($type = NULL)  {    return $this->_redis->info();  }  /**   * Get cache metadata   *   * @param  string Cache key   * @return array   */  public function get_metadata($key)  {    $value = $this->get($key);    if ($value)    {      return array(        'expire' => time() + $this->_redis->ttl($key),        'data' => $value      );    }    return FALSE;  }  /**   * Check if Redis driver is supported   *   * @return bool   */  public function is_supported()  {    if (extension_loaded('redis'))    {      return $this->_setup_redis();    }    else    {      log_message('debug', 'The Redis extension must be loaded to use Redis cache.');      return FALSE;    }  }  /**   * Setup Redis config and connection   *   * Loads Redis config file if present. Will halt execution   * if a Redis connection can't be established.   *   * @return bool   * @see   Redis::connect()   */  protected function _setup_redis()  {    $config = array();    $CI =& get_instance();    if ($CI->config->load('redis', TRUE, TRUE))    {      $config += $CI->config->item('redis');    }    $config = array_merge(self::$_default_config, $config);    $config = !empty($config['redis'])?$config['redis']:$config;    $this->_redis = new Redis();    try    {      if ($config['socket_type'] === 'unix')      {        $success = $this->_redis->connect($config['socket']);      }      else // tcp socket      {        $success = $this->_redis->connect($config['host'], $config['port'], $config['timeout']);      }      if ( ! $success)      {        log_message('debug', 'Cache: Redis connection refused. Check the config.');        return FALSE;      }    }    catch (RedisException $e)    {      log_message('debug', 'Cache: Redis connection refused ('.$e->getMessage().')');      return FALSE;    }    if (isset($config['password']))    {      $this->_redis->auth($config['password']);    }    return TRUE;  }  /**   * Class destructor   *   * Closes the connection to Redis if present.   *   * @return void   */  public function __destruct()  {    if ($this->_redis)    {      $this->_redis->close();    }  }}/* End of file Cache_redis.php *//* Location: ./system/libraries/Cache/drivers/Cache_redis.php */
 


注:相關教程知識閱讀請移步到PHP教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
亚洲欧洲在线观看| 国产成人精品视频在线| 亚洲国产精久久久久久| 亚洲大尺度美女在线| 日韩一区在线视频| 中文字幕欧美国内| 久久亚洲综合国产精品99麻豆精品福利| 成人久久精品视频| 欧美性猛交xxxx乱大交| 精品视频在线播放免| 久久99青青精品免费观看| 国产成人中文字幕| 欧美最猛性xxxxx免费| www.xxxx精品| 97在线视频免费播放| 欧美福利视频网站| 亚洲国产欧美一区| 美女福利视频一区| 国产精品成人va在线观看| 一区二区三区回区在观看免费视频| 久久av在线看| 久久综合电影一区| 国产成人精彩在线视频九色| 久久天天躁狠狠躁夜夜躁2014| 欧美一乱一性一交一视频| 91精品国产91久久久久久吃药| 国产精品男人爽免费视频1| 日韩在线激情视频| 国产a级全部精品| 成人午夜在线视频一区| 国内精品400部情侣激情| 欧美中文在线观看| 亚洲色图国产精品| 91久久精品国产91性色| 久久夜色撩人精品| 国产精品久久久久久久久久久不卡| 日韩va亚洲va欧洲va国产| 亚洲女人被黑人巨大进入| 国产丝袜一区二区三区免费视频| 欧美性猛交99久久久久99按摩| 欧美大片欧美激情性色a∨久久| 日韩视频欧美视频| 精品久久久久久久大神国产| 成人黄色片在线| 国产精品日日做人人爱| 九九久久久久99精品| 国产精品极品尤物在线观看| 欧美乱大交做爰xxxⅹ性3| 美女av一区二区| 国产精品毛片a∨一区二区三区|国| 国产精品精品国产| 欧美性做爰毛片| 国产精品揄拍500视频| 亚洲国内精品在线| 日日骚av一区| 欧美黑人又粗大| 久久国产精品久久精品| 国产在线观看一区二区三区| 欧美影院在线播放| 欧美一区三区三区高中清蜜桃| 午夜精品一区二区三区视频免费看| 国产精品免费视频xxxx| 成人免费在线视频网站| 久久国产精品99国产精| 国产精品久久久久久久9999| 欧洲成人免费aa| 成人免费视频a| 亚洲第一天堂无码专区| 亲子乱一区二区三区电影| 日韩中文字幕亚洲| 欧美性xxxxxx| 国产丝袜高跟一区| 日本免费久久高清视频| 久久精品99久久久久久久久| 国产精品欧美日韩| 91国产视频在线| 狠狠色狠狠色综合日日小说| 91精品视频免费看| 色偷偷亚洲男人天堂| 庆余年2免费日韩剧观看大牛| 色综合视频一区中文字幕| 亚洲区一区二区| 久久久久久国产| 91精品国产高清自在线| 久久久久久久久久国产精品| 在线成人一区二区| 日韩av电影手机在线观看| 国产精品久久久久久av福利软件| 欧美日韩成人精品| 亚洲成人网在线| 日韩av免费在线看| 色多多国产成人永久免费网站| 亚洲精品乱码久久久久久按摩观| 日韩av中文字幕在线| 久久资源免费视频| 日韩在线视频观看正片免费网站| 久久久精品网站| 国产欧美欧洲在线观看| 丝袜情趣国产精品| 欧美精品18videosex性欧美| 性色av一区二区三区免费| 69av视频在线播放| 少妇久久久久久| 91在线观看免费观看| 97色在线视频| 在线视频欧美性高潮| 亚洲iv一区二区三区| 亚洲mm色国产网站| 日韩精品免费视频| 国产精品久久久久久久久男| 中文日韩在线视频| 国产精品久久久久久久久久久久久久| 久久激情视频久久| 在线观看国产成人av片| 色婷婷综合久久久久中文字幕1| 成人国内精品久久久久一区| 粉嫩av一区二区三区免费野| 国产不卡视频在线| 精品调教chinesegay| 国模吧一区二区三区| 亚洲欧美日韩精品| 亚洲一二三在线| 亚洲国产精品va在线看黑人动漫| 在线视频中文亚洲| 日韩成人免费视频| 国产午夜精品视频| 日本精品一区二区三区在线播放视频| 欧美国产日韩二区| 国产精品视频免费在线观看| 日韩精品有码在线观看| 欧美在线视频a| 91精品国产91久久久久久久久| 国产精品网站大全| 俺去了亚洲欧美日韩| 国产亚洲激情在线| 97av在线视频免费播放| 综合激情国产一区| 欧美自拍视频在线观看| 亚洲日本中文字幕免费在线不卡| 国内免费久久久久久久久久久| 国产99久久精品一区二区 夜夜躁日日躁| 精品成人av一区| 久久久久成人网| 精品亚洲国产视频| 久久亚洲成人精品| 色99之美女主播在线视频| 91久久嫩草影院一区二区| 国产极品jizzhd欧美| 在线精品视频视频中文字幕| 国产精品第一视频| 91精品国产综合久久香蕉的用户体验| 欧美精品在线观看| zzijzzij亚洲日本成熟少妇| 5566日本婷婷色中文字幕97| 亚洲国内高清视频| 亚洲天堂av图片| 久久久久久国产精品三级玉女聊斋| 狠狠色狠狠色综合日日五| 亚洲激情视频在线| 黄色成人在线播放| 欧美黑人又粗大| 久久久久久久久网站| 国产在线不卡精品| 亚洲国产成人精品电影|