Skip to content

Azure-Samples/azure-redis-cache-rust-quickstart

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Quickstart: Use Azure Cache for Redis with Rust

This sample shows how you can use the Rust programming language for interacting with Azure Cache for Redis. It will demonstrate examples of commonly used Redis data structures such as STRING, HASH, LIST etc. using the redis-rs library for Redis. This client exposes both high and low-level APIs and you will see both these styles in action.

Pre-requisites

Clone the sample application

Start by cloning the application from GitHub.

  1. Open a command prompt and create a new folder named git-samples.

    md "C:\git-samples"
  2. Open a git terminal window, such as git bash. Use the cd command to change into the new folder where you will be cloning the sample app.

    cd "C:\git-samples"
  3. Run the following command to clone the sample repository. This command creates a copy of the sample app on your computer.

    git clone https://github.com/Azure-Samples/azure-redis-cache-rust-quickstart.git

Run the application

The application accepts connectivity and credentials in the form of environment variables.

  1. Fetch the Host name and Access Keys (available via Access Keys) for Azure Cache for Redis instance in the Azure portal

  2. Set them to the respective environment variables:

    set REDIS_HOSTNAME=<Host name>:<port> (e.g. <name of cache>.redis.cache.windows.net:6380)
    set REDIS_PASSWORD=<Primary Access Key>
  3. In the terminal window, change to the correct folder. For example:

    cd "C:\git-samples\azure-redis-cache-rust-quickstart"
  4. In the terminal, run the following command to start the application.

    cargo run

    You will see an output as such:

    ******* Running SET, GET, INCR commands *******
    value for 'foo' = bar
    counter = 2
    ******* Running HASH commands *******
    info for rust redis driver: {"name": "redis-rs", "repo": "https://github.com/mitsuhiko/redis-rs", "version": "0.19.0"}
    go redis driver repo name: "https://github.com/go-redis/redis"
    ******* Running LIST commands *******
    first item: item-1
    no. of items in list = 2
    listing items in list
    item: item-2
    item: item-3
    ******* Running SET commands *******
    does user1 exist in the set? true
    listing users in set
    user: user2
    user: user1
    user: user3
    ******* Running SORTED SET commands *******
    listing players and scores
    player-2 = 2
    player-4 = 4
    player-1 = 7
    player-5 = 6
    player-3 = 8

    If you want to run a specific function, comment out other functions in the main function:

    fn main() {
        basics();
        hash();
        list();
        set();
        sorted_set();
    }

Resources

About

Rust quick start for Azure Cache for Redis

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages