PHP Redis Action Class Personal summary

Source: Internet
Author: User
Tags php redis time 0
Class Myredis {private $redis; /** * @param string $host * @param int $post */Public function __construct ($host = ' 10.102.1.8 ', $port = 6        379) {$this->redis = new Redis ();        $this->redis->connect ($host, $port);    return $this->redis; }/** * Set value to build a String * @param string $key Key Name * @param string $value Set value * @param int $timeOut time 0        Indicates no expiration time */Public function set ($key, $value, $timeOut =0) {$retRes = $this->redis->set ($key, $value);        if ($timeOut > 0) $redis->expire (' $key ', $timeOut);    return $retRes; }/* * Build a collection (unordered collection) * @param string $key collection y name * @param string|array $value value */Public Function SA    DD ($key, $value) {return $this->redis->sadd ($key, $value);  }/* * Build a collection (ordered collection) * @param string $key collection name * @param string|array $value value */Public function Zadd ($key, $value) {return $this->rediS->zadd ($key, $value); }/** * Take collection corresponding element * @param string $setName set name */Public Function smembers ($setName) {return $    This->redis->smembers ($setName); }/** * Build a list (advanced to go, like stacks) * @param sting $key Key Name * @param string $value value */Public function Lpush ($key, $value)        {echo "$key-$value \ n";    return $this->redis->lpush ($key, $value); }/** * Build a list (advanced first go, like queue) * @param sting $key Key Name * @param string $value value */public functio        N Rpush ($key, $value) {echo "$key-$value \ n";    return $this->redis->rpush ($key, $value);     /** * Get all list data (from start to finish) * @param sting $key Key name * @param int $head begin * @param int $tail End    */Public Function lranges ($key, $head, $tail) {return $this->redis->lrange ($key, $head, $tail); }/** * Hash type * @param string $tableName table name key * @param string $key field name * @paRam Sting $value Value */Public Function Hset ($tableName, $field, $value) {return $this->REDIS->HS    ET ($tableName, $field, $value);    The Public Function Hget ($tableName, $field) {return $this->redis->hget ($tableName, $field); }/** * Set multiple values * @param array $keyArray key name * @param string|array $value Get the data * @param int $timeOut time */Public function sets ($keyArray, $timeout) {if (Is_array ($keyArray)) {$retRes = $            This->redis->mset ($keyArray); if ($timeout > 0) {foreach ($keyArray as $key = + $value) {$this->redis->ex                Pire ($key, $timeout);        }} return $retRes; } else {return ' call '. __function__.        "Method parameter Error!"; }}/** * gets data through key * @param string $key Key Name */Public function get ($key) {$result = $this- >redis->get ($key);    return $result; /** * Get multiple values simultaneously * @param ayyay $keyArray Key value */Public function gets ($keyArray) {if (Is_array ($keyArray))        {return $this->redis->mget ($keyArray); } else {return ' call '. __function__.        "Method parameter Error!";    }}/** * Gets all key names, not values */Public Function Keyall () {return $this->redis->keys (' * '); }/** * Delete a Data key * @param string $key Remove the name of key */Public Function del ($key) {return $this->r    Edis->delete ($key); }/** * Delete multiple key data simultaneously * @param array $keyArray Key collection */Public Function dels ($keyArray) {if (Is_ar        Ray ($keyArray)) {return $this->redis->del ($keyArray); } else {return ' call '. __function__.        "Method parameter Error!"; }}/** * Data self-increment * @param string $key Key Name */Public function increment ($key) {return $thiS->REDIS->INCR ($key); }/** * Data decrement * @param string $key Key Name */Public function decrement ($key) {return $this-&gt    ; REDIS->DECR ($key); }/** * Determines if key exists * @param string $key Key Name */Public Function isexists ($key) {return $th    Is->redis->exists ($key); }/** * Rename-when and only if Newkey does not exist, change the key to Newkey, when Newkey is present, it will be an error. Rename * is not the same as rename, it is a direct update (the existing value will be updated directly) * @par AM string $Key Key name * @param string $newKey new key Name */Public Function updatename ($key, $newKey) {return    $this->redis->renamenx ($key, $newKey); }/** * Gets the value type stored by key * None (key does not exist) int (0) string (string) int (1) list (list) int (3) set (set) int (2) zset (ordered set) in T (4) hash (hash table) int (5) * @param string $key Key Name */Public Function DataType ($key) {return $this->re    Dis->type ($key); }/** * Clear data */Public Function Flushall () {return $this->redis->flushall ();    /** * Return Redis Object * 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 * eg: $redis->redisoth    Ermethods ()->keys (' *a* ') The keys method is not sealed */Public Function redisothermethods () {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.