anchor.diff:  
   -compile(export_all).
   
  -% cmd(get, Sock, RecvCB, Args) ->
  -%   ok;
  -% cmd(version, Sock, RecvCB, Args) ->
  -%   ok.
  +-record(msg, {cmd = "",
  +              key = "",
  +              flag = 0,
  +              expire = 0,
  +              cas = 0,
  +              data = <<>>}).
  +
  +cmd(version, _Sock, _RecvCallback, _Msg) ->
  +    exit({unimplemented});
  +cmd(get, _Sock, _RecvCallback, _Msg) ->
  +    exit({unimplemented});
  +cmd(set, Sock, RecvCallback, Msg) ->
  +    cmd_update("set", Sock, RecvCallback, Msg);
  +cmd(Cmd, _, _, _) ->
  +    exit({unimplemented, Cmd}).
  +
  +cmd_update(Cmd, Sock, RecvCallback,
  +           #msg{key=Key, flag=Flag, expire=Expire, data=Data}) ->
  +    SFlag = integer_to_list(Flag),
  +    SExpire = integer_to_list(Expire),
  +    SDataSize = integer_to_list(size(Data)),
  +    send_recv(Sock, [Cmd, <<" ">>,
  +                     Key, <<" ">>,
  +                     SFlag, <<" ">>,
  +                     SExpire, <<" ">>,
  +                     SDataSize, <<"\r\n">>,
  +                     Data, <<"\r\n">>],
  +              RecvCallback).
  +
  +%% @doc send an iolist and receive a single line back.
  +send_recv(Sock, IoList) ->
  +    send_recv(Sock, IoList, undefined).
  +
  +send_recv(Sock, IoList, RecvCallback) ->
  +    ok = send(Sock, IoList),
  +    RV = recv_line(Sock),
  +    if is_function(RecvCallback) -> RecvCallback(RV);
  +       true -> ok
  +    end,
  +    RV.
  +
  +send(Sock, IoList) ->
  +    gen_tcp:send(Sock, iolist_to_binary(IoList)).
   
   %% @doc receive binary data of specified number of bytes length.
   recv_data(_, 0) -> <<>>;
  
positive.code:         Err -> Err
      end.
  
  %% @doc receive a binary \r\n terminated line, including the \r\n.
  recv_line(Sock) ->
      recv_line(Sock, <<>>).
  
  
negative.code: recv_line_test() ->
      {ok, Sock} = gen_tcp:connect("localhost", 11211,
                                   [binary, {packet, 0}, {active, false}]),
      (fun () ->
          ok = gen_tcp:send(Sock, "version\r\n"),
          {ok, RB} = recv_line(Sock),
          R = binary_to_list(RB),
          ?assert(starts_with(R, "VERSION ")),
          ?assert(ends_with(R, "\r\n"))
      end)(),
  
      (fun () ->
          ok = gen_tcp:send(Sock, "not-a-command\r\n"),
          {ok, RB} = recv_line(Sock),
          ?assertMatch(RB, <<"ERROR\r\n">>)
      end)(),
  
      ok = gen_tcp:close(Sock).
  
  