It seems that MULTI / EXEC will not work, because the second command depends on the return value of the first, but none of the commands are executed until EXEC is called. If you are using Redis 2.6 (currently in RC), you can use lua script via eval .
In general, I do not think that atomicity is of great concern here. In this case, there are no race conditions. The only thing that can happen is that the server crashes in the interval between the withdrawal of an element from the queue and its addition to the set, which seems unlikely.
Zhehao mao
source share