Skip to content

Commit

Permalink
hget for mock
Browse files Browse the repository at this point in the history
  • Loading branch information
aamalev committed Feb 5, 2025
1 parent 48e130f commit 3b46a2f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,22 @@ impl Pool for MockRedis {
}
redis::Value::Array(result)
}
Some(b"HGET") => {
let mut result = redis::Value::Nil;
if let Some(key) = cmd_iter.next() {
let values = self.values.read().await;
if let Some(Value {
value: InnerValue::Map(m),
..
}) = values.get(key)
{
if let Some(v) = cmd_iter.next().and_then(|f| m.get(f)) {
result = v.clone();
}
};
}
result
}
Some(b"HEXISTS") => {
let mut result = false;
if let Some(key) = cmd_iter.next() {
Expand All @@ -420,9 +436,7 @@ impl Pool for MockRedis {
}) = values.get(key)
{
if let Some(f) = cmd_iter.next() {
if m.contains_key(f) {
result = true;
}
result = m.contains_key(f);
}
};
}
Expand Down
8 changes: 8 additions & 0 deletions tests/test_h.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,11 @@ async def test_hmget(async_client: redis_rs.AsyncClient):
assert n == 3
result = await async_client.hmget(key, "x", "z", encoding="int")
assert result == [2, 4]


async def test_hget(async_client: redis_rs.AsyncClient):
key = str(uuid4())
n = await async_client.hset(key, "x", "2", "y", b"3", "z", 4)
assert n == 3
result = await async_client.hget(key, "x", encoding="int")
assert result == 2

0 comments on commit 3b46a2f

Please sign in to comment.