Skip to content

Commit 5a8c0df

Browse files
committed
printer for connection spec
1 parent a9f7948 commit 5a8c0df

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/client.ml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ module Common(IO: S.IO) = struct
5151
port : int;
5252
}
5353

54+
let string_of_connection_spec s =
55+
if s.port = 0 then Printf.sprintf "unix:%S" s.host
56+
else Printf.sprintf "%s:%d" s.host s.port
57+
58+
let pp_connection_spec out sp = Format.pp_print_string out (string_of_connection_spec sp)
59+
5460
let connection_spec ?(port=6379) host = {host; port}
5561

5662
let connection_spec_unix_socket socket = {host = socket; port = 0}
@@ -509,6 +515,8 @@ module type Mode = sig
509515

510516
val connection_spec : ?port:int -> string -> connection_spec
511517
val connection_spec_unix_socket : string -> connection_spec
518+
val string_of_connection_spec : connection_spec -> string
519+
val pp_connection_spec : Format.formatter -> connection_spec -> unit
512520

513521
module SlotMap : Map.S with type key = int
514522
module ConnectionSpecMap : Map.S with type key = connection_spec

src/s.ml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ module type Client = sig
9494
port : int;
9595
}
9696

97+
val string_of_connection_spec : connection_spec -> string
98+
(** Print the spec
99+
@since NEXT_RELEASE *)
100+
101+
val pp_connection_spec : Format.formatter -> connection_spec -> unit
102+
(** Print the spec
103+
@since NEXT_RELEASE *)
104+
97105
val connection_spec : ?port:int -> string -> connection_spec
98106
(** Create a connection spec with the given host.
99107
@param port port to connect to (default [6379])

0 commit comments

Comments
 (0)