|
1 | | -use deadpool_redis::{ |
2 | | - // Very important to import inner redis - otherwise macro expansion fails! |
3 | | - redis, |
4 | | - redis::{AsyncCommands, ErrorKind, RedisError, RedisResult}, |
5 | | - Config, |
6 | | - Runtime, |
7 | | -}; |
8 | | -use redis_macros::{FromRedisValue, ToRedisArgs}; |
9 | | -use serde::{Deserialize, Serialize}; |
| 1 | +// TODO: COMMENTED OUT UNTIL DEADPOOL REDIS CATCHES UP WITH REDIS 1.0 |
| 2 | +// use deadpool_redis::{ |
| 3 | +// // Very important to import inner redis - otherwise macro expansion fails! |
| 4 | +// redis, |
| 5 | +// redis::{AsyncCommands, ErrorKind, RedisError, RedisResult}, |
| 6 | +// Config, |
| 7 | +// Runtime, |
| 8 | +// }; |
| 9 | +// use redis_macros::{FromRedisValue, ToRedisArgs}; |
| 10 | +// use serde::{Deserialize, Serialize}; |
| 11 | +use redis::RedisResult; |
10 | 12 |
|
11 | | -/// Define structs to hold the data |
12 | | -/// Children structs don't have to implement FromRedisValue, ToRedisArgs, unless you want to use them as top level |
13 | | -/// They have to implement serde traits though! |
14 | | -#[derive(Debug, PartialEq, Serialize, Deserialize)] |
15 | | -enum Address { |
16 | | - Street(String), |
17 | | - Road(String), |
18 | | -} |
| 13 | +// /// Define structs to hold the data |
| 14 | +// /// Children structs don't have to implement FromRedisValue, ToRedisArgs, unless you want to use them as top level |
| 15 | +// /// They have to implement serde traits though! |
| 16 | +// #[derive(Debug, PartialEq, Serialize, Deserialize)] |
| 17 | +// enum Address { |
| 18 | +// Street(String), |
| 19 | +// Road(String), |
| 20 | +// } |
19 | 21 |
|
20 | | -/// Don't forget to implement serde traits and redis traits! |
21 | | -#[derive(Debug, PartialEq, Serialize, Deserialize, FromRedisValue, ToRedisArgs)] |
22 | | -struct User { |
23 | | - id: u32, |
24 | | - name: String, |
25 | | - addresses: Vec<Address>, |
26 | | -} |
| 22 | +// /// Don't forget to implement serde traits and redis traits! |
| 23 | +// #[derive(Debug, PartialEq, Serialize, Deserialize, FromRedisValue, ToRedisArgs)] |
| 24 | +// struct User { |
| 25 | +// id: u32, |
| 26 | +// name: String, |
| 27 | +// addresses: Vec<Address>, |
| 28 | +// } |
27 | 29 |
|
28 | 30 | /// Show a simple async usage of redis_macros traits |
29 | 31 | /// Just derive the traits and forget them! |
30 | 32 | #[tokio::main] |
31 | 33 | async fn main() -> RedisResult<()> { |
32 | | - // Open new async connection to localhost |
33 | | - let cfg = Config::from_url("redis://localhost:6379"); |
| 34 | + // // Open new async connection to localhost |
| 35 | + // let cfg = Config::from_url("redis://localhost:6379"); |
34 | 36 |
|
35 | | - let pool = cfg.create_pool(Some(Runtime::Tokio1)).unwrap(); |
36 | | - let mut con = pool.get().await.map_err(|_| { |
37 | | - RedisError::from(( |
38 | | - ErrorKind::InvalidClientConfig, |
39 | | - "Cannot connect to localhost:6379. Try starting a redis-server process or container.", |
40 | | - )) |
41 | | - })?; |
| 37 | + // let pool = cfg.create_pool(Some(Runtime::Tokio1)).unwrap(); |
| 38 | + // let mut con = pool.get().await.map_err(|_| { |
| 39 | + // RedisError::from(( |
| 40 | + // ErrorKind::InvalidClientConfig, |
| 41 | + // "Cannot connect to localhost:6379. Try starting a redis-server process or container.", |
| 42 | + // )) |
| 43 | + // })?; |
42 | 44 |
|
43 | | - // Define the data you want to store in Redis. |
44 | | - let user = User { |
45 | | - id: 1, |
46 | | - name: "Ziggy".to_string(), |
47 | | - addresses: vec![ |
48 | | - Address::Street("Downing".to_string()), |
49 | | - Address::Road("Abbey".to_string()), |
50 | | - ], |
51 | | - }; |
| 45 | + // // Define the data you want to store in Redis. |
| 46 | + // let user = User { |
| 47 | + // id: 1, |
| 48 | + // name: "Ziggy".to_string(), |
| 49 | + // addresses: vec![ |
| 50 | + // Address::Street("Downing".to_string()), |
| 51 | + // Address::Road("Abbey".to_string()), |
| 52 | + // ], |
| 53 | + // }; |
52 | 54 |
|
53 | | - // Set and get back the user in Redis asynchronously, no problem |
54 | | - let _: () = con.set("user_deadpool", &user).await?; |
55 | | - let stored_user: User = con.get("user_deadpool").await?; |
| 55 | + // // Set and get back the user in Redis asynchronously, no problem |
| 56 | + // let _: () = con.set("user_deadpool", &user).await?; |
| 57 | + // let stored_user: User = con.get("user_deadpool").await?; |
56 | 58 |
|
57 | | - // You will get back the same data |
58 | | - assert_eq!(user, stored_user); |
| 59 | + // // You will get back the same data |
| 60 | + // assert_eq!(user, stored_user); |
59 | 61 |
|
60 | 62 | Ok(()) |
61 | 63 | } |
|
0 commit comments