etcd 3 Range Query

629 Views Asked by At

How can I use etcds new range query to get a subset of records, based on these values:

a-key/path/foo_1: value-1
a-key/path/foo_2: value-2
a-key/path/foo_3: value-3
a-key/path/foo_4: value-4
a-key/path/foo_5: value-5

I'd like to be able to query that data like this:

Get everything from a-key/path/foo_3 to a-key/path/foo_4 (specific end result), returning:

a-key/path/foo_3: value-3
a-key/path/foo_4: value-4

Or, everything from a-key/path/foo_3 onwards (no end) for example:

a-key/path/foo_3: value-3
a-key/path/foo_4: value-4
a-key/path/foo_5: value-5

I'm using the dotnet-etcd client for .NET (Core) if that helps/ affects any answers.

The a-key/path/foo_ keys have no end, meaning they could go on forever... in Azure Table Storage I can query the same data like this:

// Query for table entities based on an optional `versionTo`.
new TableQuery<DynamicTableEntity>().Where(
    TableQuery.CombineFilters(
        TableQuery.GenerateFilterCondition(nameof(ITableEntity.PartitionKey), QueryComparisons.Equal, aggregateId),
        TableOperators.And,
        TableQuery.CombineFilters(
            TableQuery.GenerateFilterCondition(nameof(ITableEntity.RowKey), QueryComparisons.GreaterThanOrEqual, CreateRowKey(versionFrom)),
            TableOperators.And,
            TableQuery.GenerateFilterCondition(nameof(ITableEntity.RowKey), QueryComparisons.LessThanOrEqual, CreateRowKey(versionTo ?? int.MaxValue)))
        )
    );

// Generate the row key
string CreateEventRowKey(int version) => $"keyPrefix_{$"{version}".PadLeft(10, '0')}";

0

There are 0 best solutions below