From f27bac84a2ddcb8dc6b1ddfc0d8494aee93ebaa2 Mon Sep 17 00:00:00 2001 From: Madelyn Olson <madelyneolson@gmail.com> Date: Wed, 23 Apr 2025 23:13:56 +0100 Subject: [PATCH 1/4] Update website for version 8.1.1 (#246) Signed-off-by: Dmitry Polyakovsky <dmitry.polyakovky@oracle.com> --- content/download/releases/v8-1-1.md | 31 +++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 content/download/releases/v8-1-1.md diff --git a/content/download/releases/v8-1-1.md b/content/download/releases/v8-1-1.md new file mode 100644 index 0000000..d76e336 --- /dev/null +++ b/content/download/releases/v8-1-1.md @@ -0,0 +1,31 @@ +--- +title: "8.1.1" +date: 2025-04-23 +extra: + tag: "8.1.1" + artifact_source: https://download.valkey.io/releases/ + artifact_fname: "valkey" + container_registry: + - + name: "Docker Hub" + link: https://hub.docker.com/r/valkey/valkey/ + id: "valkey/valkey" + tags: + - "8.1.1" + - "8.1.1-bookworm" + - "8.1.1-alpine" + - "8.1.1-alpine3.21" + packages: + + artifacts: + - distro: jammy + arch: + - arm64 + - x86_64 + - distro: noble + arch: + - arm64 + - x86_64 +--- + +Valkey 8.1.1 Release \ No newline at end of file From db58e871af6efa9b5c40321a21e4eb497f1b3d7d Mon Sep 17 00:00:00 2001 From: Daniel Phillips <phiro56@gmail.com> Date: Thu, 24 Apr 2025 21:43:49 -0600 Subject: [PATCH 2/4] Bug fix: improve responsive layout of homepage documentation tiles (#249) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The documentation tiles on the homepage were stacking awkwardly at screen widths between 768px and 1090px. Modified the grid layout to create a more natural 2x2 layout at these intermediate screen sizes, ensuring consistent spacing and better visual organization. <img width="1023" alt="Screenshot 2025-04-24 at 4 53 59 PM" src="https://github.com/user-attachments/assets/237bce45-1cec-46ad-925a-766d0627fd93" /> <img width="480" alt="Screenshot 2025-04-24 at 4 54 13 PM" src="https://github.com/user-attachments/assets/ee8e564a-44d1-45f4-914b-248787ae9340" /> Signed-off-by: Daniel Phillips <phiro56@gmail.com> Signed-off-by: Dmitry Polyakovsky <dmitry.polyakovky@oracle.com> --- sass/_valkey.scss | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/sass/_valkey.scss b/sass/_valkey.scss index dba2123..baf2cd7 100644 --- a/sass/_valkey.scss +++ b/sass/_valkey.scss @@ -1073,6 +1073,19 @@ pre table { .documentation-card-grid { margin-top: 4rem; + + @media (max-width: 1100px) { + .col { + flex: 1 1 50%; + margin-bottom: 3rem; + } + } + + @media (max-width: 768px) { + .col { + flex: 1 1 100%; + } + } } .documentation-card { @@ -1083,10 +1096,8 @@ pre table { border-radius: 20px; color: white; background: #2d2471; - margin-bottom: 3rem; @include respond-min(768px) { - margin-bottom: 0; min-height: 100%; } From dcd20aaf7e673237ae62bf163a52655fa9ef8d15 Mon Sep 17 00:00:00 2001 From: Dmitry Polyakovsky <dmitry.polyakovky@oracle.com> Date: Sun, 27 Apr 2025 14:13:51 -0700 Subject: [PATCH 3/4] valkey module rust SDK updates Signed-off-by: dmitrypol <dmitrypol@gmail.com> Signed-off-by: Dmitry Polyakovsky <dmitry.polyakovky@oracle.com> --- .gitignore | 3 + ...5-04-27-valkey-modules-rust-sdk-updates.md | 269 ++++++++++++++++++ 2 files changed, 272 insertions(+) create mode 100644 content/blog/2025-04-27-valkey-modules-rust-sdk-updates.md diff --git a/.gitignore b/.gitignore index 69433c2..2feed9a 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,6 @@ _data/groups.json _data/resp2_replies.json _data/resp3_replies.json _data/modules.json +.vscode/* +.idea/* +tmp/* diff --git a/content/blog/2025-04-27-valkey-modules-rust-sdk-updates.md b/content/blog/2025-04-27-valkey-modules-rust-sdk-updates.md new file mode 100644 index 0000000..6c76684 --- /dev/null +++ b/content/blog/2025-04-27-valkey-modules-rust-sdk-updates.md @@ -0,0 +1,269 @@ ++++ +title= "Valkey Modules Rust SDK updates" +date= 2025-05-06 01:01:01 +description= "Extending Valkey using Rust SDK." +authors= ["dmitrypol"] +categories= "modules" ++++ + +In an earlier [article](/blog/modules-101/) we discussed the process of building Valkey Modules. +Modules allow adding extra features (such as new commands and data types) to Valkey without making changes to the core code. +We briefly touched on how to use the [Valkey Modules Rust SDK](https://github.com/valkey-io/valkeymodule-rs) to build a simple module. +In this article we will expand on this topic and discuss some of the new features added to the SDK over the last year. + +## What is the Valkey Modules Rust SDK? + +The SDK is based on [Redis Modules Rust SDK](https://github.com/RedisLabsModules/redismodule-rs) and provides abstraction APIs on top of Valkey Modules own API. +For those familiar with Rust development the SDK is a Rust crate that can be added to `Cargo.toml` file like any other Rust dependency. +It requires the underlying Valkey version to have appropriate module APIs but allows writing Valkey modules in Rust, without needing to use raw pointers or unsafe code. +The recently released [Bloom Filters module](/blog/introducing-bloom-filters/) is built using this crate and several of the developers who worked on the module contributed to the SDK. +Let's deep dive into to new features. + +## Client + +`Context` struct now has several new functions to get information about the client connected to Valkey. +It provides Rust wrappers around `Module_GetClient*` functions in the underlying Valkey Module API. +Most new functions return `ValkeyResult` so the module developer can handle the error appropriately. +The functions can be called for the current client or by specifying `client_id`. + +```rust +fn my_client_cmd(ctx: &Context, _args: Vec<ValkeyString>) -> ValkeyResult { + let client_id = ctx.get_client_id(); + let username = ctx.get_client_username_by_id(client_id); + Ok(ValkeyValue::from(username.to_string())) +} +valkey_module! { + ... + commands: [ + ["my_client_cmd", my_client_cmd, "", 0, 0, 0], + ] +} +``` + +## Auth callback + +Valkey 7.2 introduced support for callbacks after authentication. +Now it can be leveraged in modules. + +```rust +fn auth_callback( + ctx: &Context, + username: ValkeyString, + _password: ValkeyString, +) -> Result<c_int, ValkeyError> { + if ctx.authenticate_client_with_acl_user(&username) == Status::Ok { + // can be combined with ctx.get_client_ip to control access by IP address + let _client_ip = ctx.get_client_ip()?; + ... + return Ok(AUTH_HANDLED); + } + Ok(AUTH_NOT_HANDLED) +} +valkey_module! { + ... + auth: [auth_callback], +} +``` + +## Preload validation + +While the `valkey_module!` macro already provided an init callback to execute custom code during module load, init executed at the very end of the module load after new commands and data types are created. +That can be useful but what if we wanted to stop module load before any of that happens? +For example, we might need to restrict a module to be loaded only on specific version of Valkey. +That's where the optional `preload` is useful. + +```rust +fn preload_fn(ctx: &Context, _args: &[ValkeyString]) -> Status { + let _version = ctx.get_server_version().unwrap(); + // respond with Status::Ok or Status::Err to prevent loading + Status::Ok +} +valkey_module! { + ... + preload: preload_fn, + commands: [], +} +``` + +## Filters + +To execute custom code before specific Valkey commands we can use command filters. This can be leveraged to replace default commands with custom comands or modify arguments. +Thanks to the abstractions provided by the SDK we simply need to create a Rust function and register it in the `valkey_module!` macro. +Note of caution - since filters are executed before every command this code needs to be optimized. + +```rust +fn my_filter_fn(_ctx: *mut RedisModuleCommandFilterCtx) { + let cf_ctx = CommandFilterCtx::new(ctx); + // check the number of arguments + if cf_ctx.args_count() != 3 { + return; + } + // get which command is being executed + let _cmd = cf_ctx.cmd_get_try_as_str().unwrap(); + // grab various args passed to the command + let _all_args = cf_ctx.get_all_args_wo_cmd(); + // replace command + cf_ctx.arg_replace(0, "custom_cmd"); +} +valkey_module! { + ... + filters: [ + [my_filter_fn, VALKEYMODULE_CMDFILTER_NOSELF], + ] +} +``` + +## New event handlers + +The SDK now supports more server events. We can use this to execute our own code on client connect/disconnect, server shutdown or specific key events. + +```rust +#[client_changed_event_handler] +fn client_changed_event_handler(_ctx: &Context, client_event: ClientChangeSubevent) { + match client_event { + ClientChangeSubevent::Connected => {} + ClientChangeSubevent::Disconnected => {} + } +} +#[shutdown_event_handler] +fn shutdown_event_handler(_ctx: &Context, _event: u64) { + ... +} +#[key_event_handler] +fn key_event_handler(ctx: &Context, key_event: KeyChangeSubevent) { + match key_event { + KeyChangeSubevent::Deleted => {} + KeyChangeSubevent::Evicted => {} + KeyChangeSubevent::Overwritten => {} + KeyChangeSubevent::Expired => {} + } +} +``` + +## Custom ACL categories support + +Valkey 8 introduced support for custom ACL categories. To implement that we need to enable `required-features = ["min-valkey-compatibility-version-8-0"]` in `Cargo.toml` and register new categories in `valkey_module!` macro. Then we can restrict our custom commands to these ACL categories. + +```rust +valkey_module! { + ... + acl_categories: [ + "acl_one", + "acl_two" + ] + commands: [ + ["cmd1", cmd1, "write", 0, 0, 0, "acl_one"], + ["cmd2", cmd2, "", 0, 0, 0, "acl_one acl_two"], + ] +``` + +## Validating / Rejecting CONFIG SET + +The SDK now supports specifying optional callback functions to validate or reject custom configuations. This is available for `String`, `i64`, `bool` and `enum` configs. Here is an example of validation for i64 custom config. + +```rust +lazy_static! { + static ref CONFIG_I64: ValkeyGILGuard<i64> = ValkeyGILGuard::default(); +} +fn on_i64_config_set<G, T: ConfigurationValue<i64>>( + config_ctx: &ConfigurationContext, + _name: &str, + val: &'static T, +) -> Result<(), ValkeyError> { + if val.get(config_ctx) == custom_logic_here { + log_notice("log message here"); + Err(ValkeyError::Str("error message here ")) + } else { + Ok(()) + } +} +valkey_module! { + configurations: [ + i64: [ + ["my_i64", &*CONFIG_I64, 10, 0, 1000, ConfigurationFlags::DEFAULT, Some(Box::new(on_configuration_changed)), Some(Box::new(on_i64_config_set::<ValkeyString, ValkeyGILGuard<i64>>))], + ], + ... + ] +} +``` + +## Defrag + +There is a new `Defrag` struct abstracting away the raw C FFI calls to implement defrag for custom data types. + +```rust +static MY_VALKEY_TYPE: ValkeyType = ValkeyType::new( + "mytype123", + 0, + raw::RedisModuleTypeMethods { + ... + defrag: Some(defrag), + }, +); +unsafe extern "C" fn defrag( + defrag_ctx: *mut raw::RedisModuleDefragCtx, + _from_key: *mut RedisModuleString, + value: *mut *mut c_void, +) -> i32 { + let defrag = Defrag::new(defrag_ctx); + ... + 0 +} +valkey_module! { + ... + data_types: [ + MY_VALKEY_TYPE, + ], + ... +} +``` + +## Redis support + +There is a new feature flag if your module needs to run on both Valkey and Redis. +Specify `use-redismodule-api` so that module used RedisModule API Initialization for backwards compatibility. + +```rust +[features] +use-redismodule-api = ["valkey-module/use-redismodule-api"] +default = [] + +cargo build --release --features use-redismodule-api +``` + +## Unit tests and memory allocation + +This feature flag supports running unit tests outside of Valkey or Redis. As the result it cannot use Vakey Allocator and instead relies on the System Allocator instead. The core logis is present in `alloc.rs` but developers only need to specify this in the module `Cargo.toml`. + +```rust +[features] +enable-system-alloc = ["valkey-module/system-alloc"] + +cargo test --features enable-system-alloc +``` + +## Ideas for future development + +* Mock Context for unit testing - enable unit testing functions that require `&ctx` +* Context in Filters - enable more operations to be done in filters. +* Environment specific config support - during development or unit testing it is useful to have different config settings. +* Crontab - `cron_event_handler` uses `serverCron` (10 times per second by default) but it can be extended to run custom code on pre-determined schedule and configured via custom commands. +* And more. Please stay tuned. + +## List of contributors + +Below are the Github handles of the developers who contibuted to the SDK in the past year + +* [KarthikSubbarao](https://github.com/KarthikSubbarao) +* [dmitrypol](https://github.com/dmitrypol) +* [sachinvmurthy](https://github.com/sachinvmurthy) +* [zackcam](https://github.com/zackcam) +* [YueTang-Vanessa](https://github.com/YueTang-Vanessa) +* [hahnandrew](https://github.com/hahnandrew) +* [Mkmkme](https://github.com/Mkmkme) + +## Usefull links + +* [Valkey repo](https://github.com/valkey-io/valkey) +* [Valkey Modules Rust SDK](https://github.com/valkey-io/valkeymodule-rs) +* [Rust in VS Code](https://code.visualstudio.com/docs/languages/rust) From 07539ee8d7f35211812c07fd932015cfcc9196cb Mon Sep 17 00:00:00 2001 From: Dmitry Polyakovsky <dmitry.polyakovky@oracle.com> Date: Tue, 6 May 2025 09:25:18 -0700 Subject: [PATCH 4/4] rephrasing the article Signed-off-by: Dmitry Polyakovsky <dmitry.polyakovky@oracle.com> --- ...5-04-27-valkey-modules-rust-sdk-updates.md | 31 +++++++------------ 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/content/blog/2025-04-27-valkey-modules-rust-sdk-updates.md b/content/blog/2025-04-27-valkey-modules-rust-sdk-updates.md index 6c76684..9cfe8bb 100644 --- a/content/blog/2025-04-27-valkey-modules-rust-sdk-updates.md +++ b/content/blog/2025-04-27-valkey-modules-rust-sdk-updates.md @@ -6,10 +6,9 @@ authors= ["dmitrypol"] categories= "modules" +++ -In an earlier [article](/blog/modules-101/) we discussed the process of building Valkey Modules. -Modules allow adding extra features (such as new commands and data types) to Valkey without making changes to the core code. -We briefly touched on how to use the [Valkey Modules Rust SDK](https://github.com/valkey-io/valkeymodule-rs) to build a simple module. -In this article we will expand on this topic and discuss some of the new features added to the SDK over the last year. +In an earlier [article](/blog/modules-101/) we explored the process of building Valkey Modules—extensions that let developers add new commands and data types to Valkey without modifying its core. +We also introduced the [Valkey Modules Rust SDK](https://github.com/valkey-io/valkeymodule-rs) demonstrating how to use it to create a basic module. +In this follow-up article, we’ll dive deeper into the SDK and highlight several new features and improvements introduced over the past year. ## What is the Valkey Modules Rust SDK? @@ -242,25 +241,17 @@ enable-system-alloc = ["valkey-module/system-alloc"] cargo test --features enable-system-alloc ``` -## Ideas for future development +## Conclusion -* Mock Context for unit testing - enable unit testing functions that require `&ctx` -* Context in Filters - enable more operations to be done in filters. -* Environment specific config support - during development or unit testing it is useful to have different config settings. -* Crontab - `cron_event_handler` uses `serverCron` (10 times per second by default) but it can be extended to run custom code on pre-determined schedule and configured via custom commands. -* And more. Please stay tuned. +The Valkey Modules Rust SDK has seen exciting improvements over the past year, making it easier and more powerful to extend Valkey. +But we are not stopping. +Some of ideas for future development include mock context support for unit testing, enhanced context access within filters, and environment-specific config to streamline development and testing. +Additionally, the introduction of crontab scheduling will allow executing custom logic on a defined schedule using cron_event_handler. -## List of contributors +We hope this overview helped you understand how to leverage the SDK and inspired you to explore what's possible with Valkey modules. +Stay tuned for future updates. -Below are the Github handles of the developers who contibuted to the SDK in the past year - -* [KarthikSubbarao](https://github.com/KarthikSubbarao) -* [dmitrypol](https://github.com/dmitrypol) -* [sachinvmurthy](https://github.com/sachinvmurthy) -* [zackcam](https://github.com/zackcam) -* [YueTang-Vanessa](https://github.com/YueTang-Vanessa) -* [hahnandrew](https://github.com/hahnandrew) -* [Mkmkme](https://github.com/Mkmkme) +We also want to express appreciation to the engineers who contibuted to the SDK in the past year - [KarthikSubbarao](https://github.com/KarthikSubbarao), [dmitrypol](https://github.com/dmitrypol), [sachinvmurthy](https://github.com/sachinvmurthy), [zackcam](https://github.com/zackcam), [YueTang-Vanessa](https://github.com/YueTang-Vanessa), [hahnandrew](https://github.com/hahnandrew), [Mkmkme](https://github.com/Mkmkme). ## Usefull links