Skip to content

Commit

Permalink
Work on Set object
Browse files Browse the repository at this point in the history
  • Loading branch information
CurtTilmes committed May 22, 2017
1 parent 8fc29e8 commit d42f004
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
28 changes: 28 additions & 0 deletions eg/set.pl6
@@ -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";
26 changes: 26 additions & 0 deletions lib/Redis/Objects.pm6
Expand Up @@ -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.