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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
//! A redis client implemented in Rust. It's create is called "redis-client".
//! 
//! # Connection
//!
//! All the clients are created with a host and a port:
//! 
//! ```plain
//! try!(client::new("127.0.0.1", "6379"));
//! ```
//! They are trying to connect when they are created and the new method return a Result with either the client or a RedisError.
//!
//! # The clients
//! 
//! There is more than one client in the library.
//!
//! ## RedisClient
//! 
//! It is used to execute redis commands synchronously.
//!
//! For example:
//!
//! ```no_run
//! # use redis_client::commands::CommandSender;
//! # fn function() -> Result<(), redis_client::errors::RedisError> {
//! # let mut client = try!(redis_client::RedisClient::new("127.0.0.1", "6379"));
//! let result: String = try!(client.set("key", "value"));
//! # Ok(())}
//! ```
//!
//! ## RedisClientAsync
//!
//! It is used to execute redis commands synchronously.
//!
//! For example:
//!
//! ```no_run
//! # use redis_client::commands::CommandSenderAsync;
//! # fn function() -> Result<(), redis_client::errors::RedisError> {
//! # let mut async_client = try!(redis_client::RedisClientAsync::new("127.0.0.1", "6379"));
//! try!(async_client.get("key", |result| {
//!    let result_value: String  = match result {
//!        Ok(value) => value.into(),
//!        Err(err) => err.to_string(),
//!    };
//!    println!("{:?}", result_value);
//! }));
//! # Ok(())}
//! ```
//! To get the callback to be called once the command execution is over, the pump method needs to be called.
//!
//! ## PubSubClientAsync
//!
//! It is used for redis Pub/Sub functionnality.
//!
//! For example:
//!
//! ```no_run
//! # use redis_client::commands::PubSubCommandAsync;
//! # fn function() -> Result<(), redis_client::errors::RedisError> {
//! # let mut pubsub_client = try!(redis_client::PubSubClientAsync::new("127.0.0.1", "6379"));
//! try!(pubsub_client.subscribe("foo", |cmd_result| {
//! 		let cmd_result_value: String  = match cmd_result {
//! 			Ok(value) => value.into(),
//! 			Err(err) => err.to_string(),
//! 		};
//! 		println!("{:?}", cmd_result_value);
//! 	}, |received_value| {
//! 		println!("{:?}", received_value);
//! 	}
//! ));
//!
//! try!(pubsub_client.publish("foo", "message", |cmd_result| {
//! 		let cmd_result_value: String  = match cmd_result {
//! 			Ok(value) => value.into(),
//! 			Err(err) => err.to_string(),
//! 		};
//! 		println!("{:?}", cmd_result_value);
//! 	}
//! ));
//! # Ok(())}
//! ```
//! The first closure in every method is the one that will be called once the command execution ends. For the subscription methods, the second closure which is the
//! subscription callback, will be called once a value is received on the required channels. To trigger these calls, the pump method needs to be called. 
//! (NOTE: as multiple value may be received between two calls of the pump method, a subscription callback may be triggered more than once when te pump method is called.)
//!
//! # Commands
//!	 
//! ## Built-in Commands
//! 
//! They are the redis commands implemented in the traits CommandBuilder to build a RedisCommand, or in CommandSender and CommandSenderAsync to send them.
//! 
//! For example:
//!
//! ```no_run
//! # use redis_client::commands::CommandBuilder;
//! # fn function() -> Result<(), redis_client::errors::RedisError> {
//! # let mut client = try!(redis_client::RedisClient::new("127.0.0.1", "6379"));
//! # let mut async_client = try!(redis_client::RedisClientAsync::new("127.0.0.1", "6379"));
//! let cmd = &mut redis_client::RedisCommand::new();
//! cmd.get("key");
//! 
//! let result: String = try!(client.exec_redis_command(cmd)).into();
//! 
//! try!(async_client.exec_redis_command_async(cmd, |result| {
//!    let result_value: String  = match result {
//!        Ok(value) => value.into(),
//!        Err(err) => err.to_string(),
//!    };
//!    println!("{:?}", result_value);
//! }));
//! # Ok(())}
//! ```
//!
//! Is the same as:
//!
//! ```no_run
//! # use redis_client::commands::{CommandSender, CommandSenderAsync};
//! # fn function() -> Result<(), redis_client::errors::RedisError> {
//! # let mut client = try!(redis_client::RedisClient::new("127.0.0.1", "6379"));
//! # let mut async_client = try!(redis_client::RedisClientAsync::new("127.0.0.1", "6379"));
//! let result: String = try!(client.get("key"));
//! 
//! try!(async_client.get("key", |result| {
//!    let result_value: String  = match result {
//!        Ok(value) => value.into(),
//!        Err(err) => err.to_string(),
//!    };
//!    println!("{:?}", result_value);
//! }));
//! # Ok(())}
//! ```
//! Some redis commands can have an argument with one or more values. For these ones the rules is to implement two built-in commands, 
//! one for the single value case that have the name of the redis commands and another for the multiple values case with the same name but 
//! prefixed by a m.
//! 
//! For example:
//!
//! ```no_run
//! # use redis_client::commands::CommandSender;
//! # fn function() -> Result<(), redis_client::errors::RedisError> {
//! # let mut client = try!(redis_client::RedisClient::new("127.0.0.1", "6379"));
//! let result: String = try!(client.del("key"));
//! 
//! let mresult: String = try!(client.mdel(vec!["key1", "key2"]));
//! # Ok(())}
//! ```
//! Another rule is when a redis commands has behavioral arguments, extra built-in commands are created.
//! For example:
//!
//! ```no_run
//! # use redis_client::commands::CommandSender;
//! # fn function() -> Result<(), redis_client::errors::RedisError> {
//! # let mut client = try!(redis_client::RedisClient::new("127.0.0.1", "6379"));
//! let result: String = try!(client.setxx("key", "value")); // SET command with the XX argument
//! # Ok(())}
//! ```
//! In the case a behavioral argument is mandatory, only the built-in commands with the arguments are created.
//! For example lindex has an argument that is either AFTER or BEFORE:
//!
//! ```no_run
//! # use redis_client::commands::CommandSender;
//! # fn function() -> Result<(), redis_client::errors::RedisError> {
//! # let mut client = try!(redis_client::RedisClient::new("127.0.0.1", "6379"));
//! let aresult: String = try!(client.linsert_after("key", "pivot", "value")); // LINSERT with AFTER has an argument
//! let bresult: String = try!(client.linsert_before("key", "pivot", "value")); // LINSERT  with BEFORE has an argument
//! // let eresult: String = try!(client.linsert("key", "pivot", "value")); DOES NOT EXIST
//! # Ok(())}
//! ```
//! ## Custom Commands
//! 
//! It is also possible to build custom command and execute them.
//! 
//! For example:
//!
//! ```no_run
//! # use redis_client::commands::CommandBuilder;
//! # fn function() -> Result<(), redis_client::errors::RedisError> {
//! # let mut client = try!(redis_client::RedisClient::new("127.0.0.1", "6379"));
//! # let mut async_client = try!(redis_client::RedisClientAsync::new("127.0.0.1", "6379"));
//! let cmd = &mut redis_client::RedisCommand::new();
//! cmd.add_cmd("GET").add_arg("key").end();
//! 
//! let result: String = try!(client.exec_redis_command(cmd)).into();
//! 
//! try!(async_client.exec_redis_command_async(cmd, |result| {
//!    let result_value: String  = match result {
//!        Ok(value) => value.into(),
//!        Err(err) => err.to_string(),
//!    };
//!    println!("{:?}", result_value);
//! }));
//! # Ok(())}
//! ```
//! # Pipeline
//!
//! To execute a command pipeline you simply need to create a RedisCommand with one or more redis commands and execute it with a client's pipeline method.
//! The only difference with the execution of a single command is that the Result contains a vector of RedisResult instead of just a RedisResult.
//!
//! Example:
//!
//! ```no_run
//! # use redis_client::commands::CommandBuilder;
//! # fn function() -> Result<(), redis_client::errors::RedisError> {
//! # let mut client = try!(redis_client::RedisClient::new("127.0.0.1", "6379"));
//! # let mut async_client = try!(redis_client::RedisClientAsync::new("127.0.0.1", "6379"));
//! let cmd = &mut redis_client::RedisCommand::new();
//! cmd.set("key", "value2").get("key");
//! 
//! let results = try!(client.exec_redis_pipeline_command(cmd)); // results is a Vec<RedisResult>
//! 
//! try!(async_client.exec_redis_pipeline_command_async(cmd, |results| {
//! 	match results {
//!  		Ok(values) => {
//!   			for value in values {
//!      			println!("{:?}", value.convert::<String>())
//!     		}
//!  		},
//!     	Err(err) => println!("{:?}", err.to_string()),
//!   	};
//! }));
//! # Ok(())}
//! ```
//! 
//! # Redis Transaction
//! The transaction commands are part of the built-in commands and therefore can be used like any other commmands.

pub use errors::{ParsingError, RedisError};
pub use redis::{PubSubClientAsync, RedisClient, RedisClientAsync};
pub use results::RedisResult;
pub use commands::{CommandBuilder, CommandSender, CommandSenderAsync, PubSubCommandAsync, RedisCommand};

pub mod commands;
pub mod errors;
pub mod reader;
pub mod redis;
pub mod results;
pub mod types;