mirror of
https://github.com/actix/examples
synced 2024-11-23 22:41:07 +01:00
added delete operations
This commit is contained in:
parent
7ccde8c2d3
commit
aff38dc15b
@ -4,11 +4,12 @@ is so can be read at https://github.com/benashford/redis-async-rs/issues/19#issu
|
||||
|
||||
|
||||
|
||||
To test the demo, POST a json object containing three strings to the /cache_stuff endpoint:
|
||||
To test the demo, POST a json object containing three strings to the /stuff endpoint:
|
||||
{"one": "first entry",
|
||||
"two": "second entry",
|
||||
"three": "third entry" }
|
||||
|
||||
|
||||
|
||||
These three entries will cache to redis, keyed accordingly.
|
||||
|
||||
to delete these, simply issue a DELETE http request to /stuff endpoint
|
||||
|
@ -59,6 +59,22 @@ fn cache_stuff((info, req): (Json<CacheInfo>, HttpRequest<AppState>))
|
||||
.responder()
|
||||
}
|
||||
|
||||
fn del_stuff(req: HttpRequest<AppState>)
|
||||
-> impl Future<Item=HttpResponse, Error=AWError> {
|
||||
let redis = req.state().redis_addr.clone();
|
||||
|
||||
redis.send(Command(resp_array!["DEL", "mydomain:one", "mydomain:two", "mydomain:three"]))
|
||||
.map_err(AWError::from)
|
||||
.and_then(|res: Result<RespValue, ARError>|
|
||||
match &res {
|
||||
Ok(RespValue::Integer(x)) if x==&3 =>
|
||||
Ok(HttpResponse::Ok().body("successfully deleted values")),
|
||||
_ =>{println!("---->{:?}", res);
|
||||
Ok(HttpResponse::InternalServerError().finish())}
|
||||
})
|
||||
.responder()
|
||||
|
||||
}
|
||||
|
||||
pub struct AppState {
|
||||
pub redis_addr: Arc<Addr<RedisActor>>
|
||||
@ -75,8 +91,12 @@ fn main() {
|
||||
|
||||
App::with_state(app_state)
|
||||
.middleware(middleware::Logger::default())
|
||||
.resource("/cache_stuff", |r| r.method(Method::POST)
|
||||
.with_async(cache_stuff))
|
||||
.resource("/stuff", |r| {
|
||||
r.method(Method::POST)
|
||||
.with_async(cache_stuff);
|
||||
r.method(Method::DELETE)
|
||||
.with_async(del_stuff)})
|
||||
|
||||
}).bind("0.0.0.0:8080")
|
||||
.unwrap()
|
||||
.workers(1)
|
||||
|
Loading…
Reference in New Issue
Block a user