-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat: Add redis backend #813
Open
p1gp1g
wants to merge
21
commits into
mozilla-services:master
Choose a base branch
from
p1gp1g:feat/redis
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
b902543
Update yanked futures-utils
p1gp1g 1152f7f
Add redis backend
p1gp1g 2659043
Add docker-compose to self host the project
p1gp1g 7118d5c
Remove useless ignore()
p1gp1g 32098b3
Wipe expired messages
p1gp1g 7df5533
Don't use `unwrap()`
p1gp1g f676ee7
Move redis import under feature flag
p1gp1g e86452c
Actually use Uaid and Chanid wrappers
p1gp1g 4529e74
Change emoji for redis logs
p1gp1g 193defb
Clean up some comments
p1gp1g 1d34450
Use standard chidmessageid
p1gp1g 03bdbe8
Rename docker-compose for redis
p1gp1g a8167cd
Fix settings tests with redis
p1gp1g 12c741d
Use multiplexed connection with redis
p1gp1g 8a9b146
Remove unused dep
p1gp1g e133a00
Set potentially different chidmessageid for tests notifs
p1gp1g 83ebc3c
Remove unnecessary topic entry
p1gp1g 4dfd29d
Store MultiplexedConnection as expected by redis
p1gp1g f2f6d03
Fix loop when fetching pending messages
p1gp1g 837a426
Merge branch 'master' into feat/redis
jrconlin 00866ac
Fix comments
p1gp1g File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bigtable
andredis
are conflicting feature flags, no?If you like, we do a conditional check in syncstorage-rs to prevent folk from accidentally specifying both flags.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They should not be conflicting, the server is selected with the dsn url
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, the actual database selection is non-conflicting, but the compilation is not. I don't know of a situation where someone might want to have both Bigtable and Redis support enabled on the back end at the same time, considering that there's only one database you can specify or use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree there is no use case when both are used, but I can see some examples for compiling both. For instance if a generic container image is published/used, or one do a build that can be used in different environments, (dev/tests with redis, integration/prod with bigtable)