   end
 
   def handle_cast({:pubsub_subscribe, channels, receiver}, s) do
+    subscriptions = Enum.map(channels, fn(ch) -> {:subscribe, ch, receiver} end)
+
     s
     |> Map.put(:pubsub, true)
-    |> enqueue({:subscribe, channels, receiver})
+    |> enqueue(subscriptions)
     |> send_noreply(Protocol.pack(["SUBSCRIBE"|channels]))
   end
 
   def handle_cast({:pubsub_unsubscribe, channels, receiver}, s) do
-    s
-    |> enqueue({:unsubscribe, channels, receiver})
+    unsubscriptions = Enum.map(channels, fn(ch) -> {:unsubscribe, ch, receiver} end)
+
+    s
+    |> enqueue(unsubscriptions)
     |> send_noreply(Protocol.pack(["UNSUBSCRIBE"|channels]))
   end
 
   def handle_cast({:pubsub_psubscribe, channels, receiver}, %{pubsub: _} = s) do
+    subscriptions = Enum.map(channels, fn(ch) -> {:psubscribe, ch, receiver} end)
+
     s
     |> Map.put(:pubsub, true)
-    |> enqueue({:subscribe, channels, receiver})
+    |> enqueue(subscriptions)
     |> send_noreply(Protocol.pack(["PSUBSCRIBE"|channels]))
   end
 
   def handle_cast({:pubsub_punsubscribe, channels, receiver}, s) do
-    s
-    |> enqueue({:punsubscribe, channels, receiver})
+    unsubscriptions = Enum.map(channels, fn(ch) -> {:punsubscribe, ch, receiver} end)
+
+    s
+    |> enqueue(unsubscriptions)
     |> send_noreply(Protocol.pack(["PUNSUBSCRIBE"|channels]))
   end
 

  end

  # Enqueues `val` in the state.
  defp enqueue(%{queue: queue} = s, val) do
    %{s | queue: :queue.in(val, queue)}
  end

  end

  defp new_pubsub_msg(s, ["subscribe", channel, _count]) do
    {{:value, {:subscribe, ^channel, receiver}}, new_queue} = :queue.out(s.queue)
    s = update_in s.pubsub_clients, fn(clients) ->
      Map.update(clients, channel, [receiver], &[receiver|&1])
    end

    message = {:redix_pubsub, :subscribe, channel}
    send(receiver, message)

    %{s | queue: new_queue}
  end

  defp new_pubsub_msg(s, ["psubscribe", channel, _count]) do
    {{:value, {:psubscribe, ^channel, receiver}}, new_queue} = :queue.out(s.queue)
    s = update_in s.pubsub_clients, fn(clients) ->
      Map.update(clients, channel, [receiver], &[receiver|&1])
    end

    send receiver, {:redix_pubsub, :psubscribe, channel}

    %{s | queue: new_queue}
  end

  defp new_pubsub_msg(s, ["unsubscribe", channel, _count]) do
    {{:value, {:unsubscribe, ^channel, receiver}}, new_queue} = :queue.out(s.queue)
    s = update_in s.pubsub_clients, fn(clients) ->
      Map.update!(clients, channel, &List.delete(&1, receiver))
    end

    send receiver, {:redix_pubsub, :unsubscribe, channel}

    %{s | queue: new_queue}
  end

  defp new_pubsub_msg(s, ["punsubscribe", channel, _count]) do
    {{:value, {:punsubscribe, ^channel, receiver}}, new_queue} = :queue.out(s.queue)
    s = update_in s.pubsub_clients, fn(clients) ->
      Map.update!(clients, channel, &List.delete(&1, receiver))
    end

    send receiver, {:redix_pubsub, :punsubscribe, channel}

    %{s | queue: new_queue}
  end

  defp send_noreply(%{socket: socket} = s, data) do
