January 2019
Intermediate to advanced
520 pages
14h 32m
English
Our actor has to keep an instance of Client. We don't use a connection pool, because we will use multiple actors for handing parallel requests to a database. Look at the following struct:
pub struct CacheActor { client: Client, expiration: usize,}
The struct also contains an expiration field that holds the time-to-live (TTL) period. This defines how long Redis will hold the value.
Add a new method to the implementation that uses a provided address string to create a Client instance, and adds both the client and expiration values to the CacheActor struct, as follows:
impl CacheActor { pub fn new(addr: &str, expiration: usize) -> Self { let client = Client::open(addr).unwrap(); Self { client, expiration } }}
Also, we have to implement ...
Read now
Unlock full access