Backported Redis Queue migration fix to 4.2

The bug described in #5707 was fixed recently in e34ecc182fd1dd2554e58e172750e530ec7fca1c (master branch). But the bug still lingered around in the 4.2 version, which this pull request solves.

I have backported the exact fix and the tests, so that it'd be just one click work for you. :+1: