亚洲最大看欧美片,亚洲图揄拍自拍另类图片,欧美精品v国产精品v呦,日本在线精品视频免费

  • 站長資訊網(wǎng)
    最全最豐富的資訊網(wǎng)站

    ThinkPHP5框架中Redis是如何使用和封裝?

    下面thinkphp框架教程欄目將給大家介紹ThinkPHP5.0中Redis是如何使用和封裝的,希望對需要的朋友有所幫助!

    Redis是一種常用的非關(guān)系型數(shù)據(jù)庫,主要用作數(shù)據(jù)緩存,數(shù)據(jù)保存形式為key-value,鍵值相互映射.它的數(shù)據(jù)存儲跟MySQL不同,它數(shù)據(jù)存儲在內(nèi)存之中,所以數(shù)據(jù)讀取相對而言很快,用來做高并發(fā)非常不錯(cuò).

    ThinkPhP5.0自帶了Redis擴(kuò)展,在使用之前先下載php_redis.dll 網(wǎng)址 http://windows.php.net/downloads/pecl/releases/redis/2.2.7/ ;根據(jù)自己windows操作系統(tǒng)選擇相應(yīng)的版本,我自己是系統(tǒng)64位,安裝的是VC2012 所以下載的是php_redis-2.2.7-5.6-ts-vc11-x64.zip

    下載好壓縮包之后,把里面的php_redis.dll 解壓到D:wampbinphpphp5.6.25ext (根據(jù)自己wamp所在的盤自己選擇),然后在php.ini里面添加extension=php_redis.dll,重新啟動apache就可以了;

    下面是我自己測試的代碼,可以使用,封裝的不多,可以根據(jù)自己的需求去動手封裝

    extend 是thinkPHP5.0的擴(kuò)展類庫目錄,可以自己去定義

    namespace My;  //目錄我放在thinkphp5.0/extend/My    class RedisPackage {     protected static $handler = null;     protected $options = [         'host' => '127.0.0.1',         'port' => 6379,         'password' => '',         'select' => 0,         'timeout' => 0,    //關(guān)閉時(shí)間 0:代表不關(guān)閉         'expire' => 0,         'persistent' => false,         'prefix' => '',     ];      public function __construct($options = [])     {         if (!extension_loaded('redis')) {   //判斷是否有擴(kuò)展(如果你的apache沒reids擴(kuò)展就會拋出這個(gè)異常)             throw new BadFunctionCallException('not support: redis');               }         if (!empty($options)) {             $this->options = array_merge($this->options, $options);         }         $func = $this->options['persistent'] ? 'pconnect' : 'connect';     //判斷是否長連接         self::$handler = new Redis;         self::$handler->$func($this->options['host'], $this->options['port'], $this->options['timeout']);          if ('' != $this->options['password']) {             self::$handler->auth($this->options['password']);         }          if (0 != $this->options['select']) {             self::$handler->select($this->options['select']);         }     }      /**      * 寫入緩存      * @param string $key 鍵名      * @param string $value 鍵值      * @param int $exprie 過期時(shí)間 0:永不過期      * @return bool      */     public static function set($key, $value, $exprie = 0)     {         if ($exprie == 0) {             $set = self::$handler->set($key, $value);         } else {             $set = self::$handler->setex($key, $exprie, $value);         }         return $set;     }      /**      * 讀取緩存      * @param string $key 鍵值      * @return mixed      */     public static function get($key)     {         $fun = is_array($key) ? 'Mget' : 'get';         return self::$handler->{$fun}($key);     }      /**      * 獲取值長度      * @param string $key      * @return int      */     public static function lLen($key)     {         return self::$handler->lLen($key);     }      /**      * 將一個(gè)或多個(gè)值插入到列表頭部      * @param $key      * @param $value      * @return int      */     public static function LPush($key, $value, $value2 = null, $valueN = null)     {         return self::$handler->lPush($key, $value, $value2, $valueN);     }      /**      * 移出并獲取列表的第一個(gè)元素      * @param string $key      * @return string      */     public static function lPop($key)     {         return self::$handler->lPop($key);     } }
    namespace appindexcontroller; use thinkController; use MyRedisPackage;  class Redis extends Controller {     function redis()     {         $redis=new RedisPackage();         $redis::set('dede','我就笑笑');         echo $redis::get('dede');     } }

    推薦學(xué)習(xí):《thinkphp視頻教程》

    贊(0)
    分享到: 更多 (0)
    網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號