Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors seen while using AsyncRedisCache #136

Open
rajesh-blueshift opened this issue Dec 6, 2022 · 0 comments
Open

Errors seen while using AsyncRedisCache #136

rajesh-blueshift opened this issue Dec 6, 2022 · 0 comments

Comments

@rajesh-blueshift
Copy link

rajesh-blueshift commented Dec 6, 2022

Hi, I am a newbie to rust, I am trying to create a module based on this the example given for AsyncRedisCache

use cached::proc_macro::io_cached;
use cached::AsyncRedisCache;
use thiserror::Error;

#[derive(Error, Debug, PartialEq, Clone)]
enum ExampleError {
    #[error("error with redis cache `{0}`")]
    RedisError(String),
}

/// Cache the results of an async function in redis. Cache
/// keys will be prefixed with `cache_redis_prefix`.
/// A `map_error` closure must be specified to convert any
/// redis cache errors into the same type of error returned
/// by your function. All `io_cached` functions must return `Result`s.
#[io_cached(
    map_error = r##"|e| ExampleError::RedisError(format!("{:?}", e))"##,
    type = "AsyncRedisCache<u64, String>",
    create = r##" {
        AsyncRedisCache::new("cached_redis_prefix", 1)
            .set_refresh(true)
            .build()
            .await
            .expect("error building example redis cache")
    } "##
)]
async fn async_cached_sleep_secs(secs: u64) -> Result<String, ExampleError> {
    std::thread::sleep(std::time::Duration::from_secs(secs));
    Ok(secs.to_string())
}

However, I get following errors:

`*const AsyncRedisCache<u64, std::string::String>` cannot be sent between threads safely
the trait `std::marker::Send` is not implemented for `*const AsyncRedisCache<u64, std::string::String>`
required because of the requirements on the impl of `std::marker::Send` for `Cell<*const AsyncRedisCache<u64, std::string::String>>`
required because of the requirements on the impl of `std::marker::Sync` for `spin::once::Once<AsyncOnce<AsyncRedisCache<u64, std::string::String>>>`
shared static variables must have a type that implements `Sync`

Am I missing something?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant