猿问

如何在Erlang中操作Redis?

如何在Erlang中操作Redis


天涯尽头无女友
浏览 1282回答 1
1回答

德玛西亚99

用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]&nbsp;view plain&nbsp;copy&nbsp;save_order_id({Pid,&nbsp;DynData})&nbsp;->&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ok,&nbsp;Rds}&nbsp;=&nbsp;eredis:start_link(),&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{_,Val}&nbsp;=&nbsp;ts_dynvars:lookup(order_id,&nbsp;DynData),&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Id&nbsp;=&nbsp;binary_to_list(Val),&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ok,&nbsp;_}&nbsp;=&nbsp;eredis:q(Rds,&nbsp;["RPUSH",&nbsp;"order_list",&nbsp;Id]).&nbsp; &nbsp;get_order_id({Pid,&nbsp;DynData})&nbsp;->&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ok,&nbsp;Rds}&nbsp;=&nbsp;eredis:start_link(),&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ok,&nbsp;Id}&nbsp;=&nbsp;eredis:q(Rds,&nbsp;["LPOP",&nbsp;"order_list"]),&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Id.&nbsp;&nbsp;
随时随地看视频慕课网APP
我要回答