Class Myredis {private $ Redis; /** * @param string $host * @param int $post */Public function __construct ($host = ' xxxx ', $port = 6379) {$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 func tion 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 set y name * @param string|array $value value */Public Function Sadd ($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 Function 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->hset ($tableName, $field, $value); 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 funct Ion Sets ($keyArray, $timeout) {if (Is_array ($keyArray)) {$retRes = $this Redis->mset ($keyArray); if ($timeout > 0) {foreach ($keyArray as $key = + $value) {$this Redis->expire ($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 $th Is-> 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 Redis->delete ($key); }/** * Delete multiple key data simultaneously * @param array $keyArray Key collection */Public Function dels ($keyArray) {if (Is_array ($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- Redis->DECR ($key); }/** * Determine if key exists * @param string $key Key Name */Public Function isexists ($key) {return $this 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 also be updated directly) * @param string $Key Key name Called * @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) int (4) hash (hash table) int (5) * @param string $key Key Name */Public Function DataType ($key) {return $this Redis->type ($key); }/** * Clear data */Public Function Flushall () {return $this Redis->flushall (); }/** * return RedisObject RedisThere are a lot of ways to operate, we only PackageA part * Take this object and you can call it directly RedisOwn method * eg:$ Redis->redisothermethods ()->keys (' *a* ') The keys method is not sealed */Public Function redisothermethods () {return $this Redis; }}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The above describes the Redis PHP package, including the aspects of the content, I hope the PHP tutorial interested in a friend helpful.