test.erl 802 B

12345678910111213141516171819202122232425262728293031323334
  1. -module(test).
  2. -export([
  3. main/0
  4. ]).
  5. unwrap({ok, [{_, V}]}) -> V; %% ok
  6. unwrap(_) -> err. %% not ok
  7. main() ->
  8. %Conn = {host, "localhost", port, 11211},
  9. Conn = {host, "127.0.0.1", port, 11211},
  10. R0 = memcached:get(Conn, "test1"), %% {ok,[]}
  11. io:format("get test1 = ~p~n", [R0]),
  12. V1 = "value1 = 🔥🦀",
  13. R1 = memcached:set(Conn, "test1", V1), %% ok = stored successfully
  14. io:format("set test1 = ~p~n", [R1]),
  15. R2 = memcached:get(Conn, "test1"), %% {ok,[{"test1",[118,97,108,117,101,49,32,61,32,128293,129408]}]}
  16. io:format("get test1 = ~ts~n", [ unwrap(R2) ]), %% value1 = 🔥🦀
  17. R3 = memcached:delete(Conn, "test1"), %% ok
  18. io:format("delete test1 = ~p~n", [R3]),
  19. R4 = memcached:get(Conn, "test1"), %% {ok,[]}
  20. io:format("get test1 = ~p~n", [R4]),
  21. ok.