如何在Erlang中操作Redis
1 回答
德玛西亚99
TA贡献1770条经验 获得超3个赞
用ERedis:
下载和编译:
cd eredis./rebar compile在console中使用:
erl -pa ebin/{ok, C} = eredis:start_link().{ok, <<"OK">>} = eredis:q(C, ["SET", "foo", "bar"]).{ok, <<"bar">>} = eredis:q(C, ["GET", "foo"]).
在模块中使用:
[plain] view plain copy
save_order_id({Pid, DynData}) ->
{ok, Rds} = eredis:start_link(),
{_,Val} = ts_dynvars:lookup(order_id, DynData),
Id = binary_to_list(Val),
{ok, _} = eredis:q(Rds, ["RPUSH", "order_list", Id]).
get_order_id({Pid, DynData}) ->
{ok, Rds} = eredis:start_link(),
{ok, Id} = eredis:q(Rds, ["LPOP", "order_list"]),
Id.
- 1 回答
- 0 关注
- 1277 浏览
添加回答
举报
0/150
提交
取消