MCPcopy Create free account
hub / github.com/actix/examples / cache_stuff

Function cache_stuff

databases/redis/src/main.rs:27–51  ·  view source on GitHub ↗
(
    web::Json(info): web::Json<CacheInfo>,
    redis: web::Data<redis::Client>,
)

Source from the content-addressed store, hash-verified

25}
26
27async fn cache_stuff(
28 web::Json(info): web::Json<CacheInfo>,
29 redis: web::Data<redis::Client>,
30) -> actix_web::Result<impl Responder> {
31 let mut conn = redis
32 .get_connection_manager()
33 .await
34 .map_err(error::ErrorInternalServerError)?;
35
36 let res = redis::Cmd::mset(&[
37 ("my_domain:one", info.one),
38 ("my_domain:two", info.two),
39 ("my_domain:three", info.three),
40 ])
41 .query_async::<String>(&mut conn)
42 .await
43 .map_err(error::ErrorInternalServerError)?;
44
45 // not strictly necessary, but successful SET operations return "OK"
46 if res == "OK" {
47 Ok(HttpResponse::Ok().body("successfully cached values"))
48 } else {
49 Ok(HttpResponse::InternalServerError().finish())
50 }
51}
52
53async fn del_stuff(redis: web::Data<redis::Client>) -> actix_web::Result<impl Responder> {
54 let mut conn = redis

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected