Permalink
Browse files

Work on Set object

  • Loading branch information...
CurtTilmes committed May 22, 2017
1 parent 8fc29e8 commit d42f0042fda338f07d50965ad9284ddd63bb615d
Showing with 54 additions and 0 deletions.
  1. +28 −0 eg/set.pl6
  2. +26 −0 lib/Redis/Objects.pm6
@@ -0,0 +1,28 @@
use v6;
use Redis::Async;
use Redis::Objects;
my $redis = Redis::Async.new;
my $set = Redis::Set.new(:$redis, key => 'myset');
$set.push(^10);
say $set.keys;
say $set.elems;
say $set.values;
say $set.pick;
say $set.roll(10);
say $set.kv;
say $set.grab for ^3;
say $set.keys;
say 3 $set ?? "3 is a member" !! "3 is not a member";
@@ -152,3 +152,29 @@ class Redis::Set does Iterable {
method grab($count = 1) { $count == 1 ?? $!redis.spop($!key)
!! $!redis.spop($!key, $count) }
}
multi sub infix:<(elem)>(Cool:D $a, Redis::Set:D $b --> Bool:D) is export
{
$b.redis.sismember($b.key, $a).Bool
}
sub infix:<∈>(Cool:D $a, Redis::Set:D $b --> Bool:D) is export {
$a (elem) $b;
}
sub infix:<∉>(Cool:D $a, Redis::Set:D $b --> Bool:D) is export {
$a !(elem) $b;
}
multi sub infix:<(cont)>(Redis::Set:D $b, Cool:D $a --> Bool:D) is export
{
$a.redis.sismember($a.key, $b).Bool
}
sub infix:<∋>(Redis::Set:D $a, Cool:D $b --> Bool:D) is export {
$a (cont) $b;
}
sub infix:<∌>(Redis::Set:D $a, Cool:D $b --> Bool:D) is export {
$a !(cont) $b;
}

0 comments on commit d42f004

Please sign in to comment.