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