ioredis icon indicating copy to clipboard operation
ioredis copied to clipboard

Feature Request: Add HEXPIRE Command

Open dwprz opened this issue 1 year ago • 12 comments

I would like to request the addition of a HEXPIPRE command to the ioredis library. The HEXPIPRE command would allow users to set an expiration time on individual fields within a hash, similar to how the EXPIRE command sets an expiration time on keys. This feature would be particularly useful for scenarios where certain fields within a hash need to expire independently of the hash itself.

Consider an order management system where each user's orders are stored as a hash with multiple fields representing different orders. Each order needs to have its own expiration time to ensure that old or unfulfilled orders are automatically removed after a certain period. The HEXPIPRE command would allow us to set an expiration time on each order field without affecting other orders or the main hash.

dwprz avatar Jun 20 '24 07:06 dwprz

+1

eephrati avatar Sep 12 '24 23:09 eephrati

@dwprz @eephrati I just submitted a PR for this, but the Redis team will need to integrate it and send out new releases.

mlb5000 avatar Sep 20 '24 12:09 mlb5000

@mlb5000 Thanks! If anyone needs a temp solution until this PR get merged, you can do:

redisClient.call("HEXPIRE", redisKey, 10, "FIELDS", 1, "field_name");

this will expire the "field_name" in redisKey hash in 10 seconds.

eephrati avatar Sep 20 '24 22:09 eephrati

Ha @eephrati I hadn't even considered using the generic call function. Good call!

mlb5000 avatar Sep 20 '24 23:09 mlb5000

for those who came looking for a native hexpire method. here's the redis docs to help with the workaround

dallenbaldwin avatar Nov 25 '24 16:11 dallenbaldwin

HEXPIRE is supported by Redis 7.4+ and supported by the node-redis client library. https://github.com/redis/node-redis/blob/master/packages/client/lib/commands/HEXPIRE.ts

mortensi avatar Nov 25 '24 16:11 mortensi

Is there any update yet on this feature request? Has it been added to the ioredis library

adisco4420 avatar Mar 03 '25 16:03 adisco4420

@adisco4420 as of today, it has still not been merged :/ I was looking for it too, but will use the temporary fix provided by @eephrati.

williamwinkler avatar Apr 28 '25 11:04 williamwinkler

+1

artyomSultanov avatar May 20 '25 10:05 artyomSultanov

+1

philr35 avatar May 22 '25 10:05 philr35

+1

PierreFlowdesk avatar May 22 '25 15:05 PierreFlowdesk

+1

Verbinmay avatar May 31 '25 15:05 Verbinmay

+2

isaackogan avatar Jun 22 '25 02:06 isaackogan

The latest version of ioredis (v5.7.0) has been released with support for the HEXPIRE command, with a contribution from @mlb5000.

PavelPashov avatar Jul 31 '25 10:07 PavelPashov

Hooray!!! Ty

isaackogan avatar Aug 10 '25 16:08 isaackogan

Are the types updated to support typescript? using await redis.hexpire(cacheKey, ttl, 'FIELDS', 1, fieldKey); results in Unsafe call of a(n) error type typed value.eslint@typescript-eslint/no-unsafe-call

webdo6263 avatar Aug 15 '25 04:08 webdo6263