|
1 | 1 | use crate::{
|
2 |
| - Context, RedisModuleClientInfo, RedisModule_GetClientCertificate, RedisModule_GetClientId, |
3 |
| - RedisModule_GetClientInfoById, RedisModule_GetClientNameById, |
4 |
| - RedisModule_GetClientUserNameById, RedisModule_SetClientNameById, Status, ValkeyError, |
5 |
| - ValkeyResult, ValkeyString, |
| 2 | + Context, RedisModuleClientInfo, RedisModule_DeauthenticateAndCloseClient, |
| 3 | + RedisModule_GetClientCertificate, RedisModule_GetClientId, RedisModule_GetClientInfoById, |
| 4 | + RedisModule_GetClientNameById, RedisModule_GetClientUserNameById, |
| 5 | + RedisModule_SetClientNameById, Status, ValkeyError, ValkeyResult, ValkeyString, ValkeyValue, |
| 6 | + VALKEYMODULE_OK, |
6 | 7 | };
|
7 | 8 | use std::ffi::CStr;
|
8 | 9 | use std::os::raw::c_void;
|
@@ -120,4 +121,27 @@ impl Context {
|
120 | 121 | pub fn get_client_ip(&self) -> ValkeyResult<String> {
|
121 | 122 | self.get_client_ip_by_id(self.get_client_id())
|
122 | 123 | }
|
| 124 | + pub fn deauthenticate_and_close_client_by_id(&self, client_id: u64) -> ValkeyResult<ValkeyString> { |
| 125 | + match unsafe { RedisModule_DeauthenticateAndCloseClient.unwrap()(self.ctx, client_id) } { |
| 126 | + result if result as isize == VALKEYMODULE_OK => Ok(ValkeyString::create(None, "OK")), |
| 127 | + _ => Err(ValkeyError::Str( |
| 128 | + "Failed to deauthenticate and close client", |
| 129 | + )), |
| 130 | + } |
| 131 | + } |
| 132 | + |
| 133 | + pub fn deauthenticate_and_close_client(&self) -> ValkeyResult<String> { |
| 134 | + self.deauthenticate_and_close_client_by_id(self.get_client_id()) |
| 135 | + .map(|valkey_str| valkey_str.to_string()) |
| 136 | + } |
| 137 | + |
| 138 | + pub fn config_get(&self, config: String) -> ValkeyResult<ValkeyString> { |
| 139 | + match self.call("CONFIG", &["GET", &config])? { |
| 140 | + ValkeyValue::Array(array) if array.len() == 2 => match &array[1] { |
| 141 | + ValkeyValue::SimpleString(val) => Ok(ValkeyString::create(None, val.clone())), |
| 142 | + _ => Err(ValkeyError::Str("Config value is not a string")), |
| 143 | + }, |
| 144 | + _ => Err(ValkeyError::Str("Unexpected CONFIG GET response")), |
| 145 | + } |
| 146 | + } |
123 | 147 | }
|
0 commit comments