Blankman
Blankman

Reputation: 267010

How to determine when my list exists, but is empty?

I just learned that when a list is empty, EXISTS returns 0.

I am processing a list using this:

rpoplpush source target

When I am done processing, I still want to look at the source to see if it is empty, but also if the key exists. But since the list is empty, it is returning 0.

EXISTS source
(integer) 0

Is there a way to know that your list is empty, but the key does exist still in redis?

Upvotes: 0

Views: 761

Answers (1)

Sergio Tulentsev
Sergio Tulentsev

Reputation: 230336

In redis, empty list can't exist. If after popping an element list becomes empty, it is deleted.

    if (listTypeLength(o) == 0) {
        notifyKeyspaceEvent(NOTIFY_GENERIC,"del",
                            c->argv[1],c->db->id);
        dbDelete(c->db,c->argv[1]);
    }

Upvotes: 5

Related Questions