A new key value store providing sorted sets / collections. This is for instances when sequential data needs to be stored in the key value store. it is based upon the Redis sorted sets. Keys may be used multiple times for items that are at the same position within a sequence.
Example usage:
$collection = 'my_collection';
$store = \Drupal::service('keyvalue.sorted_set')->get($collection);
$key = (int) (microtime(TRUE) * 1000000);
$value = [
'ford' => [
'focus',
'fiesta',
],
'volkswagen' => [
'golf',
'polo,
]
];
$store->add($key, $value);
To get items from the store the getRange($start, $stop);
method would be used. This will return all items with a greater key than $start
and a lower key than $stop
. $stop
is an optional parameter, if not provided it will get all items in the collection with a greater key than $start
.
getMaxKey()
and getMinKey()
will return the highest and lowest keys in a collection.
getCount()
will return the number of items in a collection.