1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//! Redis storage and message publishing.
//!
//! To receive Redis messages, use the Redis trigger.
//!
//! # Examples
//!
//! Get a value from the Redis database.
//!
//! ```no_run
//! use spin_sdk::redis::Connection;
//!
//! # fn main() -> anyhow::Result<()> {
//! let conn = Connection::open("redis://127.0.0.1:6379")?;
//! let payload = conn.get("archimedes-data")?;
//! if let Some(data) = payload {
//! println!("{}", String::from_utf8_lossy(&data));
//! }
//! # Ok(())
//! # }
//! ```
//!
//! See the [`Connection`] type for further examples.
use ;
/// An open connection to a Redis server.
///
/// # Examples
///
/// Get a value from the Redis database.
///
/// ```no_run
/// use spin_sdk::redis::Connection;
///
/// # fn main() -> anyhow::Result<()> {
/// let conn = Connection::open("redis://127.0.0.1:6379")?;
/// let payload = conn.get("archimedes-data")?;
/// if let Some(data) = payload {
/// println!("{}", String::from_utf8_lossy(&data));
/// }
/// # Ok(())
/// # }
/// ```
///
/// Set a value in the Redis database.
///
/// ```no_run
/// use spin_sdk::redis::Connection;
///
/// # fn main() -> anyhow::Result<()> {
/// let conn = Connection::open("redis://127.0.0.1:6379")?;
/// let payload = "Eureka!".to_owned().into_bytes();
/// conn.set("archimedes-data", &payload)?;
/// # Ok(())
/// # }
/// ```
///
/// Delete a value from the Redis database.
///
/// ```no_run
/// use spin_sdk::redis::Connection;
///
/// # fn main() -> anyhow::Result<()> {
/// let conn = Connection::open("redis://127.0.0.1:6379")?;
/// conn.del(&["archimedes-data".to_owned()])?;
/// # Ok(())
/// # }
/// ```
///
/// Publish a message to a Redis channel.
///
/// ```no_run
/// use spin_sdk::redis::Connection;
///
/// # fn ensure_pet_picture(_: &[u8]) -> anyhow::Result<()> { Ok(()) }
/// # fn use_redis(request: spin_sdk::http::Request) -> anyhow::Result<()> {
/// let conn = Connection::open("redis://127.0.0.1:6379")?;
///
/// let payload = request.body().to_vec();
/// ensure_pet_picture(&payload)?;
///
/// conn.publish("pet-pictures", &payload)?;
/// # Ok(())
/// # }
/// ```
pub use Connection;
pub use ;