The problem/use-case that the feature addresses

I use Redis as a place to store objects in a web application. These objects belong to a class. I access them via some ORM Library I developed in Ruby. I need these objects to have some TTL time. I store the keys of a class objects inside a set. And I store the info of each object, each in its own Key/Value For example, a Redis DB can look like this

[SET] 'users' => ['user:1', 'user:2', 'user:3']
[STRING] 'user:1' => '{ JSON REPRESENTATION OF user1 }'
[STRING] 'user:2' => '{ JSON REPRESENTATION OF user2 }'
[STRING] 'user:3' => '{ JSON REPRESENTATION OF user3 }'

A description of the problem that the feature will solve, or the use-case with which the feature will be used.

Description of the feature

By adding this feature, I can easily expire both the object info (already available), and the Object Membership inside the set.

It can be done using a command like

smemberexpire users user1

Alternatives you've considered

My alternative solution is that, each time I see the object inside the set, I check for its key if it exists, or already expired.

Additional information

If this feature is welcome, I would be happy to implement it and make a PR for it myself.

Comment From: yossigo

@OmarQunsul I'm currently contemplating with ideas to solve similar problems. So far the idea is to make it possible to provide configuration that will trigger automatic SREM users <key> when <key> is deleted/expired, if <key> matches some pattern (e.g. user:*).

Comment From: itamarhaber

Hi @OmarQunsul!!! Long time - thanks for the feedback :)

Comment From: OmarQunsul

Hey @itamarhaber . Indeed. I hope you are doing well. I came across your PR https://github.com/redis/redis/pull/8179 that you merged recently. Cool stuff :clap:

Comment From: sgtcortez

How is this issue? Is this being implemented? I have a similar problem here. I needed a sort of relationships between keys on my redis database.
So, I found this blog post about full text search which, works like a charm ...

So, when I add a key to the database, I split it into parts and store the parts in a set.
Example:

SET USER_ID=10|COUNTRY=20| '{"user": {"name": "Matheus", "salary": 1899}, "country": {"name": "Brazil}}' 
SADD USER_ID=10| USER_ID=10|COUNTRY=20| 
SADD COUNTRY=20| USER_ID=10|COUNTRY=20| 

Sometimes, I do not use ttls, so, all the keys/members are deleted/overwrite manually
So, I do execute:

SREM USER_ID=10| USER_ID=10|COUNTRY=20|
SREM COUNTRY=20| USER_ID=10|COUNTRY=20| 
DEL USER_ID=10|COUNTRY=20|

But, the problem is when, I have some keys with ttl .
So, I would have something like:

SET USER_ID=10|COUNTRY=20| '{"user": {"name": "Matheus", "salary": 1899}, "country": {"name": "Brazil}}'  EX 3600
SADD USER_ID=10| USER_ID=10|COUNTRY=20| 
SADD COUNTRY=20| USER_ID=10|COUNTRY=20| 

But, I can not set the ttl to a member of the set. So, in the worst case, I could have some trash.
One thing that I can do to bypass this, is to use the Publish & Subscriber, which works. But, its harder to do, and, I do not think that clients must implement this to get this behavior, cause, this is too much error prone ...

Whats my idea: To add ttl to set members. Something that I do know, is that, if it is not implemented, it must affect server performance, or be a bit too hard. So, I am just thinking as a naive redis user.

SET USER_ID=10|COUNTRY=20| '{"user": {"name": "Matheus", "salary": 1899}, "country": {"name": "Brazil}}'  EX 3600
SADD USER_ID=10| USER_ID=10|COUNTRY=20|  EX 3600
SADD COUNTRY=20| USER_ID=10|COUNTRY=20|  EX 3600

@itamarhaber does it make sense for you? I might try to implement it on my spare time, and then, show you my solution

Thanks in advance!