glemcached
Types
Error returned while connecting to the Memcached instance
pub type ConnectionError {
ConnectError(mug.Error)
AuthenticationFailure
}
Constructors
-
ConnectError(mug.Error)
Something went wrong trying to establish a connection
-
AuthenticationFailure
The (maybe) provided credentials are wrong
This record holds the options used to connect (and authenticate) to the memcached instance.
pub type ConnectionOptions {
ConnectionOptions(
host: String,
port: Int,
timeout: Int,
username: String,
password: String,
)
}
Constructors
-
ConnectionOptions( host: String, port: Int, timeout: Int, username: String, password: String, )
Functions
pub fn connect(
opts: ConnectionOptions,
) -> Result(Memcached, ConnectionError)
Connect to a Memcached instance. This function creates a new TCP
connection to host:port using mug. The connection times out after
timeout
millis.
The returned Result has an Ok value of Memcached
, which holds the
connection socket and the command timeout value (default timeout
),
which can be changed with the with_timeout
function. The Error
value of the result is the mug.Error returned while creating the
connection or checking for authentication.
To check for authentication, the client sends an empty request to
the instance, which will respond with CLIENT_ERROR unauthorized
if authentication is required. Then, the client will send the
credentials using a SET command. It sets the key auth
with an
expiration of -1
.
Example
let mem = new(host, port)
|> with_timeout(500)
|> with_authentication("user", "pass")
|> connect()
pub fn with_authentication(
conn: ConnectionOptions,
username username: String,
password password: String,
) -> ConnectionOptions
Set the username and password fields of ConnectionOptions
pub fn with_timeout(
conn: ConnectionOptions,
timeout timeout: Int,
) -> ConnectionOptions
Set the ConnectionOptions
’ timeout value