PHP Redis species

Source: Internet
Author: User
Tags php redis
PHP Redis Class
/********************************************************************************* * InitPHP 2.0 domestic PHP development Framework Dao-nosql-redis *-------------------------------------------* All rights reserved: Copyright by initphp.com * You are free to use the source code, but in the course of use, Please keep the author information. Respect for the fruits of others ' work is to respect yourself *-------------------------------------------* $Author: Zhuli * $Dtime: 2011-10-09 ******************** /class Redisinit {private $redis;//redis Object/** * Initialize Redis * $config = Array (* ' server ' + ' 127.0.0.1 ' servers * ' port ' = ' 6379 ' Port number *) * @param array $config */pu Blic function init ($config = Array ()) {if ($config [' server '] = = ') $config [' server '] = ' 127.0.0.1 '; if ($config [' port '] = = ') $config [' port '] = ' 6379 '; $this->redis = new Redis (); $this->redis->connect ($config [' Server '], $config [' Port ']); return $this->redis;} /** * Set Value * @param string $key Key name * @param string|array $value Get data * @param int $timeOut time */public function set ($ Key, $value, $timeOut =0) {$value = Json_encode ($value, TRUE), $retRes = $this->redis->set ($key, $value), if ($timeOut > 0) $this->red Is->settimeout ($key, $timeOut); return $retRes;} /** * Gets data through key * @param string $key Key name */public function Get ($key) {$result = $this->redis->get ($key); return JSO N_decode ($result, TRUE);} /** * Delete a piece of data * @param string $key Key name */public function Delete ($key) {return $this->redis->delete ($key);} /** * Empty data */public function Flushall () {return $this->redis->flushall ();} /** * data into queue * @param string $key Key name * @param string|array $value Get data * @param bool $right whether to start from the right into */public functio n Push ($key, $value, $right = True) {$value = Json_encode ($value); return $right? $this->redis->rpush ($key, $value) : $this->redis->lpush ($key, $value);} /** * Data Out queue * @param string $key Key name * @param bool $left whether to start data from the left */public function pop ($key, $left = True) {$val = $ Left? $this->redis->lpop ($key): $this->redis->rpop ($key); return JSOn_decode ($val);} /** * Data self-increment * @param string $key Key name */public function increment ($key) {return $this->redis->incr ($key);} /** * Data Auto minus * @param string $key Key name */public function Decrement ($key) {return $this->REDIS->DECR ($key);} /** * Key exists, there is a return ture * @param string $key Key name */public function exists ($key) {return $this->redis->exists ($key); }/** * Back to Redis objects * Redis has a lot of ways to do it, we just encapsulate a part * Take this object and you can call the Redis own method directly */public function Redis () {return $this->redis;}}
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.