Last active
June 26, 2022 16:39
-
-
Save kulicuu/f99c1f5bf0a0f0ad816c78c9e84666bf to your computer and use it in GitHub Desktop.
parsing BulkString in RespValue of Actix-Redis
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
name = "actix_redis_cli_000" | |
version = "0.1.0" | |
edition = "2021" | |
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | |
[dependencies] | |
bytes = "1.0" | |
actix = "0.13.0" | |
actix-web = "4.1.0" | |
actix-web-actors = "4.1.0" | |
actix-files = "0.6" | |
actix-redis = "0.11.0" | |
redis-async = "0.13.0" | |
tokio = { version = "1.19.2", features = ["full"] } | |
tokio-util = { version = "0.7.3", features = [ "full" ] } | |
env_logger = "0.9" | |
log = "0.4" | |
rand = "0.8" | |
serde = "1" | |
serde_json = "1" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::string::String; | |
use actix_redis::{Command, Error, RedisActor, RespValue, resp_array}; | |
#[actix::main] | |
async fn main() { | |
let addr = RedisActor::start("127.0.0.1:6379"); | |
let res = addr.send(Command(resp_array!["SET", "AA33", "ZAiNAR"])).await; | |
println!("res {:?}", res); | |
match res { | |
Ok(Ok(resp)) => { | |
println!("command set {:?}", resp); | |
} | |
_ => { | |
println!("else") | |
} | |
} | |
let res = addr.send(Command(resp_array!["GET", "AA33"])).await; | |
let val = match res { | |
Ok(Ok(RespValue::BulkString(sv))) => String::from_utf8(sv).unwrap(), | |
_ => String::from("null") | |
}; | |
println!("val {:?}", val); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment