pub struct SendEntryOptions { /* private fields */ }Expand description
Set of options that are required by RedisStream::send_entry()
Implementations§
Source§impl SendEntryOptions
impl SendEntryOptions
Sourcepub fn new(stream: String) -> SendEntryOptions
pub fn new(stream: String) -> SendEntryOptions
Examples found in repository?
examples/stream_producer.rs (line 103)
71fn start_producer(rx: UnboundedReceiver<Message>,
72 stream_name: String,
73 group_name: String,
74 redis_address: SocketAddr) {
75 let touch_options = TouchGroupOptions::new(stream_name.clone(), group_name.clone());
76
77 // Try to create a group.
78 // If the group exists already, the future will not be set into an error.
79 // The create_group variable is the Future<Item=(), Error=()>.
80 let create_group = RedisStream::connect(&redis_address)
81 .and_then(move |con|
82 // Create group if the one does not exists yet.
83 con.touch_group(touch_options))
84 .then(|_| -> RedisResult<()> { Ok(()) });
85
86 // Creates and holds a connection to the Redis Server, waits new messages from
87 // the channel receiver (rx) and send them to a Redis stream.
88 //
89 // Note nothing will happen if the previous future has failed.
90 // The producer variable in a result is the Future<Item=(), Error=()>.
91 // The Item and Error are required by tokio::run().
92 let producer = create_group
93 .and_then(move |_| {
94 RedisStream::connect(&redis_address)
95 })
96 .and_then(move |producer| {
97 rx
98 .map_err(|_|
99 RedisError::new(RedisErrorKind::InternalError,
100 "Something went wrong with UnboundedChannel".to_string()))
101 // Use fold() to redirect messages from the channel receiver (rx) to the Redis stream.
102 .fold(producer, move |producer, message| {
103 let options = SendEntryOptions::new(stream_name.clone());
104
105 // Serialize the message to pairs of key-value.
106 let data = message.into_redis_stream_entry();
107
108 producer
109 .send_entry(options, data)
110 .map(|(producer, added_entry_id)| {
111 println!("{:?} has sent", added_entry_id.to_string());
112 println!("Please enter a message");
113 producer
114 })
115 })
116 })
117 .map(|_| ())
118 .map_err(|err| println!("{}", err));
119
120 tokio::run(producer);
121}pub fn with_id(stream: String, entry_id: EntryId) -> SendEntryOptions
Trait Implementations§
Source§impl Clone for SendEntryOptions
impl Clone for SendEntryOptions
Source§fn clone(&self) -> SendEntryOptions
fn clone(&self) -> SendEntryOptions
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for SendEntryOptions
impl RefUnwindSafe for SendEntryOptions
impl Send for SendEntryOptions
impl Sync for SendEntryOptions
impl Unpin for SendEntryOptions
impl UnwindSafe for SendEntryOptions
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more