Home > Back-end >  Redis how to judge whether a key is expired key or non-existent () this is an interview question
Redis how to judge whether a key is expired key or non-existent () this is an interview question

Time:11-24

How to determine the key redis is out of date, or does not exist,

Two cases: 1, a key is expired, 2, and this key doesn't exist,

In redis, how to distinguish, tried exsits key, and expiration, and there is no return 0, tried to TTL key, and expiration, and there is no return - 2,,

Cannot distinguish, and don't know whether the interviewer was a strange flower, is really can distinguish between,

CodePudding user response:

Come on, and bosses

CodePudding user response:

This is... To save a database

CodePudding user response:

Judgment is expired or does not exist, it would need to get to the redis operation log, to compare,
Redis monitor real-time command can view the operation logs redis, but this order is for debugging, which is used for operations to use,
If as a record, it is need persistence, then to compare, separate by a command or something to see the key is expired, or does not exist, this is impossible,

So I feel this is a problem as an application to test you, you can do it: the key expired when trigger keyExpireListen/overdue event listeners, then put the key in the form of the set or Hash return to redis, there is no judgment or expired, the operation of the first to set or check whether the key is in the Hash, is ok,
  • Related