Skip to content

Commit 5680241

Browse files
committed
add some initial docs
1 parent 678fc2a commit 5680241

File tree

4 files changed

+96
-9
lines changed

4 files changed

+96
-9
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,4 @@ jobs:
6969
run: cargo fmt --all -- --check
7070

7171
- name: Docs
72-
run: cargo doc --no-deps --features unstable
72+
run: cargo doc --no-deps

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,8 @@ edition = "2018"
88
redis = { version = "0.16.0", features = ["aio"] }
99
async-session = "1.0.2"
1010

11+
[dev-dependencies]
12+
async-std = { version = "1.6.2", features = ["attributes"] }
13+
1114
[patch.crates-io]
1215
async-session = { git = "https://github.com/jbr/async-session", branch = "tide" }

README.md

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,40 @@
1-
# Async-Redis-Session
1+
# async-redis-session
2+
## redis-backed session store for [async-session](https://github.com/http-rs/async-session)
23

3-
This is a redis session store for [async-session](https://github.com/http-rs/async-session/)!
4+
## ⚠️ Note: This crate is not yet published, so nothing in this readme will actually work yet ⚠️
5+
check out the status of https://github.com/http-rs/async-session/pull/2 for the latest
46

5-
Here's what needs to be done next:
7+
* [API Docs][docs] [![docs.rs docs][docs-badge]][docs]
8+
* [Releases][releases] [![crates.io version][version-badge]][lib-rs]
9+
* [Contributing][contributing]
610

7-
- [ ] write rustdocs
8-
- [ ] write tests
9-
- [ ] publish crate
11+
[releases] https://github.com/jbr/async-redis-session/releases
12+
[docs] https://docs.rs/async-redis-session
13+
[contributing] https://github.com/jbr/async-redis-session/blob/master/.github/CONTRIBUTING.md
14+
[lib-rs] https://lib.rs/async-redis-session
15+
[docs-badge] https://img.shields.io/badge/docs-latest-blue.svg?style=flat-square
16+
[version-badge] https://img.shields.io/crates/v/async-redis-session.svg?style=flat-square
17+
18+
## Installation
19+
```sh
20+
$ cargo add async-redis-session
21+
```
22+
23+
## Safety
24+
This crate uses ``#![deny(unsafe_code)]`` to ensure everything is implemented in
25+
100% Safe Rust.
26+
27+
## License
28+
29+
<sup>
30+
Licensed under either of <a href="LICENSE-APACHE">Apache License, Version
31+
2.0</a> or <a href="LICENSE-MIT">MIT license</a> at your option.
32+
</sup>
33+
34+
<br/>
35+
36+
<sub>
37+
Unless you explicitly state otherwise, any contribution intentionally submitted
38+
for inclusion in this crate by you, as defined in the Apache-2.0 license, shall
39+
be dual licensed as above, without any additional terms or conditions.
40+
</sub>

src/lib.rs

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,79 @@
1+
//! # async-redis-session
2+
//! ```rust
3+
//! use async_redis_session::RedisSessionStore;
4+
//! use async_session::{Session, SessionStore};
5+
//!
6+
//! # fn main() -> async_session::Result { async_std::task::block_on(async {
7+
//! let store = RedisSessionStore::new("redis://127.0.0.1/")?;
8+
//!
9+
//! let session = Session::new();
10+
//! session.insert("key".into(), "value".into());
11+
//!
12+
//! let cookie_value = store.store_session(session).await.unwrap();
13+
//! let session = store.load_session(cookie_value).await.unwrap();
14+
//! assert_eq!(session.get("key").unwrap(), "value");
15+
//! # Ok(()) }) }
16+
//! ```
17+
18+
#![forbid(unsafe_code, future_incompatible)]
19+
#![deny(
20+
missing_debug_implementations,
21+
nonstandard_style,
22+
missing_docs,
23+
unreachable_pub,
24+
missing_copy_implementations,
25+
unused_qualifications
26+
)]
27+
128
use async_session::{async_trait, serde_json, Result, Session, SessionStore};
229
use redis::{aio::Connection, AsyncCommands, Client, IntoConnectionInfo, RedisResult};
330

31+
/// # RedisSessionStore
432
#[derive(Clone, Debug)]
533
pub struct RedisSessionStore {
634
client: Client,
735
prefix: Option<String>,
836
}
937

1038
impl RedisSessionStore {
39+
/// creates a redis store from an existing [`redis::Client`]
40+
/// ```rust
41+
/// # use async_redis_session::RedisSessionStore;
42+
/// let client = redis::Client::open("redis://127.0.0.1").unwrap();
43+
/// let store = RedisSessionStore::from_client(client);
44+
/// ```
1145
pub fn from_client(client: Client) -> Self {
1246
Self {
1347
client,
1448
prefix: None,
1549
}
1650
}
1751

52+
/// creates a redis store from a [`redis::IntoConnectionInfo`]
53+
/// such as a [`String`], [`&str`](str), or [`Url`](../url/struct.Url.html)
54+
/// ```rust
55+
/// # use async_redis_session::RedisSessionStore;
56+
/// let store = RedisSessionStore::new("redis://127.0.0.1").unwrap();
57+
/// ```
1858
pub fn new(connection_info: impl IntoConnectionInfo) -> RedisResult<Self> {
1959
Ok(Self::from_client(Client::open(connection_info)?))
2060
}
2161

22-
pub fn with_prefix(mut self, prefix: String) -> Self {
23-
self.prefix = Some(prefix);
62+
/// sets a key prefix for this session store
63+
///
64+
/// ```rust
65+
/// # use async_redis_session::RedisSessionStore;
66+
/// let store = RedisSessionStore::new("redis://127.0.0.1").unwrap()
67+
/// .with_prefix("async-sessions/");
68+
/// ```
69+
/// ```rust
70+
/// # use async_redis_session::RedisSessionStore;
71+
/// let client = redis::Client::open("redis://127.0.0.1").unwrap();
72+
/// let store = RedisSessionStore::from_client(client)
73+
/// .with_prefix("async-sessions/");
74+
/// ```
75+
pub fn with_prefix(mut self, prefix: impl AsRef<str>) -> Self {
76+
self.prefix = Some(prefix.as_ref().to_owned());
2477
self
2578
}
2679

0 commit comments

Comments
 (0)