Skip to content

Commit

Permalink
Merge pull request #325 from tom-binary/feature/list_count
Browse files Browse the repository at this point in the history
Support for `list_count` storage method
  • Loading branch information
tom-binary authored Jul 4, 2024
2 parents 6981bcf + 3abe3ae commit 94b84f9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/Myriad/Role/Storage.pm
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ our @READ_METHODS = qw(
hash_exists
hash_count
hash_as_list
list_count
list_range
orderedset_member_count
orderedset_members
Expand Down Expand Up @@ -483,6 +484,22 @@ suitable for assigning to a hash.

method hash_as_list;

=head2 list_count
Takes the following parameters:
=over 4
=item * key
=back
Returns a L<Future> which will resolve to the integer count of values currently in the list.
=cut

method list_count;

=head2 list_range
Takes the following parameters:
Expand Down
4 changes: 4 additions & 0 deletions lib/Myriad/Storage/Implementation/Memory.pm
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,10 @@ async method hash_as_list : Defer ($k) {
return $data{$k}->%*;
}

async method list_count : Defer ($k) {
return 0 + $data{$k}->@*;
}

async method list_range : Defer ($k, $start = 0, $end = -1) {
my $len = 0 + $data{$k}->@*
or return [ ];
Expand Down
4 changes: 4 additions & 0 deletions lib/Myriad/Storage/Implementation/Redis.pm
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,10 @@ async method watch_keyspace ($keyspace) {
});
}

async method list_count ($k) {
await $redis->llen($self->apply_prefix($k));
}

async method list_range ($k, $start = 0, $end = -1) {
await $redis->lrange($self->apply_prefix($k), $start, $end);
}
Expand Down

0 comments on commit 94b84f9

Please sign in to comment.