]> git.saurik.com Git - redis.git/blame_incremental - client-libraries/erlang/test/erldis_tests.erl
Erlang client updated
[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
17basic_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:mget(Client, ["hello", "foo"]),
30 erldis:del(Client, "hello"),
31 erldis:del(Client, "foo"),
32 erldis:exists(Client, "hello"),
33 erldis:exists(Client, "foo"),
34 [true, true, "bar", ["kitty!", "bar"], true, true, false, false] = erldis:get_all_results(Client),
35
36 erldis:set(Client, "pippo", "pluto"),
37 erldis:sadd(Client, "pippo", "paperino"),
38 % foo doesn't exist, the result will be nil
39 erldis:lrange(Client, "foo", 1, 2),
40 erldis:lrange(Client, "pippo", 1, 2),
41 [ok,
42 {error, "ERR Operation against a key holding the wrong kind of value"},
43 nil,
44 {error, "ERR Operation against a key holding the wrong kind of value"}
45 ] = erldis:get_all_results(Client),
46 erldis:del(Client, "pippo"),
47 [true] = erldis:get_all_results(Client),
48
49 erldis:rpush(Client, "a_list", "1"),
50 erldis:rpush(Client, "a_list", "2"),
51 erldis:rpush(Client, "a_list", "3"),
52 erldis:rpush(Client, "a_list", "1"),
53 erldis:lrem(Client, "a_list", 1, "1"),
54 erldis:lrange(Client, "a_list", 0, 2),
55 [ok, ok, ok, ok, true, ["2", "3", "1"]] = erldis:get_all_results(Client),
56
57 erldis:sort(Client, "a_list"),
58 erldis:sort(Client, "a_list", "DESC"),
59 erldis:lrange(Client, "a_list", 0, 2),
60 erldis:sort(Client, "a_list", "LIMIT 0 2 ASC"),
61 [["1", "2", "3"], ["3", "2", "1"], ["2", "3", "1"],
62 ["1", "2"]] = erldis:get_all_results(Client),
63
64 ok = erldis:quit(Client).
65
66
67
68% inline_tests(Client) ->
69% [?_assertMatch(ok, erldis:set(Client, "hello", "kitty!")),
70% ?_assertMatch(false, erldis:setnx(Client, "hello", "kitty!")),
71% ?_assertMatch(true, erldis:exists(Client, "hello")),
72% ?_assertMatch(true, erldis:del(Client, "hello")),
73% ?_assertMatch(false, erldis:exists(Client, "hello")),
74%
75% ?_assertMatch(true, erldis:setnx(Client, "hello", "kitty!")),
76% ?_assertMatch(true, erldis:exists(Client, "hello")),
77% ?_assertMatch("kitty!", erldis:get(Client, "hello")),
78% ?_assertMatch(true, erldis:del(Client, "hello")),
79%
80%
81% ?_assertMatch(1, erldis:incr(Client, "pippo"))
82% ,?_assertMatch(2, erldis:incr(Client, "pippo"))
83% ,?_assertMatch(1, erldis:decr(Client, "pippo"))
84% ,?_assertMatch(0, erldis:decr(Client, "pippo"))
85% ,?_assertMatch(-1, erldis:decr(Client, "pippo"))
86%
87% ,?_assertMatch(6, erldis:incrby(Client, "pippo", 7))
88% ,?_assertMatch(2, erldis:decrby(Client, "pippo", 4))
89% ,?_assertMatch(-2, erldis:decrby(Client, "pippo", 4))
90% ,?_assertMatch(true, erldis:del(Client, "pippo"))
91% ].