Skip to content

Commit 978870c

Browse files
dmitrypolDmitry Polyakovsky
authored andcommitted
Merge branch 'valkey-io:main' into main
2 parents 07539ee + 54bd9a5 commit 978870c

16 files changed

+213
-85
lines changed

.github/workflows/zola-deploy.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,17 @@ jobs:
4040
repository: valkey-io/valkey-bloom
4141
path: valkey-bloom
4242

43+
- name: Checkout valkey-json
44+
uses: actions/checkout@v4
45+
with:
46+
repository: valkey-io/valkey-json
47+
path: valkey-json
48+
4349
- name: Init commands, topics and clients
4450
run: |
4551
cd website
4652
./build/init-topics-and-clients.sh ../valkey-doc/topics ../valkey-doc/clients
47-
./build/init-commands.sh ../valkey-doc/commands ../valkey/src/commands ../valkey-bloom/src/commands
53+
./build/init-commands.sh ../valkey-doc/commands ../valkey/src/commands ../valkey-bloom/src/commands ../valkey-json/src/commands
4854
4955
- name: Build only
5056
uses: shalzz/[email protected]

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Valkey.io website
22

33
This repo contains the source for the valkey.io website (build scripts, template, blog posts, stylesheets, etc.).
4-
The build integrates content from [`valkey-io/valkey-doc`](https://github.com/valkey-io/valkey-doc) and the commands definitions from [`valkey-io/valkey`](https://github.com/valkey-io/valkey) and [`valkey-io/valkey-bloom`](https://github.com/valkey-io/valkey-bloom) (see [Build Locally](#build-locally) below for more details).
4+
The build integrates content from [`valkey-io/valkey-doc`](https://github.com/valkey-io/valkey-doc) and the commands definitions from [`valkey-io/valkey`](https://github.com/valkey-io/valkey), [`valkey-io/valkey-bloom`](https://github.com/valkey-io/valkey-bloom), and [`valkey-io/valkey-json`](https://github.com/valkey-io/valkey-json) (see [Build Locally](#build-locally) below for more details)
55

66
## Contributing
77

@@ -64,7 +64,7 @@ Commit your changes to your local copy of `valkey-io/valkey-doc`.
6464
### Building the command reference
6565

6666
The command reference (i.e. `/commands/set/`, `/commands/get/`, `/commands/lolwut/`) sources information from `valkey-io/valkey`, `valkey-io/valkey-bloom`, and `valkey-io/valkey-doc`.
67-
`valkey-io/valkey` and `valkey-io/valkey-bloom` provides the command metadata (items like computational complexity, version history, arguments, etc) whilst `valkey-io/valkey-doc` provides the command description and the command reply.
67+
`valkey-io/valkey`, `valkey-io/valkey-bloom` and `valkey-io/valkey-json` provides the command metadata (items like computational complexity, version history, arguments, etc) whilst `valkey-io/valkey-doc` provides the command description and the command reply.
6868

6969
```mermaid
7070
flowchart TD
@@ -75,13 +75,13 @@ flowchart TD
7575
H --> J[Files: /resp2_replies.json,<br/>/resp3_replies.json] --> Z[Command Reply]
7676
```
7777

78-
Let's say that this repo and your local copy of `valkey-io/valkey-doc`, `valkey-io/valkey-bloom` and `valkey-io/valkey` reside in the same directories.
78+
Let's say that this repo and your local copy of `valkey-io/valkey-doc`, `valkey-io/valkey-bloom`, `valkey-io/valkey-json`, and `valkey-io/valkey` reside in the same directories.
7979
First, stop the `zola serve` process if you're running it.
8080
From the root directory of this repo run:
8181

8282
```shell
8383
# You should only need to run this once or when you add a new command.
84-
./build/init-commands.sh ../valkey-doc/commands ../valkey/src/commands ../valkey-bloom/src/commands
84+
./build/init-commands.sh ../valkey-doc/commands ../valkey/src/commands ../valkey-bloom/src/commands ../valkey-json/src/commands
8585
```
8686

8787
Then, restart Zola.

build-json-command-json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../valkey-json/src/commands

build/init-commands.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,15 @@ if [ ! -d "$3" ]; then
2929
exit 1
3030
fi
3131

32+
if [ ! -d "$4" ]; then
33+
echo "The JSON module command JSON directory must exist and be a valid path"
34+
exit 1
35+
fi
36+
3237
ln -s $1 ./build-command-docs
3338
ln -s $2 ./build-command-json
3439
ln -s $3 ./build-bloom-command-json
40+
ln -s $4 ./build-json-command-json
3541
for fname in $(find $1 -maxdepth 1 -iname "*.md")
3642
do
3743
base=${fname##*/}
@@ -42,6 +48,8 @@ do
4248
metadata_path="/commands/$command.json in the 'valkey' repo"
4349
elif [ -f "$3/$command.json" ]; then
4450
metadata_path="/commands/$command.json in the 'valkey-bloom' repo"
51+
elif [ -f "$4/$command.json" ]; then
52+
metadata_path="/commands/$command.json in the 'valkey-json' repo"
4553
fi
4654
cat << EOF > "./content/commands/$command.md"
4755
+++

config.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ highlight_code = true
2222
command_description_path = "../build-command-docs/"
2323
command_json_path = "../build-command-json/"
2424
command_bloom_json_path = "../build-bloom-command-json/"
25+
command_json_json_path = "../build-json-command-json/"
2526
client_json_path = "../build-clients/"
2627
doc_topic_path = "../build-topics/"
2728

content/blog/2025-04-27-valkey-modules-rust-sdk-updates.md

Lines changed: 41 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,25 @@ authors= ["dmitrypol"]
66
categories= "modules"
77
+++
88

9-
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.
9+
In an earlier [article](/blog/modules-101/) we explored the process of building Valkey Modules to enable developers to add features such as new commands and data types to Valkey without modifying its core.
1010
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.
1111
In this follow-up article, we’ll dive deeper into the SDK and highlight several new features and improvements introduced over the past year.
12+
This article assumes that the reader is well familiar with Rust and Valkey modules.
1213

1314
## What is the Valkey Modules Rust SDK?
1415

15-
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.
16+
The SDK is based on [Redis Modules Rust SDK](https://github.com/RedisLabsModules/redismodule-rs) and provides abstraction APIs on top of Valkey's own modules API.
1617
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.
17-
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.
18-
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.
19-
Let's deep dive into to new features.
18+
It requires the underlying Valkey server to have appropriate module APIs but allows writing Valkey modules in Rust, without needing to use raw pointers or unsafe code.
19+
The recently released [Bloom Filters module](/blog/introducing-bloom-filters/) is built using this SDK and several of the developers who worked on the module contributed to the SDK.
20+
Let's deep dive into the new features.
2021

2122
## Client
2223

23-
`Context` struct now has several new functions to get information about the client connected to Valkey.
24+
We begin with enhancements that give developers deeper insight into the clients connected to Valkey.
25+
The `Context` struct has been extended with several new functions that allow retrieving client specific data, such as client name, username or IP address.
2426
It provides Rust wrappers around `Module_GetClient*` functions in the underlying Valkey Module API.
25-
Most new functions return `ValkeyResult` so the module developer can handle the error appropriately.
27+
Most of these new functions return `ValkeyResult` so that the module developer can handle the error appropriately.
2628
The functions can be called for the current client or by specifying `client_id`.
2729

2830
```rust
@@ -41,8 +43,9 @@ valkey_module! {
4143

4244
## Auth callback
4345

44-
Valkey 7.2 introduced support for callbacks after authentication.
45-
Now it can be leveraged in modules.
46+
Another key improvement is support for authentication callbacks introduced in Valkey 7.2.
47+
Thanks to the new features in the SDK Rust modules can now integrate directly with Valkey's auth flow, making it possible to implement custom authentication logic or enhance security policies on a per-client basis.
48+
One potential use case is to combine it with `ctx.get_client_ip` function described above to allow some users access only from specific IP addresses.
4649

4750
```rust
4851
fn auth_callback(
@@ -51,7 +54,6 @@ fn auth_callback(
5154
_password: ValkeyString,
5255
) -> Result<c_int, ValkeyError> {
5356
if ctx.authenticate_client_with_acl_user(&username) == Status::Ok {
54-
// can be combined with ctx.get_client_ip to control access by IP address
5557
let _client_ip = ctx.get_client_ip()?;
5658
...
5759
return Ok(AUTH_HANDLED);
@@ -66,10 +68,10 @@ valkey_module! {
6668

6769
## Preload validation
6870

69-
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.
70-
That can be useful but what if we wanted to stop module load before any of that happens?
71+
While the `valkey_module!` macro already provided an `init` callback to execute custom code during module load, it executed at the very end of the module load after new commands and data types were created.
72+
That can be useful but what if we wanted to stop module load before any of that happened?
7173
For example, we might need to restrict a module to be loaded only on specific version of Valkey.
72-
That's where the optional `preload` is useful.
74+
That's where the optional `preload` comes in.
7375

7476
```rust
7577
fn preload_fn(ctx: &Context, _args: &[ValkeyString]) -> Status {
@@ -86,9 +88,10 @@ valkey_module! {
8688

8789
## Filters
8890

89-
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.
91+
To execute custom code before specific Valkey commands we can use command filters which is now supported in the SDK.
92+
Filters can be leveraged to replace default commands with custom comands or modify arguments.
9093
Thanks to the abstractions provided by the SDK we simply need to create a Rust function and register it in the `valkey_module!` macro.
91-
Note of caution - since filters are executed before every command this code needs to be optimized.
94+
Note of caution - since filters are executed before every command this code needs to be optimized for performance.
9295

9396
```rust
9497
fn my_filter_fn(_ctx: *mut RedisModuleCommandFilterCtx) {
@@ -114,7 +117,9 @@ valkey_module! {
114117

115118
## New event handlers
116119

117-
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.
120+
Reacting to server events can be very important to the module behavior.
121+
The SDK has expanded its support for registering event handlers, allowing developers to hook into more server-side events.
122+
We can use this to execute our own code on client connect/disconnect, server shutdown or specific key events.
118123

119124
```rust
120125
#[client_changed_event_handler]
@@ -141,7 +146,9 @@ fn key_event_handler(ctx: &Context, key_event: KeyChangeSubevent) {
141146

142147
## Custom ACL categories support
143148

144-
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.
149+
Valkey 8 introduced support for custom ACL categories which simplifies access control for custom commands introduced in a module.
150+
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.
151+
Then we can restrict our custom commands to these custom ACL categories.
145152

146153
```rust
147154
valkey_module! {
@@ -158,7 +165,10 @@ valkey_module! {
158165

159166
## Validating / Rejecting CONFIG SET
160167

161-
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.
168+
Configuration flexibility is important but so is validation.
169+
The SDK now supports specifying optional callback functions to validate or reject custom configuations.
170+
This is available for `String`, `i64`, `bool` and `enum` configs.
171+
Here is an example of such validation for i64 custom config.
162172

163173
```rust
164174
lazy_static! {
@@ -188,7 +198,9 @@ valkey_module! {
188198

189199
## Defrag
190200

191-
There is a new `Defrag` struct abstracting away the raw C FFI calls to implement defrag for custom data types.
201+
For memory-sensitive applications, defragmentation is essential.
202+
The SDK now offers a safe and idiomatic Rust abstraction over the defrag API for custom data types.
203+
The new `Defrag` struct abstracts away the raw C FFI calls.
192204

193205
```rust
194206
static MY_VALKEY_TYPE: ValkeyType = ValkeyType::new(
@@ -219,7 +231,8 @@ valkey_module! {
219231

220232
## Redis support
221233

222-
There is a new feature flag if your module needs to run on both Valkey and Redis.
234+
Need your module to work with both Valkey and recent versions Redis?
235+
The SDK includes a compatibility feature flag to ensure your module runs on both Valkey and Redis.
223236
Specify `use-redismodule-api` so that module used RedisModule API Initialization for backwards compatibility.
224237

225238
```rust
@@ -232,7 +245,10 @@ cargo build --release --features use-redismodule-api
232245

233246
## Unit tests and memory allocation
234247

235-
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`.
248+
This feature enables writing unit tests to run outside of Valkey or Redis.
249+
Instead of using Vakey Allocator it relies on the System Allocator.
250+
Unit tests allow us to perform much more granular testing and execute much faster.
251+
The core logic lives in `alloc.rs` but developers only need to specify this feature in the module `Cargo.toml`.
236252

237253
```rust
238254
[features]
@@ -245,15 +261,15 @@ cargo test --features enable-system-alloc
245261

246262
The Valkey Modules Rust SDK has seen exciting improvements over the past year, making it easier and more powerful to extend Valkey.
247263
But we are not stopping.
248-
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.
249-
Additionally, the introduction of crontab scheduling will allow executing custom logic on a defined schedule using cron_event_handler.
264+
Some of the ideas for future development include [mock context support for unit testing](https://github.com/valkey-io/valkeymodule-rs/issues/202), [enhanced context access within filters](https://github.com/valkey-io/valkeymodule-rs/issues/203), and [environment specific configs](https://github.com/valkey-io/valkeymodule-rs/issues/204) to streamline development and testing.
265+
Additionally, the introduction of [crontab scheduling](https://github.com/valkey-io/valkeymodule-rs/issues/205) will allow executing custom logic on a defined schedules using `cron_event_handler`.
250266

251267
We hope this overview helped you understand how to leverage the SDK and inspired you to explore what's possible with Valkey modules.
252268
Stay tuned for future updates.
253269

254-
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).
270+
We also want to express appreciation to the engineers who contributed 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).
255271

256-
## Usefull links
272+
## Useful links
257273

258274
* [Valkey repo](https://github.com/valkey-io/valkey)
259275
* [Valkey Modules Rust SDK](https://github.com/valkey-io/valkeymodule-rs)

sass/_valkey.scss

Lines changed: 78 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -345,33 +345,81 @@ p {
345345
}
346346

347347
.footer {
348-
border-top: 1px solid $grey-dk-100;
349-
background-color: $grey-lt-300;
348+
background-color: #1a2026;
350349
@include sans-serif;
351350
font-size: 1.4rem;
351+
color: #fff;
352+
padding: 2rem 0;
353+
354+
.icon-links {
355+
display: flex;
356+
flex-direction: column;
357+
gap: 15px;
358+
359+
@include respond-min(768px) {
360+
flex-direction: row;
361+
border: none;
362+
}
363+
364+
a {
365+
display: flex;
366+
align-items: center;
367+
color: #fff;
368+
369+
&:hover {
370+
color: #fff;
371+
text-decoration: underline;
372+
opacity: 0.8;
373+
}
374+
375+
img {
376+
margin-right: 5px;
377+
}
378+
}
379+
380+
}
352381

353382
.links {
354383
display: flex;
355-
flex-flow: row nowrap;
356-
justify-content: space-evenly;
357-
margin-bottom: 4em;
384+
flex-direction: column;
385+
gap: 15px;
386+
justify-content: flex-end;
387+
border-top: 1px solid rgba(255, 255, 255, 0.08);
388+
margin-top: 2rem;
389+
padding-top: 2rem;
390+
391+
@include respond-min(768px) {
392+
flex-direction: row;
393+
border: none;
394+
margin-top: 0;
395+
padding-top: 0;
396+
}
397+
398+
a {
399+
color: #fff;
400+
text-decoration: underline;
401+
402+
&:hover {
403+
opacity: 0.8;
404+
}
405+
}
358406
}
359407

360-
nav {
361-
font-size: 1.5rem;
362-
font-weight: 600;
408+
&_bottom {
409+
width: 100%;
410+
margin-top: 2rem;
411+
padding: 2rem;
363412

364-
h4 {
365-
font-weight: 400;
366-
@include sans-serif;
367-
font-size: 1.5rem;
413+
border-top: 1px solid rgba(255, 255, 255, 0.08);
414+
text-align: center;
415+
416+
p {
417+
max-width: 720px;
418+
margin: 8px auto;
368419
}
369420

370421
a {
371-
display: list-item;
372-
list-style: none;
373-
white-space: nowrap;
374-
margin-bottom: 1em;
422+
color: #6983ff;
375423

376424
&:hover {
377425
text-decoration: underline;
@@ -410,28 +458,35 @@ p {
410458

411459
.col {
412460
flex: 1 1 100%;
413-
padding: 0 2rem;
461+
padding-left: 2rem;
462+
padding-right: 2rem;
414463
}
415464

416465
.col-10 {
417-
flex: 1 1 83.33%;
466+
@include respond-min(768px) {
467+
flex: 1 1 83.33%;
468+
}
418469
}
419470

420471
.col-8 {
421-
flex: 1 1 66.66%;
472+
@include respond-min(768px) {
473+
flex: 1 1 66.66%;
474+
}
422475
}
423476

424477
.col-6 {
425-
flex: 1 1 50%;
478+
@include respond-min(768px) {
479+
flex: 1 1 50%;
480+
}
426481
}
427482

428483
.col-4 {
429-
flex: 1 1 33.33%;
484+
@include respond-min(768px) {
485+
flex: 1 1 33.33%;
486+
}
430487
}
431488

432489
.col_3 {
433-
flex: 1 1 100%;
434-
435490
@include respond-min(768px) {
436491
flex: 1 1 25%;
437492
}

0 commit comments

Comments
 (0)