Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

finish connections commands

  • Loading branch information...
commit 527cb8cf53982a4badd1cf65247725b6683204d5 1 parent 352e5da
Yecheng Fu authored
Showing with 104 additions and 4 deletions.
  1. +1 −0  TODO
  2. +90 −2 lib/Redis.pm
  3. +13 −2 t/02-commands.t
1  TODO
View
@@ -1,5 +1,6 @@
Commands
- sort
+* fixbug: use recv on IO::Socket instead get
* complete method signatures
* support debug & timeout options
92 lib/Redis.pm
View
@@ -21,7 +21,7 @@ my &integer_reply_cb = { $_.Bool };
my &string_to_float_cb = { $_.Real };
my %command_callbacks = ();
%command_callbacks{"PING"} = { $_ eq "PONG" };
-for "QUIT SET MSET PSETEX SETEX MIGRATE RENAME RENAMENX RESTORE HMSET".split(" ") -> $c {
+for "AUTH QUIT SET MSET PSETEX SETEX MIGRATE RENAME RENAMENX RESTORE HMSET SELECT".split(" ") -> $c {
%command_callbacks{$c} = &status_code_reply_cb;
}
for "EXISTS SETNX EXPIRE EXPIREAT MOVE PERSIST PEXPIRE PEXPIREAT HSET HEXISTS HSETNX".split(" ") -> $c {
@@ -153,6 +153,16 @@ method !parse_response($response, $command) {
return $response;
}
+####### Commands/Connection #######
+
+method auth(Str $password) returns Bool {
+ return self!exec_command("AUTH", $password);
+}
+
+method echo($message) returns Str {
+ return self!exec_command("ECHO", $message);
+}
+
# Ping the server.
method ping returns Bool {
return self!exec_command("PING");
@@ -163,6 +173,12 @@ method quit returns Bool {
return self!exec_command("QUIT");
}
+method select(Int $index) returns Bool {
+ return self!exec_command("SELECT", $index);
+}
+
+####### Commands/Connection #######
+
###### Commands/Keys #######
method del(*@keys) returns Int {
@@ -238,7 +254,7 @@ method restore(Str $key, Int $milliseconds, Str $serialized-value) returns Bool
}
method sort(Str $key, Str :$by?,
- Int :$offset?, Int :$count?,
+ Int :$offset?, Int :$count?,
:@get?,
Bool :$desc = False,
Bool :$alpha = False,
@@ -431,4 +447,76 @@ method hvals(Str $key) returns Array {
###### ! Commands/Hashes ######
+###### Commands/Lists ######
+
+method blpop(Int $timeout, *@keys) returns Any {
+ return self!exec_command("BLPOP", |@keys, $timeout);
+}
+
+method brpop(Int $timeout, *@keys) returns Any {
+ return self!exec_command("BRPOP", |@keys, $timeout);
+}
+
+method brpoplpush(Str $source, Str $destination, Int $timeout) returns Any {
+ return self!exec_command("BRPOPLPUSH", $source, $destination, $timeout);
+}
+
+method lindex(Str $key, Int $index) returns Any {
+ return self!exec_command("LINDEX", $key, $index);
+}
+
+method linsert(Str $key, Str $where where { $where eq any(["BEFORE", "AFTER"]) }, $pivot, $value) returns Any {
+ # TODO
+}
+
+method llen(Str $key) returns Int {
+ return self!exec_command("LLEN", $key);
+}
+
+method lpop(Str $key) returns Any {
+ return self!exec_command("LPOP", $key);
+}
+
+method lpush(Str $key, *@values) returns Int {
+ return self!exec_command("LPUSH", $key, |@values);
+}
+
+method lpushx(Str $key, *@values) returns Int {
+ return self!exec_command("LPUSHX", $key, |@values);
+}
+
+method lrange(Str $key, Int $start, Int $stop) returns Array {
+ return self!exec_command("LRANGE", $key, $start, $stop);
+}
+
+method lrem(Str $key, Int $count, $value) returns Int {
+ return self!exec_command("LREM", $key, $count, $value);
+}
+
+method lset(Str $key, Int $index, $value) {
+ return self!exec_command("LSET", $key, $index, $value);
+}
+
+method ltrim(Str $key, Int $start, Int $stop) {
+ return self!exec_command("LTRIM", $key, $start, $stop);
+}
+
+method rpop(Str $key) returns Any {
+ return self!exec_command("RPOP", $key);
+}
+
+method rpoplpush(Str $source, Str $destination) {
+ return self!exec_command("RPOPLPUSH", $source, $destination);
+}
+
+method rpush(Str $key, *@values) {
+ return self!exec_command("RPUSH", |@values);
+}
+
+method rpushx(Str $key, $value) {
+ return self!exec_command("RPUSHX", $value);
+}
+
+###### ! Commands/Lists ######
+
# vim: ft=perl6
15 t/02-commands.t
View
@@ -140,7 +140,7 @@ is_deeply $r.rename("key", "newkey"), True;
# renamenx
{
- my $failed = 1;
+ my $failed = 0;
try {
$r.renamenx("does_not_exists", "newkey");
CATCH {
@@ -192,8 +192,19 @@ is_deeply $r.hvals("hash"), ["value2", "21.1"];
###### Commands/Connection #######
-
+{
+ my $failed = 0;
+ try {
+ $r.auth("WRONG PASSWORD");
+ CATCH {
+ default { $failed = 1 }
+ }
+ }
+ ok $failed;
+}
+is_deeply $r.echo("Hello World!"), "Hello World!";
is_deeply $r.ping, True;
+is_deeply $r.select(2), True;
is_deeply $r.quit, True;
###### ! Commands/Connection #######
Please sign in to comment.
Something went wrong with that request. Please try again.