我正在尝试将eredis包含在我的 Erlang 项目中以连接到 redis。我将它放在 lib/ 目录中,并使用-include_lib ("../lib/eredis/include/eredis.hrl").
It compiles fine in erl
,但随后尝试创建客户端失败** exception error: undefined function eredis:start_link/0
。
redis_worker.erl:
-module (redis_worker).
-export ([get/2, set/3, client/0]).
-include_lib ("../lib/eredis/include/eredis.hrl").
client() ->
eredis:start_link().
get(Client, Key) when is_list(Key) ->
{ok, Val} = eredis:q(Client,["GET", Key]),
io:format("Got key: ~s which had value ~s~n", [Key, Val]).
set(Client, Key, Value) when is_list(Key) andalso is_list(Value)->
{ok, <<"OK">>} = eredis:q(Client, ["SET", Key, Value]),
io:format("Set key: ~s to ~s~n",[Key, Value]).
为什么它编译得很好(我假设这意味着执行include_lib
)但是当我尝试使用包含的库时会爆炸?