This article is the first part of the Chinese documentation of php-redis. It mainly introduces the usage skills of some commands officially provided by redis. Friends in need can refer to it.
This article is the first part of the Chinese documentation of php-redis. It mainly introduces the usage skills of some commands officially provided by redis. Friends in need can refer to it. As an extension of PHP, phpredis is very efficient and has a linked list sorting function, which is very useful for creating memory-level module business relationships; Download address: https://github.com/owlient/phpredis (supports redis 2.0.4) The following are the command usage tips officially provided by redis: Redis::__construct constructor $redis = new Redis(); connect, open link redis service parameter host: string, service address port: int, port number timeout: float, link duration (optional, default is 0, no limit to link time) Note: There is also time in redis.conf, the default is 300 pconnect, popen will not actively close the link Refer to above setOption sets redis mode getOption View the mode set by redis ping to check connection status get gets the value of a certain key (string value) If the key does not exist, return false set writes key and value (string value) If the write is successful, return true setex write value with time to live $redis->setex('key', 3600, 'value'); // sets key → value, with 1h TTL. setnx determines whether it is repeated and writes the value $redis->setnx('key', 'value'); $redis->setnx('key', 'value'); delete deletes the value of the specified key Returns the number of deleted keys (long integer) $redis->delete('key1', 'key2'); $redis->delete(array('key3', 'key4', 'key5')); ttl Get the survival time of a key persist Remove keys whose lifetime has expired true if the key expires, false if it does not expire |