Created
February 12, 2013 19:51
-
-
Save peschkaj/4772825 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
using CorrugatedIron; | |
using CorrugatedIron.Models; | |
using CorrugatedIron.Models.MapReduce; | |
using CorrugatedIron.Models.MapReduce.Inputs; | |
using CorrugatedIron.Util; | |
namespace MiscellaneousSamples | |
{ | |
public class SecondaryIndices | |
{ | |
public void KeysIndex() | |
{ | |
Console.WriteLine("Beginning KeysIndex"); | |
Console.WriteLine("\tAdding 10 items"); | |
var Cluster = RiakCluster.FromConfig("riakConfig"); | |
var Client = Cluster.CreateClient(); | |
var bucket = "rsds"; | |
Client.Batch(batch => | |
{ | |
for (var i = 1; i < 11; i++) | |
{ | |
var d = DateTime.Now.AddDays(0 - i); | |
var doc = new RiakObject(bucket, i.ToString(), new { value = i, created_date = d }); | |
var position = 100 + i; | |
doc.BinIndex("position").Set(position.ToString()); | |
batch.Put(doc); | |
} | |
}); | |
var query = new RiakMapReduceQuery() | |
.Inputs(RiakIndex.Range("rsds", "$key", "0", "ZZZZZ")); | |
var result = Client.MapReduce(query); | |
var keys = result.Value.PhaseResults.SelectMany(x => x.GetObjects<RiakObjectId>()).ToList(); | |
foreach (var key in keys) | |
{ | |
Console.WriteLine("\t{0} : {1}", key.Bucket, key.Key); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment