I have users stored in Redis and want to be able to call only certain subsets from a set, if I don't get the correct user back I want to put it back in the set and then try again until I get one of the desired users

@redis = Redis.new @randUser = @redis.spop("users") if @randUser.include?(["user_4", "user_5", "user_6"]) @redis.sadd("users", @randUser) # Run @randUser = @redis.spop("users") again else $user_username = @redis.hget(@randUser, "username") $user_password = @redis.hget(@randUser, "password") end

I can't quite get the logic right in my head, how else could I approach this please?