Пример #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Creating Data");
            Customer            customer     = CreateCustomer();
            IEnumerable <Order> orders       = CreateOrders(customer);
            OrderSummary        orderSummary = CreateOrderSummary(customer, orders);


            Console.WriteLine("Starting Client");
            using (IRiakEndPoint endpoint = RiakCluster.FromConfig("riakConfig"))
            {
                IRiakClient client = endpoint.CreateClient();

                Console.WriteLine("Storing Data");

                client.Put(ToRiakObject(customer));

                foreach (Order order in orders)
                {
                    // NB: this adds secondary index data as well
                    client.Put(ToRiakObject(order));
                }

                client.Put(ToRiakObject(orderSummary));

                Console.WriteLine("Fetching related data by shared key");
                string key = "1";

                var result = client.Get(customersBucketName, key);
                CheckResult(result);
                Console.WriteLine("Customer     1: {0}\n", GetValueAsString(result));

                result = client.Get(orderSummariesBucketName, key);
                CheckResult(result);
                Console.WriteLine("OrderSummary 1: {0}\n", GetValueAsString(result));

                Console.WriteLine("Index Queries");

                // Query for order keys where the SalesPersonId index is set to 9000
                var riakIndexId = new RiakIndexId(ordersBucketName, ordersSalesPersonIdIndexName);
                RiakResult <RiakIndexResult> indexRiakResult = client.GetSecondaryIndex(riakIndexId, 9000); // NB: *must* use 9000 as integer here.
                CheckResult(indexRiakResult);
                RiakIndexResult indexResult = indexRiakResult.Value;
                Console.WriteLine("Jane's orders (key values): {0}", string.Join(", ", indexResult.IndexKeyTerms.Select(ikt => ikt.Key)));

                // Query for orders where the OrderDate index is between 2013-10-01 and 2013-10-31
                riakIndexId     = new RiakIndexId(ordersBucketName, ordersOrderDateIndexName);
                indexRiakResult = client.GetSecondaryIndex(riakIndexId, "2013-10-01", "2013-10-31"); // NB: *must* use strings here.
                CheckResult(indexRiakResult);
                indexResult = indexRiakResult.Value;
                Console.WriteLine("October orders (key values): {0}", string.Join(", ", indexResult.IndexKeyTerms.Select(ikt => ikt.Key)));
            }
        }
Пример #2
0
        private void button6_Click(object sender, EventArgs e)
        {
            Console.WriteLine("Index Queries");

            // Query for order keys where the SalesPersonId index is set to 9000
            var riakIndexId = new RiakIndexId(ordersBucketName, ordersSalesPersonIdIndexName);
            RiakResult <RiakIndexResult> indexRiakResult = client.GetSecondaryIndex(riakIndexId, 9000); // NB: *must* use 9000 as integer here.

            CheckResult(indexRiakResult);
            RiakIndexResult indexResult = indexRiakResult.Value;

            Console.WriteLine("Jane's orders (key values): {0}", string.Join(", ", indexResult.IndexKeyTerms.Select(ikt => ikt.Key)));

            // Query for orders where the OrderDate index is between 2013-10-01 and 2013-10-31
            riakIndexId     = new RiakIndexId(ordersBucketName, ordersOrderDateIndexName);
            indexRiakResult = client.GetSecondaryIndex(riakIndexId, "2013-10-01", "2013-10-31"); // NB: *must* use strings here.
            CheckResult(indexRiakResult);
            indexResult = indexRiakResult.Value;
            Console.WriteLine("October orders (key values): {0}", string.Join(", ", indexResult.IndexKeyTerms.Select(ikt => ikt.Key)));
        }
 /// <inheritdoc/>
 public Task <RiakResult <RiakIndexResult> > GetSecondaryIndex(RiakIndexId index, BigInteger value, RiakIndexGetOptions options = null)
 {
     return(Task.Factory.StartNew(() => client.GetSecondaryIndex(index, value, options)));
 }