Redis - get key values ​​that match a regular expression

I need to save for each key several values ​​with different TTL.

for example, for XXXX, the values ​​are val1 (expiration time: 10), val2 (expiration time: 20)

Option 1: My best practice might be: Use hash / sets with expiration of each member.

Unfortunately, Redis containers(lists, hashes, sets, and sorted sets) does not support expiration of each member, although this function has been requested many times in the past.

Option 2: So I had to do something like this:

SETEX XXXX: 0 10 val1

SETEX XXXX: 1 20 val2

Now I want to get all the values ​​that have not expired, and their key starts with XXXX.

So, I tried this:

127.0.0.1:6379> keys XXXX:*
1) "XXXX:0"
2) "XXXX:1"

But I want to get the values, not the keys!

3:. , :

SETEX XXXX:val1 10 val1
SETEX XXXX:val2 20 val2

127.0.0.1:6379> keys XXXX:*
1) "XXXX:val1"
2) "XXXX:val2"

. :...

, 1 ( ) , , 2, ?

+4
2

, , , , .

, XXXX - , , , .

ZADD XXXX [current-timestamp + 10] val1
ZADD XXXX [current-timestamp + 20] val2

:

ZREVRANGEBYSCORE XXXX +inf [current-timestamp]

:

ZREMRANGEBYSCORE XXXX -inf [current-timestamp]
+1

1 , .

3 - , .

2, , SCAN KEYS . GET, .

(, 4) / SORT...GET . , , ( /, ) # 2.

0

All Articles