Struct DetachedContextGuard

Source
pub struct DetachedContextGuard { /* private fields */ }
Expand description

This object is returned after locking Valkey from DetachedContext. On dispose, Valkey will be unlocked. This object implements Deref for Context so it can be used just like any Valkey Context for command invocation. This object should not be used to return replies because there is no real client behind this context to return replies to.

Methods from Deref<Target = Context>§

Source

pub fn create_timer<F, T: 'static>( &self, period: Duration, callback: F, data: T, ) -> RedisModuleTimerID
where F: FnOnce(&Self, T),

Wrapper for RedisModule_CreateTimer.

This function takes ownership of the provided data, and transfers it to Redis. The callback will get the original data back in a type safe manner. When the callback is done, the data will be dropped.

Source

pub fn stop_timer<T>( &self, timer_id: RedisModuleTimerID, ) -> Result<T, ValkeyError>

Wrapper for RedisModule_StopTimer.

The caller is responsible for specifying the correct type for the returned data. This function has no way to know what the original type of the data was, so the same data type that was used for create_timer needs to be passed here to ensure their types are identical.

Source

pub fn get_timer_info<T>( &self, timer_id: RedisModuleTimerID, ) -> Result<(Duration, &T), ValkeyError>

Wrapper for RedisModule_GetTimerInfo.

The caller is responsible for specifying the correct type for the returned data. This function has no way to know what the original type of the data was, so the same data type that was used for create_timer needs to be passed here to ensure their types are identical.

Source

pub fn authenticate_client_with_acl_user( &self, username: &ValkeyString, ) -> Status

Authenticates a client using an ACL user

§Arguments
  • username - ACL username to authenticate with
§Returns
  • Status::Ok - Authentication successful
  • Status::Err - Authentication failed
Source

pub fn block_client(&self) -> BlockedClient

Source

pub fn get_client_id(&self) -> u64

Source

pub fn get_client_name_by_id( &self, client_id: u64, ) -> ValkeyResult<ValkeyString>

wrapper for RedisModule_GetClientNameById

Source

pub fn get_client_name(&self) -> ValkeyResult<ValkeyString>

wrapper for RedisModule_GetClientNameById using current client ID

Source

pub fn set_client_name_by_id( &self, client_id: u64, client_name: &ValkeyString, ) -> Status

wrapper for RedisModule_SetClientNameById

Source

pub fn set_client_name(&self, client_name: &ValkeyString) -> Status

wrapper for RedisModule_SetClientNameById using current client ID

Source

pub fn get_client_username_by_id( &self, client_id: u64, ) -> ValkeyResult<ValkeyString>

wrapper for RedisModule_GetClientUserNameById

Source

pub fn get_client_username(&self) -> ValkeyResult<ValkeyString>

wrapper for RedisModule_GetClientUserNameById using current client ID

Source

pub fn get_client_cert(&self) -> ValkeyResult<ValkeyString>

wrapper for RedisModule_GetClientCertificate

Source

pub fn get_client_info_by_id( &self, client_id: u64, ) -> ValkeyResult<RedisModuleClientInfo>

wrapper for RedisModule_GetClientInfoById

Source

pub fn get_client_info(&self) -> ValkeyResult<RedisModuleClientInfo>

wrapper for RedisModule_GetClientInfoById using current client ID

Source

pub fn get_client_ip_by_id(&self, client_id: u64) -> ValkeyResult<String>

wrapper to get the client IP address from RedisModuleClientInfo

Source

pub fn get_client_ip(&self) -> ValkeyResult<String>

wrapper to get the client IP address from RedisModuleClientInfo using current client ID

Source

pub fn deauthenticate_and_close_client_by_id(&self, client_id: u64) -> Status

Source

pub fn deauthenticate_and_close_client(&self) -> Status

Source

pub fn config_get(&self, config: String) -> ValkeyResult<ValkeyString>

Source

pub fn register_command_filter( &self, module_cmd_filter_func: extern "C" fn(*mut RedisModuleCommandFilterCtx), flags: u32, ) -> CommandFilter

wrapper for RedisModule_RegisterCommandFilter to directly register a filter, likely in init

Source

pub fn unregister_command_filter(&self, cmd_filter: &CommandFilter)

wrapper for RedisModule_UnregisterCommandFilter to directly unregister filter, likely in deinit

Source

pub fn server_info(&self, section: &str) -> ServerInfo

Source

pub fn log(&self, level: ValkeyLogLevel, message: &str)

Source

pub fn log_debug(&self, message: &str)

Source

pub fn log_notice(&self, message: &str)

Source

pub fn log_verbose(&self, message: &str)

Source

pub fn log_warning(&self, message: &str)

Source

pub fn auto_memory(&self)

§Panics

Will panic if RedisModule_AutoMemory is missing in redismodule.h

Source

pub fn is_keys_position_request(&self) -> bool

§Panics

Will panic if RedisModule_IsKeysPositionRequest is missing in redismodule.h

Source

pub fn key_at_pos(&self, pos: i32)

§Panics

Will panic if RedisModule_KeyAtPos is missing in redismodule.h

Source

pub fn call<'a, T: Into<StrCallArgs<'a>>>( &self, command: &str, args: T, ) -> ValkeyResult

Source

pub fn call_ext<'a, T: Into<StrCallArgs<'a>>, R: From<CallResult<'static>>>( &self, command: &str, options: &CallOptions, args: T, ) -> R

Invoke a command on Valkey and return the result Unlike ‘call’ this API also allow to pass a CallOption to control different aspects of the command invocation.

Source

pub fn reply_simple_string(&self, s: &str) -> Status

Source

pub fn reply_error_string(&self, s: &str) -> Status

Source

pub fn reply_with_key(&self, result: ValkeyValueKey) -> Status

Source

pub fn reply(&self, result: ValkeyResult) -> Status

§Panics

Will panic if methods used are missing in redismodule.h

Source

pub fn open_key(&self, key: &ValkeyString) -> ValkeyKey

Source

pub fn open_key_with_flags( &self, key: &ValkeyString, flags: KeyFlags, ) -> ValkeyKey

Source

pub fn open_key_writable(&self, key: &ValkeyString) -> ValkeyKeyWritable

Source

pub fn open_key_writable_with_flags( &self, key: &ValkeyString, flags: KeyFlags, ) -> ValkeyKeyWritable

Source

pub fn replicate_verbatim(&self)

Source

pub fn replicate<'a, T: Into<StrCallArgs<'a>>>(&self, command: &str, args: T)

Replicate command to the replica and AOF.

Source

pub fn create_string<T: Into<Vec<u8>>>(&self, s: T) -> ValkeyString

Source

pub fn get_raw(&self) -> *mut RedisModuleCtx

Source

pub unsafe fn export_shared_api(&self, func: *const c_void, name: *const c_char)

Source

pub fn notify_keyspace_event( &self, event_type: NotifyEvent, event: &str, keyname: &ValkeyString, ) -> Status

Source

pub fn current_command_name(&self) -> Result<String, ValkeyError>

Source

pub fn get_server_version(&self) -> Result<Version, ValkeyError>

Returns the valkey version either by calling RedisModule_GetServerVersion API, Or if it is not available, by calling “info server” API and parsing the reply

Source

pub fn get_server_version_rm_call(&self) -> Result<Version, ValkeyError>

Returns the valkey version by calling “info server” API and parsing the reply

Source

pub fn set_module_options(&self, options: ModuleOptions)

Source

pub fn get_flags(&self) -> ContextFlags

Return ContextFlags object that allows to check properties related to the state of the current Valkey instance such as:

  • Role (master/slave)
  • Loading RDB/AOF
  • Execution mode such as multi exec or Lua
Source

pub fn get_current_user(&self) -> ValkeyString

Return the current user name attached to the context

Source

pub fn authenticate_user( &self, user_name: &ValkeyString, ) -> Result<ContextUserScope<'_>, ValkeyError>

Attach the given user to the current context so each operation performed from now on using this context will be validated againts this new user. Return [ContextUserScope] which make sure to unset the user when freed and can not outlive the current Context.

Source

pub fn acl_check_key_permission( &self, user_name: &ValkeyString, key_name: &ValkeyString, permissions: &AclPermissions, ) -> Result<(), ValkeyError>

Verify the the given user has the give ACL permission on the given key. Return Ok(()) if the user has the permissions or error (with relevant error message) if the validation failed.

Source

pub fn add_post_notification_job<F: FnOnce(&Context) + 'static>( &self, callback: F, ) -> APIResult<Status>

When running inside a key space notification callback, it is dangerous and highly discouraged to perform any write operation. In order to still perform write actions in this scenario, Valkey provides this API ([add_post_notification_job]) that allows to register a job callback which Valkey will call when the following condition holds:

  1. It is safe to perform any write operation.
  2. The job will be called atomically along side the key space notification.

Notice, one job might trigger key space notifications that will trigger more jobs. This raises a concerns of entering an infinite loops, we consider infinite loops as a logical bug that need to be fixed in the module, an attempt to protect against infinite loops by halting the execution could result in violation of the feature correctness and so Valkey will make no attempt to protect the module from infinite loops.

Source

pub fn avoid_replication_traffic(&self) -> bool

Returns true if a client sent the CLIENT PAUSE command to the server or if Valkey Cluster does a manual failover, pausing the clients. This is needed when we have a master with replicas, and want to write, without adding further data to the replication channel, that the replicas replication offset, match the one of the master. When this happens, it is safe to failover the master without data loss.

However modules may generate traffic by calling commands or directly send data to the replication stream.

So modules may want to try to avoid very heavy background work that has the effect of creating data to the replication channel, when this function returns true. This is mostly useful for modules that have background garbage collection tasks, or that do writes and replicate such writes periodically in timer callbacks or other periodic callbacks.

Trait Implementations§

Source§

impl Deref for DetachedContextGuard

Source§

type Target = Context

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl Drop for DetachedContextGuard

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl ValkeyLockIndicator for DetachedContextGuard

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.