]> git.saurik.com Git - redis.git/blame_incremental - client-libraries/erlang/test/erldis_tests.erl
New file dump format, perl client library added
[redis.git] / client-libraries / erlang / test / erldis_tests.erl
... / ...
CommitLineData
1-module(erldis_tests).
2
3-include_lib("eunit/include/eunit.hrl").
4-include("erldis.hrl").
5
6quit_test() ->
7 {ok, Client} = erldis:connect("localhost"),
8 ok = erldis:quit(Client),
9 false = is_process_alive(Client).
10
11utils_test() ->
12 ?assertEqual(client:str(1), "1"),
13 ?assertEqual(client:str(atom), "atom"),
14 ?assertEqual(client:format([[1, 2, 3]]), "1 2 3"),
15 ?assertEqual(client:format([[1,2,3], [4,5,6]]), "1 2 3\r\n4 5 6").
16
17pipeline_test() ->
18 {ok, Client} = erldis:connect("localhost"),
19 erldis:flushall(Client),
20 erldis:get(Client, "pippo"),
21 erldis:set(Client, "hello", "kitty!"),
22 erldis:setnx(Client, "foo", "bar"),
23 erldis:setnx(Client, "foo", "bar"),
24 [ok, nil, ok, true, false] = erldis:get_all_results(Client),
25
26 erldis:exists(Client, "hello"),
27 erldis:exists(Client, "foo"),
28 erldis:get(Client, "foo"),
29 erldis:del(Client, "hello"),
30 erldis:del(Client, "foo"),
31 erldis:exists(Client, "hello"),
32 erldis:exists(Client, "foo"),
33 [true, true, "bar", true, true, false, false] = erldis:get_all_results(Client),
34
35 erldis:set(Client, "pippo", "pluto"),
36 erldis:sadd(Client, "pippo", "paperino"),
37 % foo doesn't exist, the result will be nil
38 erldis:lrange(Client, "foo", 1, 2),
39 erldis:lrange(Client, "pippo", 1, 2),
40 [ok, {error, wrong_type}, nil,
41 {error, "Operation against a key holding the wrong kind of value"}
42 ] = erldis:get_all_results(Client),
43 erldis:del(Client, "pippo"),
44 [true] = erldis:get_all_results(Client),
45
46 erldis:rpush(Client, "a_list", "1"),
47 erldis:rpush(Client, "a_list", "2"),
48 erldis:rpush(Client, "a_list", "3"),
49 erldis:rpush(Client, "a_list", "1"),
50 erldis:lrem(Client, "a_list", 1, "1"),
51 erldis:lrange(Client, "a_list", 0, 2),
52 [ok, ok, ok, ok, 1, ["2", "3", "1"]] = erldis:get_all_results(Client),
53
54 erldis:sort(Client, "a_list"),
55 erldis:sort(Client, "a_list", "DESC"),
56 erldis:lrange(Client, "a_list", 0, 2),
57 erldis:sort(Client, "a_list", "LIMIT 0 2 ASC"),
58 [["1", "2", "3"], ["3", "2", "1"], ["2", "3", "1"],
59 ["1", "2"]] = erldis:get_all_results(Client),
60
61 ok = erldis:quit(Client).
62
63
64
65% inline_tests(Client) ->
66% [?_assertMatch(ok, erldis:set(Client, "hello", "kitty!")),
67% ?_assertMatch(false, erldis:setnx(Client, "hello", "kitty!")),
68% ?_assertMatch(true, erldis:exists(Client, "hello")),
69% ?_assertMatch(true, erldis:del(Client, "hello")),
70% ?_assertMatch(false, erldis:exists(Client, "hello")),
71%
72% ?_assertMatch(true, erldis:setnx(Client, "hello", "kitty!")),
73% ?_assertMatch(true, erldis:exists(Client, "hello")),
74% ?_assertMatch("kitty!", erldis:get(Client, "hello")),
75% ?_assertMatch(true, erldis:del(Client, "hello")),
76%
77%
78% ?_assertMatch(1, erldis:incr(Client, "pippo"))
79% ,?_assertMatch(2, erldis:incr(Client, "pippo"))
80% ,?_assertMatch(1, erldis:decr(Client, "pippo"))
81% ,?_assertMatch(0, erldis:decr(Client, "pippo"))
82% ,?_assertMatch(-1, erldis:decr(Client, "pippo"))
83%
84% ,?_assertMatch(6, erldis:incrby(Client, "pippo", 7))
85% ,?_assertMatch(2, erldis:decrby(Client, "pippo", 4))
86% ,?_assertMatch(-2, erldis:decrby(Client, "pippo", 4))
87% ,?_assertMatch(true, erldis:del(Client, "pippo"))
88% ].