/** Stores data on the server; the key, value, and an expiration time are specified.
* The server will automatically delete the value when the expiration time has been reached.
* If the value is not a String or numeric type, or if {@link #set_serial(boolean) set_serial(true)}
* has been called; the data will be Serialized prior to storage.
*
* If compression is enabled, and the data is longer than the compression threshold,
* and compresses by at least the compression savings, the data will be stored in
* compressed form.
*
* @param key key to store data under
* @param value value to store
* @param expiry when to expire the record
* @return true, if the data was successfully stored
*/
public boolean set(String key, Object value, Date expiry) {
return set("set",key,value,expiry,null);
}
#define REALTIME_MAXDELTA 60*60*24*30
/*
* given time value that's either unix time or delta from current unix time, return
* unix time. Use the fact that delta can't exceed one month (and real time value can't
* be that low).
*/
static rel_time_t realtime(const time_t exptime) {
/* no. of seconds in 30 days - largest possible delta exptime */
if (exptime == 0) return 0; /* 0 means never expire */
if (exptime > REALTIME_MAXDELTA) {
/* if item expiration is at/before the server started, give it an
expiration time of 1 second after the server started.
(because 0 means don't expire). without this, we'd
underflow and wrap around to some large value way in the
future, effectively making items expiring in the past
really expiring never */
if (exptime <= process_started)
return (rel_time_t)1;
return (rel_time_t)(exptime - process_started);
} else {
return (rel_time_t)(exptime + current_time);
}
}