Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for list range storage method #324

Merged
merged 1 commit into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 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_range
orderedset_member_count
orderedset_members
unorderedset_is_member
Expand Down Expand Up @@ -482,6 +483,26 @@ suitable for assigning to a hash.

method hash_as_list;

=head2 list_range

Takes the following parameters:

=over 4

=item * key

=item * start index (from 0), use negative values to indicate distance from end of list (-1 being the last element)

=item * end index (from 0), as above

=back

Returns a L<Future> which will resolve to a list of values from the list.

=cut

method list_range;

=head2 orderedset_member_count

Returns the count of members that have scores within the range passed from an orderedset structure
Expand Down
9 changes: 9 additions & 0 deletions lib/Myriad/Storage/Implementation/Memory.pm
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,15 @@ async method hash_as_list : Defer ($k) {
return $data{$k}->%*;
}

async method list_range : Defer ($k, $start = 0, $end = -1) {
my $len = 0 + $data{$k}->@*
or return [ ];
# Handle negative values as offset from end (-1 being last element)
$start = $len - $start if $start < 0;
$end = $len - $end if $end < 0;
return [ $data{$k}->@*[$start .. $end] ];
}

=head2 orderedset_add

Takes the following parameters:
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_range ($k, $start = 0, $end = -1) {
await $redis->lrange($self->apply_prefix($k), $start, $end);
}

=head2 push

Takes the following parameters:
Expand Down
Loading