gpt4 book ai didi

erlang - 如何让 Webmachine 和 eredis 一起工作?

转载 作者:IT王子 更新时间:2023-10-29 06:03:28 29 4
gpt4 key购买 nike

在我的 Webmachine 应用程序中,我一直在思考 Redis 的使用问题一个星期。我还没有开悟。

我将使用 Eredis,这是一个使用示例:

{ok, Con} = eredis:start_link().

{ok, <<"OK">>} = eredis:q(Con, ["SET", "foo", "bar"]).
{ok, <<"bar">>} = eredis:q(Con, ["GET", "foo"]).

据我所知,eredis:start_link() 应该只在某处调用一次。但是我怎样才能在我的资源中获取 Con 变量呢?

最佳答案

有几种解决方法:

  • 在本地或全局注册一个redis连接
  • 使用像gproc这样的进程寄存器
  • 将连接的 pid 保存在 webmachine 资源上下文中
  • 使用像pooler这样的连接池或 poolboy
  • 如果您不想在池中排队请求 dispcount适合

编辑:被误解的问题,第一个答案如下:

Webmachine 和eredis 都是Erlang applications following the OTP principles .如果您的应用程序符合 OTP,您可以将 eredis 添加到 .app 文件中的 applications,如下所示:

{application, awesome_app, [
{description, "My awesome app."},
{vsn, "0.0.1"},
{modules, []},
{registered, []},
{applications, [kernel, stdlib,
eredis,
webmachine]}
]}.

OTP 符合应用程序使用 releases .创建发布并启动应用程序后,applications 中的应用程序将在您的应用程序之前启动。

Rebar是您构建和生成版本的 friend (more info here)。钢筋的替代品是 sinanthis article 中有描述.

关于erlang - 如何让 Webmachine 和 eredis 一起工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12895448/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com