25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-16 17:15:55 +01:00

Redis: Add support for unix domain socket (#4318)

This commit is contained in:
Badlop 2024-12-03 05:09:18 +01:00
parent a84c492130
commit f269d5b613
2 changed files with 14 additions and 6 deletions

View File

@ -1137,11 +1137,13 @@ doc() ->
"The default value is the value defined in _`queue_type`_ " "The default value is the value defined in _`queue_type`_ "
"or 'ram' if the latter is not set.")}}, "or 'ram' if the latter is not set.")}},
{redis_server, {redis_server,
#{value => ?T("Hostname"), #{value => "Host | IP Address | Unix Socket Path",
note => "improved in 24.xx",
desc => desc =>
?T("A hostname or an IP address of the " ?T("A hostname, IP address or unix domain socket file of the "
"_`database.md#redis|Redis`_ server." "_`database.md#redis|Redis`_ server. "
"The default is 'localhost'.")}}, "Setup the path to unix domain socket like: '\"unix:/path/to/socket\"'. "
"The default value is 'localhost'.")}},
{registration_timeout, {registration_timeout,
#{value => "timeout()", #{value => "timeout()",
desc => desc =>
@ -1434,7 +1436,7 @@ doc() ->
?T("The hostname or IP address of the SQL server. For _`sql_type`_ " ?T("The hostname or IP address of the SQL server. For _`sql_type`_ "
"'mssql' or 'odbc' this can also be an ODBC connection string. " "'mssql' or 'odbc' this can also be an ODBC connection string. "
"When _`sql_type`_ is 'mysql' or 'pgsql', this can be the path to " "When _`sql_type`_ is 'mysql' or 'pgsql', this can be the path to "
"a unix domain socket expressed like: \"unix:/path/to/socket\"." "a unix domain socket expressed like: '\"unix:/path/to/socket\"'."
"The default value is 'localhost'.")}}, "The default value is 'localhost'.")}},
{sql_ssl, {sql_ssl,
#{value => "true | false", #{value => "true | false",

View File

@ -457,11 +457,12 @@ code_change(_OldVsn, State, _Extra) ->
%%%=================================================================== %%%===================================================================
-spec connect(state()) -> {ok, pid()} | {error, any()}. -spec connect(state()) -> {ok, pid()} | {error, any()}.
connect(#state{num = Num}) -> connect(#state{num = Num}) ->
Server = ejabberd_option:redis_server(), Server1 = ejabberd_option:redis_server(),
Port = ejabberd_option:redis_port(), Port = ejabberd_option:redis_port(),
DB = ejabberd_option:redis_db(), DB = ejabberd_option:redis_db(),
Pass = ejabberd_option:redis_password(), Pass = ejabberd_option:redis_password(),
ConnTimeout = ejabberd_option:redis_connect_timeout(), ConnTimeout = ejabberd_option:redis_connect_timeout(),
Server = parse_server(Server1),
try case do_connect(Num, Server, Port, Pass, DB, ConnTimeout) of try case do_connect(Num, Server, Port, Pass, DB, ConnTimeout) of
{ok, Client} -> {ok, Client} ->
?DEBUG("Connection #~p established to Redis at ~ts:~p", ?DEBUG("Connection #~p established to Redis at ~ts:~p",
@ -481,6 +482,11 @@ connect(#state{num = Num}) ->
{error, Reason} {error, Reason}
end. end.
parse_server([$u,$n,$i,$x,$: | Path]) ->
{local, Path};
parse_server(Server) ->
Server.
do_connect(1, Server, Port, Pass, _DB, _ConnTimeout) -> do_connect(1, Server, Port, Pass, _DB, _ConnTimeout) ->
%% First connection in the pool is always a subscriber %% First connection in the pool is always a subscriber
Options = [{host, Server}, Options = [{host, Server},