1 |
|
-module(mongoose_wpool_redis). |
2 |
|
-behaviour(mongoose_wpool). |
3 |
|
|
4 |
|
-export([init/0]). |
5 |
|
-export([start/4]). |
6 |
|
-export([stop/2]). |
7 |
|
-export([is_supported_strategy/1]). |
8 |
|
|
9 |
|
%% -------------------------------------------------------------- |
10 |
|
%% mongoose_wpool callbacks |
11 |
|
-spec init() -> ok. |
12 |
|
init() -> |
13 |
93 |
ok. |
14 |
|
|
15 |
|
-spec start(mongooseim:host_type_or_global(), mongoose_wpool:tag(), |
16 |
|
mongoose_wpool:pool_opts(), mongoose_wpool:conn_opts()) -> {ok, pid()} | {error, any()}. |
17 |
|
start(HostType, Tag, WpoolOptsIn, ConnOpts) -> |
18 |
93 |
ProcName = mongoose_wpool:make_pool_name(redis, HostType, Tag), |
19 |
93 |
WpoolOpts = wpool_spec(WpoolOptsIn, ConnOpts), |
20 |
93 |
mongoose_wpool:start_sup_pool(redis, ProcName, WpoolOpts). |
21 |
|
|
22 |
|
-spec stop(mongooseim:host_type_or_global(), mongoose_wpool:tag()) -> ok. |
23 |
|
stop(_, _) -> |
24 |
91 |
ok. |
25 |
|
|
26 |
:-( |
is_supported_strategy(available_worker) -> false; |
27 |
93 |
is_supported_strategy(_) -> true. |
28 |
|
|
29 |
|
%% -------------------------------------------------------------- |
30 |
|
%%% Internal functions |
31 |
|
wpool_spec(WpoolOptsIn, ConnOpts) -> |
32 |
93 |
Worker = {eredis_client, makeargs(ConnOpts)}, |
33 |
93 |
[{worker, Worker} | WpoolOptsIn]. |
34 |
|
|
35 |
|
makeargs(Opts = #{host := _Host, port := _Port, database := _Database, password := _Password}) -> |
36 |
93 |
proplists:from_map(Opts) ++ [{reconnect_sleep, 100}, {connect_timeout, 5000}]. |