Skip to content
Browse files

Merge pull request #7 from JRaspass/master

Fix compilation under Perl 6.c
  • Loading branch information...
2 parents 5a04119 + 2bfbdbd commit 83ce24287ad69d3647cab9d18eae11b2bad7d836 @Cofyc committed
Showing with 102 additions and 102 deletions.
  1. +7 −7 lib/Redis.pm
  2. +2 −2 t/02-keys.t
  3. +16 −16 t/02-lists.t
  4. +5 −5 t/02-scripting.t
  5. +13 −13 t/02-sets.t
  6. +23 −23 t/02-sortedsets.t
  7. +35 −35 t/02-strings.t
  8. +1 −1 t/03-binary.t
View
14 lib/Redis.pm
@@ -30,7 +30,7 @@ Executes arbitrary command.
=end pod
-class Redis;
+unit class Redis;
has Str $.host = '127.0.0.1';
has Int $.port = 6379;
@@ -69,8 +69,8 @@ for "INCRBYFLOAT HINCRBYFLOAT ZINCRBY ZSCORE".split(" ") -> $c {
}
return %h;
};
-%command_callbacks{"INFO"} = {
- my @lines = $_.decode.split("\r\n");
+%command_callbacks{"INFO"} = sub ($info) {
+ my @lines = $info.decode.split("\r\n");
my %info;
for @lines -> $l {
if $l.substr(0, 1) eq "#" {
@@ -85,7 +85,7 @@ for "INCRBYFLOAT HINCRBYFLOAT ZINCRBY ZSCORE".split(" ") -> $c {
has %!command_callbacks = %command_callbacks;
method new(Str $server?, Str :$encoding?, Bool :$decode_response?) {
- my %config = {}
+ my %config := {}
if $server.defined {
if $server ~~ m/^([\d+]+ %\.) [':' (\d+)]?$/ {
%config<host> = $0.Str;
@@ -116,7 +116,7 @@ method reconnect {
}
multi method encode(Str:D $value) returns Buf {
- return $value.encode(self.encoding);
+ return Buf.new($value.encode(self.encoding));
}
multi method encode(Buf:D $value) returns Buf {
@@ -187,7 +187,7 @@ method !read_response returns Any {
}
method !decode_response($response) {
- if $response.WHAT === Buf {
+ if $response.WHAT === Buf[uint8] {
return $response.decode(self.encoding);
} elsif $response.WHAT === Array {
return $response.map( { self!decode_response($_) } ).Array;
@@ -203,7 +203,7 @@ method !decode_response($response) {
}
method !parse_response($response is copy, Str $command) {
- if %!command_callbacks.exists($command) {
+ if %!command_callbacks{$command}:exists {
$response = %!command_callbacks{$command}($response);
}
if self.decode_response and $command !eq any("DUMP") {
View
4 t/02-keys.t
@@ -53,7 +53,7 @@ if $r.info<redis_version> gt "2.6" {
# keys
$r.set("pattern1", 1);
$r.set("pattern2", 2);
-is-deeply $r.keys("pattern*"), ["pattern1", "pattern2"];
+is-deeply $r.keys("pattern*").sort, ("pattern1", "pattern2");
# migrate TODO
@@ -64,7 +64,7 @@ $r.set("key", "value");
is-deeply $r.object("refcount", "key"), 1;
# randomkey
-is-deeply $r.randomkey().WHAT.gist, "Str()";
+is-deeply $r.randomkey().WHAT.gist, "(Str)";
# rename
is-deeply $r.rename("key", "newkey"), True;
View
32 t/02-lists.t
@@ -14,29 +14,29 @@ plan 16;
# lindex & lpush & llen & linsert & lrange & lpushx
$r.del("mylist");
-is_deeply $r.lpush("mylist", "World", "Hello"), 2;
-is_deeply $r.lindex("mylist", 1), "World";
-is_deeply $r.lindex("mylist", 2), Nil;
-is_deeply $r.llen("mylist"), 2;
-dies_ok { $r.linsert("mylist", "OK", "World", ", "); }
-is_deeply $r.linsert("mylist", "BEFORE", "World", ", "), 3;
-is_deeply $r.lrange("mylist", 0, 2), ["Hello", ", ", "World"];
+is-deeply $r.lpush("mylist", "World", "Hello"), 2;
+is-deeply $r.lindex("mylist", 1), "World";
+is-deeply $r.lindex("mylist", 2), Any;
+is-deeply $r.llen("mylist"), 2;
+dies-ok { $r.linsert("mylist", "OK", "World", ", "); }
+is-deeply $r.linsert("mylist", "BEFORE", "World", ", "), 3;
+is-deeply $r.lrange("mylist", 0, 2), ["Hello", ", ", "World"];
# lpushx & lpop & rpop
-is_deeply $r.lpushx("mylist", 1), 4;
-is_deeply $r.lpop("mylist"), "1";
-is_deeply $r.rpop("mylist"), "World";
+is-deeply $r.lpushx("mylist", 1), 4;
+is-deeply $r.lpop("mylist"), "1";
+is-deeply $r.rpop("mylist"), "World";
# lrem & lset & ltrim
$r.del("mylist");
$r.lpush("mylist", 1, 2, 3, 4);
-is_deeply $r.lset("mylist", 0, 1), True;
-is_deeply $r.lrem("mylist", 0, 1), 2;
-is_deeply $r.ltrim("mylist", 0, 1), True;
+is-deeply $r.lset("mylist", 0, 1), True;
+is-deeply $r.lrem("mylist", 0, 1), 2;
+is-deeply $r.ltrim("mylist", 0, 1), True;
# rpoplpush & rpush & rpushx
-is_deeply $r.rpoplpush("mylist", "newlist"), "2";
-is_deeply $r.rpush("mylist", 2), 2;
-is_deeply $r.rpushx("mylist", 2), 3;
+is-deeply $r.rpoplpush("mylist", "newlist"), "2";
+is-deeply $r.rpush("mylist", 2), 2;
+is-deeply $r.rpushx("mylist", 2), 3;
# vim: ft=perl6
View
10 t/02-scripting.t
@@ -12,16 +12,16 @@ if $r.info<redis_version> gt "2.6" {
plan 5;
$r.set("key", 1);
- is_deeply $r.eval("return redis.call('get', 'key')", 0), "1";
+ is-deeply $r.eval("return redis.call('get', 'key')", 0), "1";
- is_deeply $r.script_flush(), True;
+ is-deeply $r.script_flush(), True;
- dies_ok { $r.script_kill() };
+ dies-ok { $r.script_kill() };
my $sha = $r.script_load("return redis.call('get', 'key')");
- is_deeply $r.script_exists($sha, "unknown"), [1, 0];
+ is-deeply $r.script_exists($sha, "unknown"), [1, 0];
- is_deeply $r.evalsha($sha, 0), "1";
+ is-deeply $r.evalsha($sha, 0), "1";
} else {
done;
}
View
26 t/02-sets.t
@@ -10,31 +10,31 @@ $r.flushall;
plan 15;
-is_deeply $r.sadd("set1", 1, 2, 3, 4), 4;
-is_deeply $r.scard("set1"), 4;
+is-deeply $r.sadd("set1", 1, 2, 3, 4), 4;
+is-deeply $r.scard("set1"), 4;
$r.sadd("set2", 3, 4);
-is_deeply $r.sdiff("set1", "set2"), ["1", "2"];
-is_deeply $r.sdiffstore("set_diff", "set1", "set2"), 2;
-is_deeply $r.smembers("set_diff"), ["1", "2"];
-is_deeply $r.sinter("set1", "set2"), ["3", "4"];
-is_deeply $r.sinterstore("set_inter", "set2"), 2;
-is_deeply $r.sismember("set_inter", 3), True;
+is-deeply $r.sdiff("set1", "set2"), ["1", "2"];
+is-deeply $r.sdiffstore("set_diff", "set1", "set2"), 2;
+is-deeply $r.smembers("set_diff"), ["1", "2"];
+is-deeply $r.sinter("set1", "set2"), ["3", "4"];
+is-deeply $r.sinterstore("set_inter", "set2"), 2;
+is-deeply $r.sismember("set_inter", 3), True;
# smove
-is_deeply $r.smove("set_inter", "set_diff", 3), True;
+is-deeply $r.smove("set_inter", "set_diff", 3), True;
# spop
ok $r.spop("set_diff") eq any("1", "2", "3");
-is_deeply $r.scard("set_diff"), 2;
+is-deeply $r.scard("set_diff"), 2;
# srandmember
ok $r.srandmember("set_diff") eq any("1", "2", "3");
# srem
-is_deeply $r.srem("set_inter", "3", "4"), 0;
+is-deeply $r.srem("set_inter", "3", "4"), 0;
# sunion & sunionstore
-is_deeply $r.sunion("set1", "set2"), ["1", "2", "3", "4"];
-is_deeply $r.sunionstore("set_union", "set1", "set2"), 4;
+is-deeply $r.sunion("set1", "set2"), ["1", "2", "3", "4"];
+is-deeply $r.sunionstore("set_union", "set1", "set2"), 4;
# vim: ft=perl6
View
46 t/02-sortedsets.t
@@ -10,43 +10,43 @@ $r.flushall;
plan 23;
-is_deeply $r.zadd("myzset", ONE => 1, TWO => 2, THREE=> 3), 3;
-is_deeply $r.zadd("myzset", "ZERO", 0, "ONE" => 1, TWO => 2, THREE=> 3), 1;
-dies_ok { $r.zadd("myzset", "ZERO", ONE => 1, TWO => 2, THREE=> 3) }
+is-deeply $r.zadd("myzset", ONE => 1, TWO => 2, THREE=> 3), 3;
+is-deeply $r.zadd("myzset", "ZERO", 0, "ONE" => 1, TWO => 2, THREE=> 3), 1;
+dies-ok { $r.zadd("myzset", "ZERO", ONE => 1, TWO => 2, THREE=> 3) }
-is_deeply $r.zcard("myzset"), 4;
+is-deeply $r.zcard("myzset"), 4;
-is_deeply $r.zcount("myzset", 2, 3), 2;
+is-deeply $r.zcount("myzset", 2, 3), 2;
-is_deeply $r.zincrby("myzset", 1.1, "THREE"), 4.1;
+is-deeply $r.zincrby("myzset", 1.1, "THREE"), 4.1;
# zinterstore & zrange & zrangebyscore & zrevrange & zrevrangebyscore
$r.zadd("zset1", "one" => 1, "two" => 2);
$r.zadd("zset2", "one" => 1, "two" => 2, "three" => 3);
-is_deeply $r.zinterstore("out", "zset1", "zset2", weights => (2,3)), 2;
-is_deeply $r.zinterstore("out", "zset1", "zset2", WEIGHTS => (2,3)), 2;
-is_deeply $r.zrange("out", 0, -1), ["one", "two"];
-is_deeply $r.zrange("out", 0, -1, :WITHSCORES), ["one", "5", "two", "10"];
-is_deeply $r.zrevrange("out", 0, -1, :WITHSCORES), ["two", "10", "one", "5"];
-is_deeply $r.zrangebyscore("out", 6, 10), ["two"];
-is_deeply $r.zrangebyscore("out", 6, 10, :WITHSCORES), ["two", "10"];
-is_deeply $r.zrangebyscore("out", 0, 10, :WITHSCORES, OFFSET=>0, COUNT=>1), ["one", "5"];
-is_deeply $r.zrevrangebyscore("out", 10, 0, :WITHSCORES, OFFSET=>0, COUNT=>1), ["two", "10"];
+is-deeply $r.zinterstore("out", "zset1", "zset2", weights => (2,3)), 2;
+is-deeply $r.zinterstore("out", "zset1", "zset2", WEIGHTS => (2,3)), 2;
+is-deeply $r.zrange("out", 0, -1), ["one", "two"];
+is-deeply $r.zrange("out", 0, -1, :WITHSCORES), ["one", "5", "two", "10"];
+is-deeply $r.zrevrange("out", 0, -1, :WITHSCORES), ["two", "10", "one", "5"];
+is-deeply $r.zrangebyscore("out", 6, 10), ["two"];
+is-deeply $r.zrangebyscore("out", 6, 10, :WITHSCORES), ["two", "10"];
+is-deeply $r.zrangebyscore("out", 0, 10, :WITHSCORES, OFFSET=>0, COUNT=>1), ["one", "5"];
+is-deeply $r.zrevrangebyscore("out", 10, 0, :WITHSCORES, OFFSET=>0, COUNT=>1), ["two", "10"];
# zrank & zrem & zremrangbyrank & zrevrank
$r.flushall;
$r.zadd("myzset", one=>1, two=>2, three=>3, four=>4);
-is_deeply $r.zrank("myzset", "one"), 0;
-is_deeply $r.zrevrank("myzset", "one"), 3;
-is_deeply $r.zrank("myzset", "other"), Nil;
-is_deeply $r.zrem("myzset", "other", "one"), 1;
-is_deeply $r.zremrangbyrank("myzset", 0, 1), 2;
-is_deeply $r.zremrangebyscore("myzset", 2, 3), 0;
+is-deeply $r.zrank("myzset", "one"), 0;
+is-deeply $r.zrevrank("myzset", "one"), 3;
+is-deeply $r.zrank("myzset", "other"), Nil;
+is-deeply $r.zrem("myzset", "other", "one"), 1;
+is-deeply $r.zremrangbyrank("myzset", 0, 1), 2;
+is-deeply $r.zremrangebyscore("myzset", 2, 3), 0;
# zscore & zunionstore
$r.flushall;
$r.zadd("myzset", one=>1, two=>2, three=>3, four=>4);
$r.zadd("myzset2", five=>5, six=>6);
-is_deeply $r.zscore("myzset", "three"), 3;
-is_deeply $r.zunionstore("newset", "myzset", "myzset2"), 6;
+is-deeply $r.zscore("myzset", "three"), 3;
+is-deeply $r.zunionstore("newset", "myzset", "myzset2"), 6;
View
70 t/02-strings.t
@@ -16,89 +16,89 @@ if $r.info<redis_version> gt "2.6" {
# append
$r.del("key");
-is_deeply $r.append("key", "Hello"), 5;
-is_deeply $r.append("key", " World"), 11;
+is-deeply $r.append("key", "Hello"), 5;
+is-deeply $r.append("key", " World"), 11;
# bitcount
if $r.info<redis_version> gt "2.6" {
$r.set("key", "foobar");
- is_deeply $r.bitcount("key"), 26;
- is_deeply $r.bitcount("key", 0, 0), 4;
- is_deeply $r.bitcount("key", 1, 1), 6;
+ is-deeply $r.bitcount("key"), 26;
+ is-deeply $r.bitcount("key", 0, 0), 4;
+ is-deeply $r.bitcount("key", 1, 1), 6;
}
# bitop
if $r.info<redis_version> gt "2.6" {
$r.set("key1", "foobar");
$r.set("key2", "abcdefg");
- is_deeply $r.bitop("AND", "dest", "key1", "key2"), 7;
+ is-deeply $r.bitop("AND", "dest", "key1", "key2"), 7;
}
# incr & decr & decrby & incrby
$r.set("key2", 100);
-is_deeply $r.incr("key2"), 101;
-is_deeply $r.decr("key2"), 100;
-is_deeply $r.decrby("key2", 2), 98;
-is_deeply $r.incrby("key2", 3), 101;
+is-deeply $r.incr("key2"), 101;
+is-deeply $r.decr("key2"), 100;
+is-deeply $r.decrby("key2", 2), 98;
+is-deeply $r.incrby("key2", 3), 101;
# getbit
-is_deeply $r.getbit("key2", 2), 1;
+is-deeply $r.getbit("key2", 2), 1;
# getrange
$r.set("mykey", "This is a string");
-is_deeply $r.getrange("mykey", 0, 3), "This";
+is-deeply $r.getrange("mykey", 0, 3), "This";
# getset
$r.del("mycounter");
-is_deeply $r.incr("mycounter"), 1;
-is_deeply $r.getset("mycounter", 0), "1";
-is_deeply $r.get("mycounter"), "0";
+is-deeply $r.incr("mycounter"), 1;
+is-deeply $r.getset("mycounter", 0), "1";
+is-deeply $r.get("mycounter"), "0";
# incrbyfloat
if $r.info<redis_version> gt "2.6" {
$r.set("mykey", 10.50);
- is_deeply $r.incrbyfloat("mykey", 0.1), 10.6;
+ is-deeply $r.incrbyfloat("mykey", 0.1), 10.6;
$r.set("mykey", 5.0e3);
- is_deeply $r.incrbyfloat("mykey", 2.0e2), 5200;
+ is-deeply $r.incrbyfloat("mykey", 2.0e2), 5200;
}
# set & get
-is_deeply $r.set("key", "value"), True;
-is_deeply $r.get("key"), "value";
-is_deeply $r.get("does_not_exists"), Nil;
-is_deeply $r.set("key2", 100), True;
-is_deeply $r.get("key2"), "100";
+is-deeply $r.set("key", "value"), True;
+is-deeply $r.get("key"), "value";
+is-deeply $r.get("does_not_exists"), Any;
+is-deeply $r.set("key2", 100), True;
+is-deeply $r.get("key2"), "100";
# mget
$r.del("key", "key2");
-is_deeply $r.mset("key", "value", key2 => "value2"), True;
-is_deeply $r.mget("key", "key2"), ["value", "value2"];
-is_deeply $r.msetnx("key", "value", key2 => "value2"), 0;
+is-deeply $r.mset("key", "value", key2 => "value2"), True;
+is-deeply $r.mget("key", "key2"), ["value", "value2"];
+is-deeply $r.msetnx("key", "value", key2 => "value2"), 0;
# psetex
if $r.info<redis_version> gt "2.6" {
- is_deeply $r.psetex("key", 100, "value"), True;
- is_deeply $r.get("key"), "value";
+ is-deeply $r.psetex("key", 100, "value"), True;
+ is-deeply $r.get("key"), "value";
sleep(0.1);
- is_deeply $r.get("key"), Nil;
+ is-deeply $r.get("key"), Any;
}
# setbit
$r.del("mykey");
-is_deeply $r.setbit("mykey", 7, 1), 0;
-is_deeply $r.setbit("mykey", 7, 0), 1;
+is-deeply $r.setbit("mykey", 7, 1), 0;
+is-deeply $r.setbit("mykey", 7, 0), 1;
# setex
-is_deeply $r.setex("key", 1, "value"), True;
+is-deeply $r.setex("key", 1, "value"), True;
# setnx
-is_deeply $r.setnx("key", "value"), False;
+is-deeply $r.setnx("key", "value"), False;
# setrange
-is_deeply $r.setrange("key", 2, "123"), 5;
-is_deeply $r.get("key"), "va123";
+is-deeply $r.setrange("key", 2, "123"), 5;
+is-deeply $r.get("key"), "va123";
# strlen
-is_deeply $r.strlen("key"), 5;
+is-deeply $r.strlen("key"), 5;
# vim: ft=perl6
View
2 t/03-binary.t
@@ -11,6 +11,6 @@ $r.flushall;
plan 2;
# arbitary binary string
-my Buf $binary = Buf.new(1,2,3,129);
+my Buf $binary = Buf[uint8].new(1,2,3,129);
is-deeply $r.set("key", $binary), True;
is-deeply $r.get("key"), $binary;

0 comments on commit 83ce242

Please sign in to comment.
Something went wrong with that request. Please try again.