@@ -220,6 +220,12 @@ def _init_ffi(self):
220220 unsigned long arg_count, const size_t *args, const unsigned long* args_len,
221221 const unsigned char* route_bytes, size_t route_bytes_len, uint64_t span_ptr
222222 );
223+ CommandResult* update_connection_password(
224+ const void* client_adapter_ptr,
225+ uintptr_t request_id,
226+ const char* password,
227+ bool immediate_authentication
228+ );
223229 """
224230 )
225231
@@ -403,6 +409,60 @@ def _execute_command(
403409 )
404410 return self ._handle_cmd_result (result )
405411
412+ def _update_connection_password (
413+ self ,
414+ password : Optional [str ],
415+ immediate_auth : bool = False ,
416+ ) -> TResult :
417+ """
418+ Update the current connection password with a new password.
419+
420+ Note:
421+ This method updates the client's internal password configuration and does
422+ not perform password rotation on the server side.
423+
424+ This method is useful in scenarios where the server password has changed or when
425+ utilizing short-lived passwords for enhanced security. It allows the client to
426+ update its password to reconnect upon disconnection without the need to recreate
427+ the client instance. This ensures that the internal reconnection mechanism can
428+ handle reconnection seamlessly, preventing the loss of in-flight commands.
429+
430+ Args:
431+ password (`Optional[str]`): The new password to use for the connection,
432+ if `None` the password will be removed.
433+ immediate_auth (`bool`):
434+ `True`: The client will authenticate immediately with the new password against all connections, Using `AUTH`
435+ command. If password supplied is an empty string, auth will not be performed and warning will be returned.
436+ The default is `False`.
437+
438+ Returns:
439+ TOK: A simple OK response. If `immediate_auth=True` returns OK if the reauthenticate succeed.
440+
441+ Example:
442+ >>> client.update_connection_password("new_password", immediate_auth=True)
443+ 'OK'
444+ """
445+ if self ._is_closed :
446+ raise ClosingError ("Client is closed." )
447+ client_adapter_ptr = self ._core_client
448+ if client_adapter_ptr == self ._ffi .NULL :
449+ raise ValueError ("Invalid client pointer." )
450+
451+ # Prepare C string for password
452+ c_password = (
453+ self ._ffi .new ("char[]" , password .encode (ENCODING ))
454+ if password is not None
455+ else self ._ffi .new ("char[]" , b"" )
456+ )
457+
458+ result = self ._lib .update_connection_password (
459+ client_adapter_ptr ,
460+ 0 , # Request ID (0 for sync use)
461+ c_password ,
462+ immediate_auth ,
463+ )
464+ return self ._handle_cmd_result (result )
465+
406466 def close (self ):
407467 if not self ._is_closed :
408468 self ._lib .close_client (self ._core_client )
0 commit comments