Recently we migrated some hash slots to other nodes.

During the migration there was an error. What ended up happening is once the migration did finally succeed, we ended up with orphaned keys in memory on the source instance.

Is there any way to safely delete keys from a slot on a node that is not assigned to the hash slot anymore.

Example, slot 690 failed during migration from node A to node B. It was subsequently successful and node B now owns slot 690. It appears there are still keys from slot 690 in node A, which end up in the backup files. Any reference to slot 690 in redis cli points me to node B.

Thanks, Ted

Comment From: antirez

@Tbone542 yep you can safely delete those keys. Which Redis version are you using?

Comment From: Tbone542

I am using Redis 5.0.5

What command(s) should be used to remove the unwanted keys from the node that shouldn't have them in memory?

Comment From: shaharmor

I don’t think there is a command to remove all keys that a node doesn’t own.

You can probably do it manually by calculating the hash slot for all keys but it’s a lot of work.

I would really like such a command as well

Comment From: Tbone542

I actually know the hash slot that is affected. On the node that doesn't own the slot the command CLUSTER COUNTKEYSINSLOT shows me the number on the local node (12,188). If I run the command on the node that owns the slot, I get (14,564). This makes sense as the migration was a few weeks ago and more keys were added to the slot.

Comment From: antirez

Let me check how we can make deletion of orphaned keys more automatic.

Comment From: antirez

I think the new redis-cli --cluster fix of Redis 6 is able to do this stuff, but I'm testing it.

Comment From: Tbone542

Is there a way to manually delete the keys in Redis 5 without affecting the live keys on the correct node?