From f269d5b613b9a560b01f6081b9175a363b93b682 Mon Sep 17 00:00:00 2001 From: Badlop Date: Tue, 3 Dec 2024 05:09:18 +0100 Subject: [PATCH] Redis: Add support for unix domain socket (#4318) --- src/ejabberd_options_doc.erl | 12 +++++++----- src/ejabberd_redis.erl | 8 +++++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/ejabberd_options_doc.erl b/src/ejabberd_options_doc.erl index a4ba40095..4e4bfe242 100644 --- a/src/ejabberd_options_doc.erl +++ b/src/ejabberd_options_doc.erl @@ -1137,11 +1137,13 @@ doc() -> "The default value is the value defined in _`queue_type`_ " "or 'ram' if the latter is not set.")}}, {redis_server, - #{value => ?T("Hostname"), + #{value => "Host | IP Address | Unix Socket Path", + note => "improved in 24.xx", desc => - ?T("A hostname or an IP address of the " - "_`database.md#redis|Redis`_ server." - "The default is 'localhost'.")}}, + ?T("A hostname, IP address or unix domain socket file of the " + "_`database.md#redis|Redis`_ server. " + "Setup the path to unix domain socket like: '\"unix:/path/to/socket\"'. " + "The default value is 'localhost'.")}}, {registration_timeout, #{value => "timeout()", desc => @@ -1434,7 +1436,7 @@ doc() -> ?T("The hostname or IP address of the SQL server. For _`sql_type`_ " "'mssql' or 'odbc' this can also be an ODBC connection string. " "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'.")}}, {sql_ssl, #{value => "true | false", diff --git a/src/ejabberd_redis.erl b/src/ejabberd_redis.erl index 0c4a5c9aa..05fa5e497 100644 --- a/src/ejabberd_redis.erl +++ b/src/ejabberd_redis.erl @@ -457,11 +457,12 @@ code_change(_OldVsn, State, _Extra) -> %%%=================================================================== -spec connect(state()) -> {ok, pid()} | {error, any()}. connect(#state{num = Num}) -> - Server = ejabberd_option:redis_server(), + Server1 = ejabberd_option:redis_server(), Port = ejabberd_option:redis_port(), DB = ejabberd_option:redis_db(), Pass = ejabberd_option:redis_password(), ConnTimeout = ejabberd_option:redis_connect_timeout(), + Server = parse_server(Server1), try case do_connect(Num, Server, Port, Pass, DB, ConnTimeout) of {ok, Client} -> ?DEBUG("Connection #~p established to Redis at ~ts:~p", @@ -481,6 +482,11 @@ connect(#state{num = Num}) -> {error, Reason} end. +parse_server([$u,$n,$i,$x,$: | Path]) -> + {local, Path}; +parse_server(Server) -> + Server. + do_connect(1, Server, Port, Pass, _DB, _ConnTimeout) -> %% First connection in the pool is always a subscriber Options = [{host, Server},