Permalink
Browse files

Tested agaist Redis version 2.4.16 and 2.5.12.

  • Loading branch information...
1 parent 9c45b7d commit 1b1a3f0b09f2cf579660062ceef49d2cc5eec74f @cofyc committed Sep 6, 2012
Showing with 116 additions and 82 deletions.
  1. +5 −0 README.md
  2. +1 −1 TODO
  3. +14 −14 lib/Redis.pm
  4. +1 −7 t/01-connect.t
  5. +1 −2 t/02-connection.t
  6. +11 −5 t/02-hashes.t
  7. +30 −17 t/02-keys.t
  8. +1 −1 t/02-lists.t
  9. +1 −1 t/02-pub&sub.t
  10. +13 −9 t/02-scripting.t
  11. +1 −1 t/02-server.t
  12. +1 −1 t/02-sets.t
  13. +1 −1 t/02-sortedsets.t
  14. +29 −17 t/02-strings.t
  15. +1 −1 t/02-transactions.t
  16. +1 −1 t/03-binary.t
  17. +1 −1 t/03-multibytes.t
  18. +1 −1 t/04-exec-any-commands.t
  19. +1 −0 t/Test/SpawnRedisServer.pm
  20. +1 −1 t/redis.conf
View
@@ -29,6 +29,11 @@ Install with Panda
$ panda install Redis
or if you don't have Redis server installed
$ panda install --notests Redis
+
+Unit Tests
+==========
+
+ Tested agaist Redis version 2.4.16 and 2.5.12.
References
==========
View
2 TODO
@@ -1,3 +1,3 @@
-* start Redis daemon automatically in unit testing
+* better unit testing, it's dangerous to test with external daemon
* complete method signatures
* support timeout options
View
@@ -1,19 +1,19 @@
use v6;
-# =begin Pod
-#
-# =head1 Redis
-#
-# C<Redis> is a Perl6 binding for Redis database.
-#
-# =head1 Synopsis
-#
-# my $redis = Redis.new("192.168.1.12:6379");
-# $redis.connect();
-# $redis.set("key", "value");
-# say $redis.get("key");
-#
-# =end Pod
+=begin Pod
+
+=head1 Redis
+
+C<Redis> is a Perl6 binding for Redis database.
+
+=head1 Synopsis
+
+my $redis = Redis.new("192.168.1.12:6379");
+$redis.connect();
+$redis.set("key", "value");
+say $redis.get("key");
+
+=end Pod
class Redis;
View
@@ -3,18 +3,12 @@ use v6;
BEGIN { @*INC.push('t', 'lib') };
use Redis;
use Test;
-use Test::SpawnRedisServer;
-plan 2;
+plan 1;
{
my $r = Redis.new('127.0.0.1:0');
dies_ok { $r.connect }
}
-{
- my $r = Redis.new();
- ok $r.connect;
-}
-
# vim: ft=perl6
View
@@ -3,9 +3,8 @@ use v6;
BEGIN { @*INC.push('t', 'lib') };
use Redis;
use Test;
-use Test::SpawnRedisServer;
-my $r = Redis.new(decode_response => True);
+my $r = Redis.new("127.0.0.1:63790", decode_response => True);
$r.connect;
plan 5;
View
@@ -3,13 +3,16 @@ use v6;
BEGIN { @*INC.push('t', 'lib') };
use Redis;
use Test;
-use Test::SpawnRedisServer;
-my $r = Redis.new(decode_response => True);
+my $r = Redis.new("127.0.0.1:63790", decode_response => True);
$r.connect;
$r.flushall;
-plan 13;
+if $r.info<redis_version> gt "2.6" {
+ plan 13;
+} else {
+ plan 12;
+}
# hset & hget & hmset & hmget & hsetnx
$r.hdel("hash", "field1");
@@ -29,11 +32,14 @@ is_deeply $r.hgetall("hash"), {key2 => "value2", count => "1"};
# hincrby & hincrbyfloat
is_deeply $r.hincrby("hash", "count", 10), 11;
-is_deeply $r.hincrbyfloat("hash", "count", 10.1), 21.1;
+if $r.info<redis_version> gt "2.6" {
+ is_deeply $r.hincrbyfloat("hash", "count", 10.1), 21.1;
+}
# hkeys & hlen & hvals
is_deeply $r.hkeys("hash"), ["key2", "count"];
is_deeply $r.hlen("hash"), 2;
-is_deeply $r.hvals("hash"), ["value2", "21.1"];
+$r.hset("hash", "count", 10);
+is_deeply $r.hvals("hash"), ["value2", "10"];
# vim: ft=perl6
View
@@ -3,39 +3,52 @@ use v6;
BEGIN { @*INC.push('t', 'lib') };
use Redis;
use Test;
-use Test::SpawnRedisServer;
-my $r = Redis.new(decode_response => True);
+my $r = Redis.new("127.0.0.1:63790", decode_response => True);
$r.connect;
$r.flushall;
-plan 21;
+
+if $r.info<redis_version> gt "2.6" {
+ plan 21;
+} else {
+ plan 14;
+}
# del
is_deeply $r.del("key", "key2", "does_not_exists"), 0;
# dump & restore
-$r.set("key", "value");
-my $serialized = $r.dump("key");
-$r.del("newkey");
-is_deeply $r.restore("newkey", 100, $serialized), True;
-is_deeply $r.get("newkey"), "value";
+if $r.info<redis_version> gt "2.6" {
+ $r.set("key", "value");
+ my $serialized = $r.dump("key");
+ $r.del("newkey");
+ is_deeply $r.restore("newkey", 100, $serialized), True;
+ is_deeply $r.get("newkey"), "value";
+}
# exists
$r.set("key", "value");
is_deeply $r.exists("key"), True;
is_deeply $r.exists("does_not_exists"), False;
# expire & persist & pexpire & expireat & pexpireat & pttl & ttl
-is_deeply $r.expire("key", 100), True;
-ok $r.ttl("key") <= 100;
-ok $r.persist("key");
-is_deeply $r.ttl("key"), -1;
-is_deeply $r.pexpire("key", 100000), True;
-is_deeply $r.expireat("key", 100), True;
-is_deeply $r.ttl("key"), -1;
-is_deeply $r.pexpireat("key", 1), False;
-is_deeply $r.pttl("key"), -1;
+if $r.info<redis_version> gt "2.6" {
+ is_deeply $r.expire("key", 100), True;
+ ok $r.ttl("key") <= 100;
+ ok $r.persist("key");
+ is_deeply $r.ttl("key"), -1;
+ is_deeply $r.pexpire("key", 100000), True;
+ is_deeply $r.expireat("key", 100), True;
+ is_deeply $r.ttl("key"), -1;
+ is_deeply $r.pexpireat("key", 1), False;
+ is_deeply $r.pttl("key"), -1;
+} else {
+ is_deeply $r.expire("key", 100), True;
+ ok $r.ttl("key") <= 100;
+ ok $r.persist("key");
+ is_deeply $r.ttl("key"), -1;
+}
# keys
$r.set("pattern1", 1);
View
@@ -5,7 +5,7 @@ use Redis;
use Test;
use Test::SpawnRedisServer;
-my $r = Redis.new(decode_response => True);
+my $r = Redis.new("127.0.0.1:63790", decode_response => True);
$r.connect;
$r.flushall;
View
@@ -5,7 +5,7 @@ use Redis;
use Test;
use Test::SpawnRedisServer;
-my $r = Redis.new(decode_response => True);
+my $r = Redis.new("127.0.0.1:63790", decode_response => True);
$r.connect;
$r.flushall;
View
@@ -5,20 +5,24 @@ use Redis;
use Test;
use Test::SpawnRedisServer;
-my $r = Redis.new(decode_response => True);
+my $r = Redis.new("127.0.0.1:63790", decode_response => True);
$r.connect;
$r.flushall;
-plan 5;
+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";
+ $r.set("key", 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];
+ my $sha = $r.script_load("return redis.call('get', 'key')");
+ 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
@@ -5,7 +5,7 @@ use Redis;
use Test;
use Test::SpawnRedisServer;
-my $r = Redis.new();
+my $r = Redis.new("127.0.0.1:63790", decode_response => True);
$r.connect;
plan 3;
View
@@ -5,7 +5,7 @@ use Redis;
use Test;
use Test::SpawnRedisServer;
-my $r = Redis.new(decode_response => True);
+my $r = Redis.new("127.0.0.1:63790", decode_response => True);
$r.connect;
$r.flushall;
View
@@ -5,7 +5,7 @@ use Redis;
use Test;
use Test::SpawnRedisServer;
-my $r = Redis.new(decode_response => True);
+my $r = Redis.new("127.0.0.1:63790", decode_response => True);
$r.connect;
$r.flushall;
View
@@ -5,27 +5,35 @@ use Redis;
use Test;
use Test::SpawnRedisServer;
-my $r = Redis.new(decode_response => True);
+my $r = Redis.new("127.0.0.1:63790", decode_response => True);
$r.connect;
$r.flushall;
-plan 35;
+if $r.info<redis_version> gt "2.6" {
+ plan 35;
+} else {
+ plan 26;
+}
# append
$r.del("key");
is_deeply $r.append("key", "Hello"), 5;
is_deeply $r.append("key", " World"), 11;
# bitcount
-$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;
+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;
+}
# bitop
-$r.set("key1", "foobar");
-$r.set("key2", "abcdefg");
-is_deeply $r.bitop("AND", "dest", "key1", "key2"), 7;
+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;
+}
# incr & decr & decrby & incrby
$r.set("key2", 100);
@@ -48,10 +56,12 @@ is_deeply $r.getset("mycounter", 0), "1";
is_deeply $r.get("mycounter"), "0";
# incrbyfloat
-$r.set("mykey", 10.50);
-is_deeply $r.incrbyfloat("mykey", 0.1), 10.6;
-$r.set("mykey", 5.0e3);
-is_deeply $r.incrbyfloat("mykey", 2.0e2), 5200;
+if $r.info<redis_version> gt "2.6" {
+ $r.set("mykey", 10.50);
+ is_deeply $r.incrbyfloat("mykey", 0.1), 10.6;
+ $r.set("mykey", 5.0e3);
+ is_deeply $r.incrbyfloat("mykey", 2.0e2), 5200;
+}
# set & get
is_deeply $r.set("key", "value"), True;
@@ -67,10 +77,12 @@ is_deeply $r.mget("key", "key2"), ["value", "value2"];
is_deeply $r.msetnx("key", "value", key2 => "value2"), 0;
# psetex
-is_deeply $r.psetex("key", 100, "value"), True;
-is_deeply $r.get("key"), "value";
-sleep(0.1);
-is_deeply $r.get("key"), Nil;
+if $r.info<redis_version> gt "2.6" {
+ is_deeply $r.psetex("key", 100, "value"), True;
+ is_deeply $r.get("key"), "value";
+ sleep(0.1);
+ is_deeply $r.get("key"), Nil;
+}
# setbit
$r.del("mykey");
View
@@ -5,7 +5,7 @@ use Redis;
use Test;
use Test::SpawnRedisServer;
-my $r = Redis.new(decode_response => True);
+my $r = Redis.new("127.0.0.1:63790", decode_response => True);
$r.connect;
$r.flushall;
View
@@ -5,7 +5,7 @@ use Redis;
use Test;
use Test::SpawnRedisServer;
-my $r = Redis.new();
+my $r = Redis.new("127.0.0.1:63790");
$r.connect;
$r.flushall;
View
@@ -5,7 +5,7 @@ use Redis;
use Test;
use Test::SpawnRedisServer;
-my $r = Redis.new(decode_response=>True);
+my $r = Redis.new("127.0.0.1:63790", decode_response => True);
$r.connect;
$r.flushall;
View
@@ -5,7 +5,7 @@ use Redis;
use Test;
use Test::SpawnRedisServer;
-my $r = Redis.new(decode_response => True);
+my $r = Redis.new("127.0.0.1:63790", decode_response => True);
$r.connect;
plan 1;
@@ -1,6 +1,7 @@
module Test::SpawnRedisServer;
sub SpawnRedis() is export {
+ shell "redis-server t/redis.conf";
}
# vim: ft=perl6
View
@@ -1,5 +1,5 @@
timeout 1
appendonly no
daemonize no
-port 6379
+port 63790
bind 127.0.0.1

0 comments on commit 1b1a3f0

Please sign in to comment.