Skip to content

Commit

Permalink
inserted -> created
Browse files Browse the repository at this point in the history
  • Loading branch information
gillchristian committed Oct 20, 2024
1 parent 283fc76 commit 7db8830
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/commands/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl Executable for Keys {
let matching_keys = store
.iter()
.filter(|(key, _)| glob_match(self.pattern.as_str(), key))
.sorted_by(|(_, a), (_, b)| b.inserted_at.cmp(&a.inserted_at))
.sorted_by(|(_, a), (_, b)| b.created_at.cmp(&a.created_at))
.map(|(key, _)| Frame::Bulk(Bytes::from(key.to_string())))
.collect::<Vec<_>>();

Expand Down
15 changes: 6 additions & 9 deletions src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ impl<'a> InnerStoreLocked<'a> {
// Ensure any previous TTL is removed.
let removed = self.remove(&key);

let inserted_at = removed.map(|v| v.inserted_at).unwrap_or(Instant::now());
let created_at = removed.map(|v| v.created_at).unwrap_or(Instant::now());

let value = Value {
data,
expires_at: None,
inserted_at,
created_at,
};
self.state.keys.insert(key, value);
}
Expand All @@ -75,13 +75,13 @@ impl<'a> InnerStoreLocked<'a> {
// Ensure any previous TTL is removed.
let removed = self.remove(&key);

let inserted_at = removed.map(|v| v.inserted_at).unwrap_or(Instant::now());
let created_at = removed.map(|v| v.created_at).unwrap_or(Instant::now());

let expires_at = Instant::now() + ttl;
let value = Value {
data,
expires_at: Some(expires_at),
inserted_at,
created_at,
};

self.state.keys.insert(key.clone(), value);
Expand Down Expand Up @@ -149,10 +149,7 @@ impl<'a> InnerStoreLocked<'a> {
}

pub fn iter(&self) -> impl Iterator<Item = (&String, &Value)> {
self.state
.keys
.iter()
.map(|(key, value)| (key, value))
self.state.keys.iter().map(|(key, value)| (key, value))
}

pub fn incr_by<T, R>(&mut self, key: &str, increment: T) -> Result<R, String>
Expand Down Expand Up @@ -238,7 +235,7 @@ type Key = String;
pub struct Value {
pub data: Bytes,
pub expires_at: Option<Instant>,
pub inserted_at: Instant,
pub created_at: Instant,
}

pub struct State {
Expand Down

0 comments on commit 7db8830

Please sign in to comment.