Description:
When setting a key with a specific expire time, the value stored in MySQL does not match what was set.
Memcached appears to correctly expire the key, so the problem seems to be related to how MySQL stores this value.
How to repeat:
This assumes the Memcached plugin is already setup and working using the database memcached_test and the table memstash.
CREATE DATABASE `memcached_test`;
CREATE TABLE `memstash` (
`k` varchar(255) NOT NULL,
`v` longtext,
`flags` int(11) DEFAULT NULL,
`cas_column` bigint(20) unsigned DEFAULT NULL,
`expires` bigint(20) unsigned DEFAULT NULL,
PRIMARY KEY (`k`),
KEY `v` (`v`(255))
);
Create a test key, add it via Memcached, execute date +'%s', query MySQL for the expire time of the added key and compare the time difference :
# echo "Y" > testkey
# memcp --verbose --debug --servers=localhost --expire=120 ; date +'%s'
op: set
source file: testkey
length: 1
key: testkey
flags: 0
expires: 288
1387226603
# mysql memcached_test -e "SELECT expires FROM memstash WHERE k = 'testkey'"
+------------+
| expires |
+------------+
| 1387226891 |
+------------+
The erroneous expire time is more evident when used with a unix timestamp.
# memcp --verbose --debug --servers=localhost --expire=1390671296 testkey ; date +'%s'
op: set
source file: testkey
length: 1
key: testkey
flags: 0
expires: 84027052694
1387226782
# mysql memcached_ttfb -e "SELECT expires FROM memstash WHERE k = 'testkey'"
+------------+
| expires |
+------------+
| 2422674070 |
+------------+
Suggested fix:
Have the saved value reflect the actual unix timestamp.