dongcoder7
dongcoder7

Reputation: 21

redis how to expire a key in different hash

Now,I have a redis conn named r, and two hash table named: hash1, hash2. Then

r.hset(hash1, id, value1)
r.hset(hash2, id, value2)

r.expire(id, ttl)

is that valid use? or it's error?

Upvotes: 1

Views: 775

Answers (1)

Hichem BOUSSETTA
Hichem BOUSSETTA

Reputation: 1857

Expire function is not available on hash fields. In the official documentation (picture below) you can find the functions that apply for a hash key.

There exist topics discussion the absence of the expire functionality within a hash. Take a look at this one for example: https://github.com/antirez/redis/issues/3192

You can however manage the deletion yourself using HDEL or some cron task if you have a deletion timeout for all keys. I understand that this is not ideal indeed :-)

HASH API REDIS

Upvotes: 1

Related Questions