Skip to content

do not delete expired keys in KEYS command#5470

Merged
antirez merged 1 commit intoredis:unstablefrom
soloestoy:keys-no-trigger-expire
Oct 24, 2018
Merged

do not delete expired keys in KEYS command#5470
antirez merged 1 commit intoredis:unstablefrom
soloestoy:keys-no-trigger-expire

Conversation

@soloestoy
Copy link
Contributor

No description provided.

@itamarhaber
Copy link
Member

@soloestoy I wonder why this.

Background: some users are actually relying on this - touching every key w/ KEYS or SCAN - to force expiry.

@soloestoy
Copy link
Contributor Author

Hi @itamarhaber , I know that people use KEYS or SCAN to force expire, but I think KEYS is not a good choice, it's already too complex and slow, and expire will make KEYS slower down, moreover we have to propagate expire to AOF and slave, that will make AOF buffer and SLAVE output buffer grow too fat.

@antirez
Copy link
Contributor

antirez commented Oct 24, 2018

Hello folks, I think that KEYS should remain like it is, showing the set of keys that exist. Not doing that would depart from the semantics from a product point of view, like:

EXPIRE foo 1
Wait 5 seconds
KEYS *
... foo ...

So I would not modify KEYS... However I've another solution for people that are in need of such capability. I'll follow up shortly.

@soloestoy
Copy link
Contributor Author

Hello folks, I think that KEYS should remain like it is, showing the set of keys that exist. Not doing that would depart from the semantics from a product point of view

Hi @antirez , I mean KEYS still remains its behavior, would not show the expired keys:

EXPIRE FOO 1
Wait 5 seconds
KEYS *
nil

KEYS only check TTL, but do not delete it...

@antirez
Copy link
Contributor

antirez commented Oct 24, 2018

Oh ok, that makes sense, and I like the refactoring going there in db.c, let me check the code better.

@antirez
Copy link
Contributor

antirez commented Oct 24, 2018

I'm merging @soloestoy, changing only one thing. Just an subjective hint, matter of taste, but see the following code:

    if (!keyIsExpired(db,key)) {
        return 0;
    } else if (server.masterhost != NULL) {
        /* If we are running in the context of a slave, return ASAP:
         * the slave key expiration is controlled by the master that will
         * send us synthesized DEL operations for expired keys.
         *
         * Still we try to return the right information to the caller,
         * that is, 0 if we think the key should be still valid, 1 if
         * we think the key is expired at this time. */
        return 1;
    }

It becomes much obvious once you remove the useless else/if

    if (!keyIsExpired(db,key)) return 0;
    
    if (server.masterhost != NULL) {
        /* If we are running in the context of a slave, return ASAP:
         * the slave key expiration is controlled by the master that will
         * send us synthesized DEL operations for expired keys.
         *
         * Still we try to return the right information to the caller,
         * that is, 0 if we think the key should be still valid, 1 if
         * we think the key is expired at this time. */
        return 1;
    }

@antirez antirez merged commit 3c89fb5 into redis:unstable Oct 24, 2018
antirez added a commit that referenced this pull request Oct 24, 2018
antirez added a commit that referenced this pull request Nov 5, 2018
JackieXie168 pushed a commit to JackieXie168/redis that referenced this pull request Dec 17, 2018
do not delete expired keys in KEYS command
JackieXie168 pushed a commit to JackieXie168/redis that referenced this pull request Dec 17, 2018
pulllock pushed a commit to pulllock/redis that referenced this pull request Jun 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants