-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
1,034 additions
and
21 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
pub fn main() { | ||
if !cfg!(feature = "bigtable") { | ||
panic!("No database defined! Please compile with `features=bigtable`"); | ||
if !cfg!(feature = "bigtable") && !cfg!(feature = "redis") { | ||
panic!("No database defined! Please compile with `features=bigtable` (or redis)"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/// This uses redis as a storage and management | ||
/// system for Autopush Notifications and Routing information. | ||
/// | ||
/// Keys for the data are | ||
/// `autopush/user/{uaid}` String to store the user data | ||
/// `autopush/co/{uaid}` u64 to store the last time the user has interacted with the server | ||
/// `autopush/channels/{uaid}` List to store the list of the channels of the user | ||
/// `autopush/msgs/{uaid}` SortedSet to store the list of the pending message ids for the user | ||
/// `autopush/msgs_exp/{uaid}` SortedSet to store the list of the pending message ids, ordered by expiry date, this is because SortedSet elements can't have independant expiry date | ||
/// `autopush/msg/{uaid}/{chidmessageid}`, with `{chidmessageid} == {chid}:{version}` String to store | ||
/// the content of the messages | ||
/// | ||
mod redis_client; | ||
|
||
pub use redis_client::RedisClientImpl; | ||
|
||
use serde::Deserialize; | ||
use std::time::Duration; | ||
|
||
use crate::db::error::DbError; | ||
use crate::util::deserialize_opt_u32_to_duration; | ||
|
||
/// The settings for accessing the redis contents. | ||
#[derive(Clone, Debug, Deserialize)] | ||
pub struct RedisDbSettings { | ||
#[serde(default)] | ||
#[serde(deserialize_with = "deserialize_opt_u32_to_duration")] | ||
pub timeout: Option<Duration>, | ||
} | ||
|
||
// Used by test, but we don't want available for release. | ||
#[allow(clippy::derivable_impls)] | ||
impl Default for RedisDbSettings { | ||
fn default() -> Self { | ||
Self { | ||
timeout: Default::default(), | ||
} | ||
} | ||
} | ||
|
||
impl TryFrom<&str> for RedisDbSettings { | ||
type Error = DbError; | ||
fn try_from(setting_string: &str) -> Result<Self, Self::Error> { | ||
let me: Self = match serde_json::from_str(setting_string) { | ||
Ok(me) => me, | ||
Err(e) if e.is_eof() => Self::default(), | ||
Err(e) => Err(DbError::General(format!( | ||
"Could not parse DdbSettings: {:?}", | ||
e | ||
)))?, | ||
}; | ||
Ok(me) | ||
} | ||
} | ||
|
||
mod tests { | ||
|
||
#[test] | ||
fn test_settings_parse() -> Result<(), crate::db::error::DbError> { | ||
let settings = super::RedisDbSettings::try_from("{\"timeout\": 123}")?; | ||
assert_eq!(settings.timeout, Some(std::time::Duration::from_secs(123))); | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
use crate::db::error::DbError; | ||
|
||
impl From<serde_json::Error> for DbError { | ||
fn from(err: serde_json::Error) -> Self { | ||
DbError::Serialization(err.to_string()) | ||
} | ||
} |
Oops, something went wrong.