public void OperateMapScore() { // Test score. Key key = new Key(args.ns, args.set, "opmkey10"); client.Delete(null, key); MapPolicy mapPolicy = new MapPolicy(MapOrder.KEY_VALUE_ORDERED, MapWriteMode.UPDATE); Dictionary <Value, Value> inputMap = new Dictionary <Value, Value>(); inputMap[Value.Get("weiling")] = Value.Get(0); inputMap[Value.Get("briann")] = Value.Get(0); inputMap[Value.Get("brianb")] = Value.Get(0); inputMap[Value.Get("meher")] = Value.Get(0); // Create map. Record record = client.Operate(null, key, MapOperation.PutItems(mapPolicy, binName, inputMap)); AssertRecordFound(key, record); // Change scores record = client.Operate(null, key, MapOperation.Increment(mapPolicy, binName, Value.Get("weiling"), Value.Get(10)), MapOperation.Increment(mapPolicy, binName, Value.Get("briann"), Value.Get(20)), MapOperation.Increment(mapPolicy, binName, Value.Get("brianb"), Value.Get(1)), MapOperation.Increment(mapPolicy, binName, Value.Get("meher"), Value.Get(20)) ); AssertRecordFound(key, record); // Query top 3 scores record = client.Operate(null, key, MapOperation.GetByRankRange(binName, -3, 3, MapReturnType.KEY)); AssertRecordFound(key, record); // Remove people with score 10 and display top 3 again record = client.Operate(null, key, MapOperation.RemoveByValue(binName, Value.Get(10), MapReturnType.KEY), MapOperation.GetByRankRange(binName, -3, 3, MapReturnType.KEY) ); AssertRecordFound(key, record); IList results = record.GetList(binName); int i = 0; IList list = (IList)results[i++]; string s = (string)list[0]; Assert.AreEqual("weiling", s); list = (IList)results[i++]; s = (string)list[0]; Assert.AreEqual("brianb", s); s = (string)list[1]; Assert.AreEqual("briann", s); s = (string)list[2]; Assert.AreEqual("meher", s); }
private void RunScoreExample(AerospikeClient client, Arguments args) { Key key = new Key(args.ns, args.set, "mapkey"); string binName = args.GetBinName("mapbin"); // Delete record if it already exists. client.Delete(args.writePolicy, key); IDictionary inputMap = new Dictionary <Value, Value>(); inputMap[Value.Get("Charlie")] = Value.Get(55); inputMap[Value.Get("Jim")] = Value.Get(98); inputMap[Value.Get("John")] = Value.Get(76); inputMap[Value.Get("Harry")] = Value.Get(82); // Write values to empty map. Record record = client.Operate(args.writePolicy, key, MapOperation.PutItems(MapPolicy.Default, binName, inputMap) ); console.Info("Record: " + record); // Increment some user scores. record = client.Operate(args.writePolicy, key, MapOperation.Increment(MapPolicy.Default, binName, Value.Get("John"), Value.Get(5)), MapOperation.Increment(MapPolicy.Default, binName, Value.Get("Jim"), Value.Get(-4)) ); console.Info("Record: " + record); // Get top two scores. record = client.Operate(args.writePolicy, key, MapOperation.GetByRankRange(binName, -2, 2, MapReturnType.KEY_VALUE) ); // There should be one result for each map operation on the same map bin. // In this case, there are two map operations (pop and size), so there // should be two results. IList results = record.GetList(binName); foreach (object value in results) { console.Info("Received: " + value); } }
public void OperateMapRank() { // Test rank. if (!args.ValidateMap()) { return; } Key key = new Key(args.ns, args.set, "opmkey6"); client.Delete(null, key); Dictionary <Value, Value> inputMap = new Dictionary <Value, Value>(); inputMap[Value.Get("Charlie")] = Value.Get(55); inputMap[Value.Get("Jim")] = Value.Get(98); inputMap[Value.Get("John")] = Value.Get(76); inputMap[Value.Get("Harry")] = Value.Get(82); // Write values to empty map. Record record = client.Operate(null, key, MapOperation.PutItems(MapPolicy.Default, binName, inputMap)); AssertRecordFound(key, record); // Increment some user scores. record = client.Operate(null, key, MapOperation.Increment(MapPolicy.Default, binName, Value.Get("John"), Value.Get(5)), MapOperation.Decrement(MapPolicy.Default, binName, Value.Get("Jim"), Value.Get(4)) ); AssertRecordFound(key, record); // Get scores. record = client.Operate(null, key, MapOperation.GetByRankRange(binName, -2, 2, MapReturnType.KEY), MapOperation.GetByRankRange(binName, 0, 2, MapReturnType.KEY_VALUE), MapOperation.GetByRank(binName, 0, MapReturnType.VALUE), MapOperation.GetByRank(binName, 2, MapReturnType.KEY), MapOperation.GetByValueRange(binName, Value.Get(90), Value.Get(95), MapReturnType.RANK), MapOperation.GetByValueRange(binName, Value.Get(90), Value.Get(95), MapReturnType.COUNT), MapOperation.GetByValueRange(binName, Value.Get(90), Value.Get(95), MapReturnType.KEY_VALUE), MapOperation.GetByValueRange(binName, Value.Get(81), Value.Get(82), MapReturnType.KEY), MapOperation.GetByValue(binName, Value.Get(77), MapReturnType.KEY), MapOperation.GetByValue(binName, Value.Get(81), MapReturnType.RANK), MapOperation.GetByKey(binName, Value.Get("Charlie"), MapReturnType.RANK), MapOperation.GetByKey(binName, Value.Get("Charlie"), MapReturnType.REVERSE_RANK) ); AssertRecordFound(key, record); IList results = record.GetList(binName); int i = 0; IList list = (IList)results[i++]; string str; long val; str = (string)list[0]; Assert.AreEqual("Harry", str); str = (string)list[1]; Assert.AreEqual("Jim", str); list = (IList)results[i++]; KeyValuePair <object, object> entry = (KeyValuePair <object, object>)list[0]; Assert.AreEqual("Charlie", entry.Key); Assert.AreEqual(55L, entry.Value); entry = (KeyValuePair <object, object>)list[1]; Assert.AreEqual("John", entry.Key); Assert.AreEqual(81L, entry.Value); val = (long)results[i++]; Assert.AreEqual(55, val); str = (string)results[i++]; Assert.AreEqual("Harry", str); list = (IList)results[i++]; val = (long)list[0]; Assert.AreEqual(3, val); val = (long)results[i++]; Assert.AreEqual(1, val); list = (IList)results[i++]; entry = (KeyValuePair <object, object>)list[0]; Assert.AreEqual("Jim", entry.Key); Assert.AreEqual(94L, entry.Value); list = (IList)results[i++]; str = (string)list[0]; Assert.AreEqual("John", str); list = (IList)results[i++]; Assert.AreEqual(0, list.Count); list = (IList)results[i++]; val = (long)list[0]; Assert.AreEqual(1, val); val = (long)results[i++]; Assert.AreEqual(0, val); val = (long)results[i++]; Assert.AreEqual(3, val); }