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