Skip to content

A simple rust app that monitors how many times a user has refreshed a the page and reads/writes this value to and from a redis server.

Notifications You must be signed in to change notification settings

diva-in-STEM/rust-refresh-app

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Redis WebAssembly

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!

Prerequisites

Before running the code, make sure you have the following installed:

Getting Started

Follow these steps to run the code:

  1. Clone the repository:

    git clone https://github.com/your-username/redis-wasm.git
    
  2. Navigate to the project directory:

    cd redis-wasm
    
  3. Build the WebAssembly module using wasm-pack:

    wasm-pack build --target web
  4. Start the Redis server. You can refer to the Redis documentation for instructions on starting the server based on your platform.

  5. Run the index.html code with a server like live preview in VS Code or http-server from python.

Code Explanation

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.

About

A simple rust app that monitors how many times a user has refreshed a the page and reads/writes this value to and from a redis server.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published