/** * Store data at the server * * CacheRedis::put() stores an item $buff with $key on the Redis server. * Parameter $valid_time is expiration time in seconds. If it's 0, the item never expires * (but Redis server doesn't guarantee this item to be stored all the time, it could be delete from the cache to make place for other items). * * Remember that resource variables (i.e. file and connection descriptors) cannot be stored in the cache, * because they can not be adequately represented in serialized state. * * @param string $key The key that will be associated with the item. * @param mixed $buff The variable to store. Strings and integers are stored as is, other types are stored serialized. * @param int $valid_time Expiration time of the item. * You can also use Unix timestamp or a number of seconds starting from current time, but in the latter case the number of seconds may not exceed 2592000 (30 days). * If it's equal to zero, use the default valid time CacheRedis::valid_time. * @return bool Returns true on success or false on failure. */ function put($key, $buff, $valid_time = 0) { if ($valid_time > 60 * 60 * 24 * 30) { $valid_time = $valid_time - time(); } if ($valid_time <= 0) { $valid_time = $this->valid_time; } try { return $this->redis->setex($this->getKey($key), $valid_time, serialize(array($_SERVER['REQUEST_TIME'], $buff))); } catch (RedisException $e) { return $this->status = false; } }