Skip to content

Commit

Permalink
Added 'ping' associated function to check if the server is live or dead!
Browse files Browse the repository at this point in the history
Updated README
  • Loading branch information
younisshah committed Aug 7, 2017
1 parent d059665 commit 9e26c7a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ match n.execute_with_args() {
};
```

4) `PING` to check if the server is live or dead.
```rust
use nazar::t38::{Client};
let is_live = Client::ping("redis://127.0.0.1:9851");
```

## Geofence features

Expand Down
25 changes: 25 additions & 0 deletions src/t38.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,31 @@ impl<'a> Client<'a> {
self
}

/// Pings the Tile38 server running at the given url.
/// It should be used to check if the server is alive or dead!
///
/// # Arguments
///
/// * `url` - URL at which a Tile38 server instance is running
///
/// # Example
/// use nazar::t38::{Client}
/// let is_live = Client::ping("redis://127.0.0.1:9851");
pub fn ping(url: &'a str) -> bool
{
assert!(url != "");
let cmd = redis::cmd("PING");
let result: NazarResult<String> = cmd.query(&get_connection(url).unwrap());
match result {
Ok(r) => {
r == "PONG"
}
Err(_) => {
false
}
}
}

/// execute_with_args executes Tile38 query
pub fn execute_with_args(&self) -> NazarResult<String> {
if !self.cmd.is_empty() {
Expand Down

0 comments on commit 9e26c7a

Please sign in to comment.