diff --git a/lib/Myriad/Role/Storage.pm b/lib/Myriad/Role/Storage.pm index 0d468764..751c83ee 100644 --- a/lib/Myriad/Role/Storage.pm +++ b/lib/Myriad/Role/Storage.pm @@ -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 @@ -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 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 diff --git a/lib/Myriad/Storage/Implementation/Memory.pm b/lib/Myriad/Storage/Implementation/Memory.pm index 64290783..a199a508 100644 --- a/lib/Myriad/Storage/Implementation/Memory.pm +++ b/lib/Myriad/Storage/Implementation/Memory.pm @@ -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: diff --git a/lib/Myriad/Storage/Implementation/Redis.pm b/lib/Myriad/Storage/Implementation/Redis.pm index a23b9e7c..c9d8e29e 100644 --- a/lib/Myriad/Storage/Implementation/Redis.pm +++ b/lib/Myriad/Storage/Implementation/Redis.pm @@ -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: