1
0
mirror of https://github.com/actix/actix-extras.git synced 2025-01-23 07:14:35 +01:00

43 lines
1.2 KiB
Rust
Raw Normal View History

2018-01-22 22:28:29 -08:00
#[macro_use]
extern crate redis_async;
2018-05-08 10:12:57 -07:00
use actix_redis::{Command, Error, RedisActor, RespValue};
2018-01-22 22:28:29 -08:00
2019-12-15 23:46:03 +06:00
#[actix_rt::test]
async fn test_error_connect() {
2018-01-22 22:28:29 -08:00
let addr = RedisActor::start("localhost:54000");
let _addr2 = addr.clone();
2019-12-15 23:46:03 +06:00
let res = addr.send(Command(resp_array!["GET", "test"])).await;
match res {
Ok(Err(Error::NotConnected)) => (),
_ => panic!("Should not happen {:?}", res),
}
2018-01-22 22:28:29 -08:00
}
2019-12-15 23:46:03 +06:00
#[actix_rt::test]
async fn test_redis() {
2018-01-22 22:28:29 -08:00
env_logger::init();
let addr = RedisActor::start("127.0.0.1:6379");
2019-12-15 23:46:03 +06:00
let res = addr
.send(Command(resp_array!["SET", "test", "value"]))
.await;
match res {
Ok(Ok(resp)) => {
assert_eq!(resp, RespValue::SimpleString("OK".to_owned()));
2018-01-22 22:28:29 -08:00
2019-12-15 23:46:03 +06:00
let res = addr.send(Command(resp_array!["GET", "test"])).await;
match res {
2018-01-22 22:28:29 -08:00
Ok(Ok(resp)) => {
2019-12-15 23:46:03 +06:00
println!("RESP: {:?}", resp);
assert_eq!(resp, RespValue::BulkString((&b"value"[..]).into()));
2018-05-08 10:12:57 -07:00
}
2018-01-22 22:28:29 -08:00
_ => panic!("Should not happen {:?}", res),
2019-12-15 23:46:03 +06:00
}
}
_ => panic!("Should not happen {:?}", res),
}
2018-01-22 22:28:29 -08:00
}