This project demonstrates how to use Redis with WebAssembly (Wasm) using Rust. Unfortunately, this code won't work natively due to the wasm sandbox having tight security. I am currently working on a fix for this but not guarantee on the release date!
Before running the code, make sure you have the following installed:
- Rust: https://www.rust-lang.org/tools/install
- Redis: https://redis.io/topics/quickstart
- wasm-pack: https://rustwasm.github.io/wasm-pack/installer/
Follow these steps to run the code:
-
Clone the repository:
git clone https://github.com/your-username/redis-wasm.git
-
Navigate to the project directory:
cd redis-wasm
-
Build the WebAssembly module using wasm-pack:
wasm-pack build --target web
-
Start the Redis server. You can refer to the Redis documentation for instructions on starting the server based on your platform.
-
Run the index.html code with a server like live preview in VS Code or http-server from python.
The Rust code in this project interacts with Redis using the redis crate. It provides two exported functions that can be called from JavaScript:
get_redis_key: Retrieves the value of a Redis key. It takes the Redis host, port, and key as input and returns the corresponding value.
increment_redis_key: Increments the value of a Redis key. It takes the Redis host, port, and key as input and increments the value by 1. The Wasm module can be used in a web environment by including the generated JavaScript glue code (redis_wasm.js) and Wasm binary (redis_wasm_bg.wasm) in your HTML file.