Skip to content

Instantly share code, notes, and snippets.

@peschkaj
Created February 12, 2013 19:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peschkaj/4772825 to your computer and use it in GitHub Desktop.
Save peschkaj/4772825 to your computer and use it in GitHub Desktop.
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