Skip to content

Commit

Permalink
document and coerce redis connection url
Browse files Browse the repository at this point in the history
  • Loading branch information
colemickens committed Jun 23, 2018
1 parent f57790e commit 3141adf
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ keytext BROKER_KEYTEXT (none)
=============== ==================== ================
``config.toml`` Environment Variable Default
=============== ==================== ================
url BROKER_REDIS_URL (none)
url BROKER_REDIS_URL (none) (example: redis://localhost:6379)
session_ttl BROKER_SESSION_TTL 900 (15 minutes)
cache_ttl BROKER_CACHE_TTL 3600 (1 hour)
=============== ==================== ================
Expand Down
2 changes: 1 addition & 1 deletion config.toml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ keytext =


[redis]
# Redis connection URL - Default: (mandatory, CHANGE THIS)
# Redis connection URL - Default: (mandatory, CHANGE THIS) (example: redis://localhost, redis://localhost:6379/0)
url =
# Time that users have to complete authentication - Default: 900 (15 minutes)
session_ttl = 900
Expand Down
15 changes: 12 additions & 3 deletions src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,18 @@ pub struct Store {

impl Store {
pub fn new(url: &str, expire_sessions: usize, expire_cache: usize)
-> Result<Store, &'static str> {
match redis::Client::open(url) {
Err(_) => Err("error opening store connection"),
-> Result<Store, String> {
let mut url = url.to_string();
if url.starts_with("http://") {
url = url.replace("http://", "redis://");
} else if !url.starts_with("redis://") {
url = format!("redis://{}", &url);
}
match redis::Client::open(url.as_str()) {
Err(e) => {
let f = format!("error opening store connection: {} (url={})", e, url);
Err(f)
},
Ok(client) => Ok(Store { client, expire_sessions, expire_cache }),
}
}
Expand Down

0 comments on commit 3141adf

Please sign in to comment.