Skip to content

Commit

Permalink
Add support for zmpop (#605)
Browse files Browse the repository at this point in the history
  • Loading branch information
gkorland committed May 25, 2022
1 parent e96bb7b commit c1e3c97
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
12 changes: 12 additions & 0 deletions src/commands.rs
Expand Up @@ -813,6 +813,18 @@ implement_commands! {
cmd("ZPOPMIN").arg(key).arg(count)
}

/// Removes and returns up to count members with the highest scores,
/// from the first non-empty sorted set in the provided list of key names.
fn zmpop_max<K: ToRedisArgs>(keys: &'a [K], count: isize) {
cmd("ZMPOP").arg(keys.len()).arg(keys).arg("MAX").arg("COUNT").arg(count)
}

/// Removes and returns up to count members with the lowest scores,
/// from the first non-empty sorted set in the provided list of key names.
fn zmpop_min<K: ToRedisArgs>(keys: &'a [K], count: isize) {
cmd("ZMPOP").arg(keys.len()).arg(keys).arg("MIN").arg("COUNT").arg(count)
}

/// Return up to count random members in a sorted set (or 1 if `count == None`)
fn zrandmember<K: ToRedisArgs>(key: K, count: Option<isize>) {
cmd("ZRANDMEMBER").arg(key).arg(count)
Expand Down
6 changes: 1 addition & 5 deletions src/connection.rs
Expand Up @@ -867,11 +867,7 @@ impl ConnectionLike for Connection {
}
}

if let Some(err) = first_err {
Err(err)
} else {
Ok(rv)
}
first_err.map_or(Ok(rv), Err)
}

fn get_db(&self) -> i64 {
Expand Down
2 changes: 1 addition & 1 deletion src/streams.rs
Expand Up @@ -190,7 +190,7 @@ impl ToRedisArgs for StreamReadOptions {

if let Some(ref group) = self.group {
// noack is only available w/ xreadgroup
if let Some(true) = self.noack {
if self.noack == Some(true) {
out.write_arg(b"NOACK");
}

Expand Down
2 changes: 1 addition & 1 deletion src/types.rs
Expand Up @@ -1263,7 +1263,7 @@ impl FromRedisValue for InfoDict {

impl<T: FromRedisValue> FromRedisValue for Option<T> {
fn from_redis_value(v: &Value) -> RedisResult<Option<T>> {
if let Value::Nil = *v {
if *v == Value::Nil {
return Ok(None);
}
Ok(Some(from_redis_value(v)?))
Expand Down

0 comments on commit c1e3c97

Please sign in to comment.