EMQX消息存储Redis源码分析(1)

EMQX 数据存储Redis主要牵涉到几个外部的库文件:

1、 eredis:Non-blocking Redis client with focus on performance and robustness https://github.com/wooga/eredis.git 

2、eredis_cluster:eredis_cluster is a wrapper for eredis to support cluster mode of redis  https://github.com/adrienmo/eredis_cluster.git 

3、ecpool: It is different with worker-pool libraries in that it is designed to pool connection/clients to server or database https://github.com/emqx/ecpool.git

下面分析第一个文件emqx_backend_redis_app.erl。

第一步、启动emqx_backend_redis application,

第二步、启动应用的第一个监听者emqx_backend_redis_sup

第三步、注册Redis统计

第四步、载入emqx_backend_redis模块

-module(emqx_backend_redis_app).

-include("../include/emqx_backend_redis.hrl").

-behaviour(application).

-emqx_plugin(backend).

-export([start/2, stop/1]).

start(_Type, _Args) ->
%%   获取配置信息
  Pools = application:get_env(emqx_backend_redis, pools, []),
%%  启动应用监听者
  {ok, Sup} = emqx_backend_redis_sup:start_link(Pools),

%%  注册redis统计
  emqx_backend_redis:register_metrics(),

%%  载入redis模块
  emqx_backend_redis:load(),

  {ok, Sup}.

%% 停止应用,卸载安装的模块
stop(_State) ->
  lists:foreach(
    fun ({Pool, Env}) ->
      case proplists:get_value(type, Env) of
        cluster ->
          eredis_cluster:stop_pool(emqx_backend_redis:pool_name(Pool));
        _ -> ok
      end
    end,
    application:get_env(emqx_backend_redis, pools, [])),
  emqx_backend_redis:unload(),
  ok.

猜你喜欢

转载自blog.csdn.net/qq513036862/article/details/112937553