本文整理汇总了C#中Aerospike.Client.AerospikeClient.Add方法的典型用法代码示例。如果您正苦于以下问题:C# AerospikeClient.Add方法的具体用法?C# AerospikeClient.Add怎么用?C# AerospikeClient.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Aerospike.Client.AerospikeClient
的用法示例。
在下文中一共展示了AerospikeClient.Add方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RunExample
/// <summary>
/// Add integer values.
/// </summary>
public override void RunExample(AerospikeClient client, Arguments args)
{
Key key = new Key(args.ns, args.set, "addkey");
string binName = args.GetBinName("addbin");
// Delete record if it already exists.
client.Delete(args.writePolicy, key);
// Perform some adds and check results.
Bin bin = new Bin(binName, 10);
console.Info("Initial add will create record. Initial value is " + bin.value + '.');
client.Add(args.writePolicy, key, bin);
bin = new Bin(binName, 5);
console.Info("Add " + bin.value + " to existing record.");
client.Add(args.writePolicy, key, bin);
Record record = client.Get(args.policy, key, bin.name);
if (record == null)
{
throw new Exception(string.Format("Failed to get: namespace={0} set={1} key={2}",
key.ns, key.setName, key.userKey));
}
// The value received from the server is an unsigned byte stream.
// Convert to an integer before comparing with expected.
int received = record.GetInt(bin.name);
int expected = 15;
if (received == expected)
{
console.Info("Add successful: namespace={0} set={1} key={2} bin={3} value={4}",
key.ns, key.setName, key.userKey, bin.name, received);
}
else
{
console.Error("Add mismatch: Expected {0}. Received {1}.", expected, received);
}
// Demonstrate add and get combined.
bin = new Bin(binName, 30);
console.Info("Add " + bin.value + " to existing record.");
record = client.Operate(args.writePolicy, key, Operation.Add(bin), Operation.Get(bin.name));
expected = 45;
received = record.GetInt(bin.name);
if (received == expected)
{
console.Info("Add successful: namespace={0} set={1} key={2} bin={3} value={4}",
key.ns, key.setName, key.userKey, bin.name, received);
}
else
{
console.Error("Add mismatch: Expected {0}. Received {1}.", expected, received);
}
}
示例2: AddSingleValue
private static void AddSingleValue(AerospikeClient client,
WritePolicy writePolicy)
{
var newKey = new Key("test", "myAddSet", "myAddKey");
var counter = new Bin("mybin", 1);
client.Add(writePolicy, newKey, counter);
Console.WriteLine("Wrote this additional value (or bin): " + newKey);
Console.WriteLine("");
}