redis_auth()#
Syntax
redis_auth( conn_id, password )
Description#
Authenticate the connection identified by conn_id with the provided password. This sends the Redis AUTH command to the server.
Note: Redis 6+ supports ACLs and an AUTH form that accepts a username and password. This wrapper accepts a single password argument — if your server requires a username, authenticate according to your server configuration or use a client that supports the username/password form.
This mirrors the Redis AUTH command: https://redis.io/docs/latest/commands/auth/
Returns#
String — typically “OK” on successful authentication. On failure an error is returned (or the extension’s error/exception behavior applies).
Parameters#
Parameter | Type | Description |
---|---|---|
conn_id | connection | Redis connection identifier/handle used by the MivaScript Redis extension |
password | string | Password to authenticate the connection with |
Behavior and Errors#
- On success the server replies with “OK”.
- If the password is incorrect or authentication is not required/allowed, an error is returned.
- If the connection is not valid, the call will fail — ensure
redis_connect()
succeeded. - Be mindful of server ACLs (Redis 6+) which might require username-based authentication.
Examples#
Authenticate a connection
<MvASSIGN NAME="l.conn" VALUE="{ redis_connect('127.0.0.1', 6379) }">
<MvASSIGN NAME="l.auth" VALUE="{ redis_auth(l.conn, 'my_secret_password') }">
<MvEVAL EXPR="{ 'Auth response: ' $ l.auth }">
Authenticate then run a command
<MvASSIGN NAME="l.conn" VALUE="{ redis_connect('127.0.0.1', 6379) }">
<MvASSIGN NAME="l._" VALUE="{ redis_auth(l.conn, 'my_secret_password') }">
<MvASSIGN NAME="l.set" VALUE="{ redis_set(l.conn, 'foo', 'bar') }">
<MvASSIGN NAME="l.val" VALUE="{ redis_get(l.conn, 'foo') }">
<MvEVAL EXPR="{ l.val }">