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 |
|
init() -> |
12 |
76 |
ok. |
13 |
|
|
14 |
|
start(HostType, Tag, WpoolOptsIn, ConnOpts) -> |
15 |
76 |
ProcName = mongoose_wpool:make_pool_name(redis, HostType, Tag), |
16 |
76 |
WpoolOpts = wpool_spec(WpoolOptsIn, ConnOpts), |
17 |
76 |
mongoose_wpool:start_sup_pool(redis, ProcName, WpoolOpts). |
18 |
|
|
19 |
|
stop(_, _) -> |
20 |
73 |
ok. |
21 |
|
|
22 |
:-( |
is_supported_strategy(available_worker) -> false; |
23 |
76 |
is_supported_strategy(_) -> true. |
24 |
|
|
25 |
|
%% -------------------------------------------------------------- |
26 |
|
%%% Internal functions |
27 |
|
wpool_spec(WpoolOptsIn, ConnOpts) -> |
28 |
76 |
Worker = {eredis_client, makeargs(ConnOpts)}, |
29 |
76 |
[{worker, Worker} | WpoolOptsIn]. |
30 |
|
|
31 |
|
makeargs(#{host := Host, port := Port, database := Database, password := Password}) -> |
32 |
76 |
[Host, Port, Database, Password, 100, 5000]. |