D:\Redis-x64-3.2.100>redis-cli.exe -h 127.0.0.1 -p 6379
127.0.0.1:6379> set aa "123"
(error) NOAUTH Authentication required.
127.0.0.1:6379> auth kingredis
OK
set 一个key 为bb ,value为"aa"的对象,设置expire为30s,接下来我们看看
127.0.0.1:6379> set bb "aa" ex 30
OK
127.0.0.1:6379> TTL bb
(integer) 25
127.0.0.1:6379> get bb
"aa"
127.0.0.1:6379> TTL bb
(integer) 14
127.0.0.1:6379> getbb
(error) ERR unknown command 'getbb'
127.0.0.1:6379> get bb
"aa"
127.0.0.1:6379> TTL bb
(integer) 5
127.0.0.1:6379> get bb
(nil)
说明到期了以后,redis会自动删除过期的key