Redix 在 elixir 中使用
添加依赖:
defp deps do [ {:plug_cowboy, "~> 2.0"}, {:hackney, "~> 1.17"}, {:jason, ">= 1.0.0"}, {:redix, "~> 1.1"} ] end
执行:
mix deps.get
在 application 中启动,添加到 superviser 树中:
defmodule Elixirapp.Application do @moduledoc false use Application require Logger @impl true def start(_type, _args) do children = [ {Plug.Cowboy, scheme: :http, plug: Elixirapp.Router, options: [port: 8010]}, {Redix, host: "localhost", name: :redix}, # name :redix is the conn ] opts = [strategy: :one_for_one, name: Elixirapp.Supervisor] Logger.info("Server listening ...") Supervisor.start_link(children, opts) end end
这里的 name :redix 是 redix 客户端与 redis 的链接
使用方式:
{:ok, data} = Redix.command(:redix, ["SET", "name", "curry"])
这里的 atom :redix
是 Redix 启动时 name 参数指定的名称。
或者使用 pipe:
{:ok, data} = :redix |> Redix.command(["GET", "name"])
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论