Skip to content

Commit

Permalink
finish the list commands
Browse files Browse the repository at this point in the history
  • Loading branch information
AsoSunag committed Feb 6, 2016
1 parent ac15139 commit f17d54b
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 0 deletions.
60 changes: 60 additions & 0 deletions src/commands.rs
Expand Up @@ -177,6 +177,37 @@ generate_command_traits!{
add_arg(end_range);
}

fn blpop<K: ToString>(key: K, timeout: u32) {
add_cmd("BLPOP");
add_arg(key);
add_arg(timeout);
}

fn mblpop<K: ToString>(keys: Vec<K>, timeout: u32) {
add_cmd("BLPOP");
add_args(keys);
add_arg(timeout);
}

fn brpop<K: ToString>(key: K, timeout: u32) {
add_cmd("BRPOP");
add_arg(key);
add_arg(timeout);
}

fn mbrpop<K: ToString>(keys: Vec<K>, timeout: u32) {
add_cmd("BRPOP");
add_args(keys);
add_arg(timeout);
}

fn brpoplpush<S: ToString, D: ToString>(source: S, dest: D, timeout: u32) {
add_cmd("BRPOPLPUSH");
add_arg(source);
add_arg(dest);
add_arg(timeout);
}

fn decr<K: ToString>(key: K) {
add_cmd("DECR");
add_arg(key);
Expand Down Expand Up @@ -341,6 +372,22 @@ generate_command_traits!{
add_arg(index);
}

fn linsert_after<K: ToString, P: ToString, V: ToString>(key: K, pivot: P, value: V) {
add_cmd("LINSERT");
add_arg(key);
add_arg("AFTER");
add_arg(pivot);
add_arg(value);
}

fn linsert_before<K: ToString, P: ToString, V: ToString>(key: K, pivot: P, value: V) {
add_cmd("LINSERT");
add_arg(key);
add_arg("BEFORE");
add_arg(pivot);
add_arg(value);
}

fn llen<K: ToString>(key: K) {
add_cmd("LLEN");
add_arg(key);
Expand Down Expand Up @@ -390,6 +437,13 @@ generate_command_traits!{
add_arg(value);
}

fn ltrim<K: ToString>(key: K, start: i32, end: i32) {
add_cmd("LTRIM");
add_arg(key);
add_arg(start);
add_arg(end);
}

fn multi() {
add_cmd("MULTI");
}
Expand All @@ -411,6 +465,12 @@ generate_command_traits!{
add_arg(key);
}

fn rpoplpush<S: ToString, D: ToString>(source: S, dest: D) {
add_cmd("RPOPLPUSH");
add_arg(source);
add_arg(dest);
}

fn rpush<K: ToString, V: ToString>(key: K, value: V) {
add_cmd("RPUSH");
add_arg(key);
Expand Down
72 changes: 72 additions & 0 deletions tests/commands.rs
Expand Up @@ -70,6 +70,46 @@ fn bitcount_range_cmd_works() {
check_result(cmd.into(), b"BITCOUNT key -1 1\r\n");
}

#[test]
fn blpop_cmd_works() {
let cmd = &mut RedisCommand::new();
cmd.blpop("key", 10);

check_result(cmd.into(), b"BLPOP key 10\r\n");
}

#[test]
fn mblpop_cmd_works() {
let cmd = &mut RedisCommand::new();
cmd.mblpop(vec!["key1", "key2"], 10);

check_result(cmd.into(), b"BLPOP key1 key2 10\r\n");
}

#[test]
fn brpop_cmd_works() {
let cmd = &mut RedisCommand::new();
cmd.brpop("key", 10);

check_result(cmd.into(), b"BRPOP key 10\r\n");
}

#[test]
fn mbrpop_cmd_works() {
let cmd = &mut RedisCommand::new();
cmd.mbrpop(vec!["key1", "key2"], 10);

check_result(cmd.into(), b"BRPOP key1 key2 10\r\n");
}

#[test]
fn brpoplpush_cmd_works() {
let cmd = &mut RedisCommand::new();
cmd.brpoplpush("source", "dest", 10);

check_result(cmd.into(), b"BRPOPLPUSH source dest 10\r\n");
}

#[test]
fn decr_cmd_works() {
let cmd = &mut RedisCommand::new();
Expand Down Expand Up @@ -306,6 +346,22 @@ fn lindex_cmd_works() {
check_result(cmd.into(), b"LINDEX key 2\r\n");
}

#[test]
fn linsert_after_cmd_works() {
let cmd = &mut RedisCommand::new();
cmd.linsert_after("key", "pivot", "value");

check_result(cmd.into(), b"LINSERT key AFTER pivot value\r\n");
}

#[test]
fn linsert_before_cmd_works() {
let cmd = &mut RedisCommand::new();
cmd.linsert_before("key", "pivot", "value");

check_result(cmd.into(), b"LINSERT key BEFORE pivot value\r\n");
}

#[test]
fn llen_cmd_works() {
let cmd = &mut RedisCommand::new();
Expand Down Expand Up @@ -370,6 +426,14 @@ fn lset_cmd_works() {
check_result(cmd.into(), b"LSET key 1 value\r\n");
}

#[test]
fn ltrim_cmd_works() {
let cmd = &mut RedisCommand::new();
cmd.ltrim("key", 1, -1);

check_result(cmd.into(), b"LTRIM key 1 -1\r\n");
}

#[test]
fn multi_cmd_works() {
let cmd = &mut RedisCommand::new();
Expand Down Expand Up @@ -402,6 +466,14 @@ fn rpop_cmd_works() {
check_result(cmd.into(), b"RPOP key\r\n");
}

#[test]
fn rpoplpush_cmd_works() {
let cmd = &mut RedisCommand::new();
cmd.rpoplpush("key", "value");

check_result(cmd.into(), b"RPOPLPUSH key value\r\n");
}

#[test]
fn rpush_cmd_works() {
let cmd = &mut RedisCommand::new();
Expand Down

0 comments on commit f17d54b

Please sign in to comment.