Skip to content

Commit dfb48ab

Browse files
committed
better code
1 parent ae5ee5c commit dfb48ab

4 files changed

Lines changed: 8 additions & 13 deletions

File tree

crabdis-core/src/parsers/resp/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ mod tests {
778778

779779
let not_expired = Value::Expire((
780780
Arc::new(Value::String("test".into())),
781-
Instant::now() + Duration::from_secs(60),
781+
Instant::now() + Duration::from_mins(1),
782782
));
783783

784784
assert!(!not_expired.expired());
@@ -811,7 +811,7 @@ mod tests {
811811
let inner = Value::String("test".into());
812812
let expired = Value::Expire((
813813
Arc::new(inner.clone()),
814-
Instant::now() + Duration::from_secs(60),
814+
Instant::now() + Duration::from_mins(1),
815815
));
816816

817817
assert_eq!(expired.inner(), &inner);

crabdis-macros/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "crabdis-macros"
33
description = "Macros for Crabdis"
44
readme = "../README.md"
55
keywords = ["redis", "resp", "protocol", "serialization"]
6-
categories = ["macros", "network-programming"]
6+
categories = ["network-programming"]
77
version.workspace = true
88
edition.workspace = true
99
license.workspace = true

crabdis/src/storage/mod.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ impl RdbConfig {
6969
last_save_time: AtomicU64::new(
7070
std::time::SystemTime::now()
7171
.duration_since(std::time::UNIX_EPOCH)
72-
.map(|d| d.as_secs())
73-
.unwrap_or(0),
72+
.map_or(0, |d| d.as_secs()),
7473
),
7574
bgsave_in_progress: AtomicU64::new(0),
7675
}
@@ -110,8 +109,7 @@ impl RdbConfig {
110109
self.last_save_time.store(
111110
std::time::SystemTime::now()
112111
.duration_since(std::time::UNIX_EPOCH)
113-
.map(|d| d.as_secs())
114-
.unwrap_or(0),
112+
.map_or(0, |d| d.as_secs()),
115113
Ordering::Relaxed,
116114
);
117115
}
@@ -132,8 +130,7 @@ impl RdbConfig {
132130
let last_save = self.last_save_time.load(Ordering::Relaxed);
133131
let now = std::time::SystemTime::now()
134132
.duration_since(std::time::UNIX_EPOCH)
135-
.map(|d| d.as_secs())
136-
.unwrap_or(0);
133+
.map_or(0, |d| d.as_secs());
137134
let elapsed = now.saturating_sub(last_save);
138135

139136
let save_points = self.save_points.read().await;

crabdis/src/storage/rdb.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ pub async fn save_rdb(state: &State) -> Result<()> {
6262
// Try to acquire the save lock (compare-and-swap from 0 to timestamp)
6363
let now = std::time::SystemTime::now()
6464
.duration_since(std::time::UNIX_EPOCH)
65-
.map(|d| d.as_secs())
66-
.unwrap_or(1); // Use 1 as minimum to distinguish from "not in progress"
65+
.map_or(1, |d| d.as_secs()); // Use 1 as minimum to distinguish from "not in progress"
6766

6867
if state
6968
.rdb_config
@@ -128,8 +127,7 @@ pub fn bgsave_rdb(state: Arc<State>) -> Result<()> {
128127
// Try to acquire the save lock (compare-and-swap from 0 to timestamp)
129128
let now = std::time::SystemTime::now()
130129
.duration_since(std::time::UNIX_EPOCH)
131-
.map(|d| d.as_secs())
132-
.unwrap_or(1); // Use 1 as minimum to distinguish from "not in progress"
130+
.map_or(1, |d| d.as_secs()); // Use 1 as minimum to distinguish from "not in progress"
133131

134132
if state
135133
.rdb_config

0 commit comments

Comments
 (0)