Skip to content
This repository has been archived by the owner on Oct 19, 2020. It is now read-only.

Commit

Permalink
Better concurrent set example
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeSapkin committed Feb 9, 2015
1 parent b2cbc1e commit d5f6670
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions examples/get-range-run/source/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import
std.array,
std.c.stdlib,
std.conv,
std.parallelism,
std.range,
std.stdio;

import
Expand All @@ -23,21 +25,20 @@ void main()
}

auto prefix = "SomeKey";
auto key1 = pack(prefix, 1);
auto key2 = pack(prefix, 2);
db.clearRange(prefix.pack.range);

"Doing set transaction".writeln;
db.run((tr)
{
tr[key1] = pack("SomeValue1");
tr[key2] = pack("SomeValue2");
});
"Setting values using concurrent transactions".writeln;
foreach(idx; iota(0, 10).parallel)
db.run((tr)
{
auto key = pack(prefix, cast(long)idx);
tr[key] = pack(cast(long)idx);
});

"Doing get transaction".writeln;
"Getting SomeKey range".writeln;
db.run((tr)
{
"Getting [SomeKey1, SomeKey2] range".writeln;
auto r = tr[rangeInclusive(key1, key2)];
auto r = tr[prefix.pack.range];
foreach (record; r)
{
"Got ".write;
Expand Down

0 comments on commit d5f6670

Please sign in to comment.