本文整理汇总了C#中Aerospike.Client.AerospikeClient.Put方法的典型用法代码示例。如果您正苦于以下问题:C# AerospikeClient.Put方法的具体用法?C# AerospikeClient.Put怎么用?C# AerospikeClient.Put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Aerospike.Client.AerospikeClient
的用法示例。
在下文中一共展示了AerospikeClient.Put方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: generateCustomerProduct
public static void generateCustomerProduct(AerospikeClient client)
{
Random products = new Random (2727);
Random productsPerAccount = new Random (9898);
Random productQuantity = new Random (1919);
for (int i = 0; i < accountTotal; i++) {
int productsToAdd = productsPerAccount.Next (1, 150);
string keyString = i.ToString ();
Key cdtkey = new Key (ns, cdtSet, keyString);
Aerospike.Helper.Collection.LargeList clist = new Aerospike.Helper.Collection.LargeList (client, null, cdtkey, cdtBinName);
Key ldtkey = new Key (ns, ldtSet, keyString);
LargeList llist = client.GetLargeList (null, ldtkey, ldtBinName);
//for diagnositics
client.Put (null, cdtkey, new Bin (keyBinName, keyString), new Bin (accBinName, keyString));
client.Put (null, ldtkey, new Bin (keyBinName, keyString), new Bin (accBinName, keyString));
for (int j = 0; j < productsToAdd; j++) {
int product = products.Next (1, productTotal);
int productAmount = productQuantity.Next (1, 100);
Value value = makeValue (product, productAmount);
llist.Update (value);
clist.Update (value);
}
}
}
示例2: RunExample
/// <summary>
/// Drop a bin from a record.
/// </summary>
public override void RunExample(AerospikeClient client, Arguments args)
{
if (args.singleBin)
{
console.Info("Delete bin is not applicable to single bin servers.");
return;
}
console.Info("Write multi-bin record.");
Key key = new Key(args.ns, args.set, "delbinkey");
string binName1 = args.GetBinName("bin1");
string binName2 = args.GetBinName("bin2");
Bin bin1 = new Bin(binName1, "value1");
Bin bin2 = new Bin(binName2, "value2");
client.Put(args.writePolicy, key, bin1, bin2);
console.Info("Delete one bin in the record.");
bin1 = Bin.AsNull(binName1); // Set bin value to null to drop bin.
client.Put(args.writePolicy, key, bin1);
console.Info("Read record.");
Record record = client.Get(args.policy, key, bin1.name, bin2.name, "bin3");
if (record == null)
{
throw new Exception(string.Format("Failed to get: namespace={0} set={1} key={2}",
key.ns, key.setName, key.userKey));
}
foreach (KeyValuePair<string, object> entry in record.bins)
{
console.Info("Received: namespace={0} set={1} key={2} bin={3} value={4}",
key.ns, key.setName, key.userKey, entry.Key, entry.Value);
}
bool valid = true;
if (record.GetValue("bin1") != null)
{
console.Error("bin1 still exists.");
valid = false;
}
object v2 = record.GetValue("bin2");
if (v2 == null || !v2.Equals("value2"))
{
console.Error("bin2 value mismatch.");
valid = false;
}
if (valid)
{
console.Info("Bin delete successful");
}
}
示例3: RunReplaceExample
private void RunReplaceExample(AerospikeClient client, Arguments args)
{
Key key = new Key(args.ns, args.set, "replacekey");
Bin bin1 = new Bin("bin1", "value1");
Bin bin2 = new Bin("bin2", "value2");
Bin bin3 = new Bin("bin3", "value3");
console.Info("Put: namespace={0} set={1} key={2} bin1={3} value1={4} bin2={5} value2={6}",
key.ns, key.setName, key.userKey, bin1.name, bin1.value, bin2.name, bin2.value);
client.Put(args.writePolicy, key, bin1, bin2);
console.Info("Replace with: namespace={0} set={1} key={2} bin={3} value={4}",
key.ns, key.setName, key.userKey, bin3.name, bin3.value);
WritePolicy policy = new WritePolicy();
policy.recordExistsAction = RecordExistsAction.REPLACE;
client.Put(policy, key, bin3);
console.Info("Get: namespace={0} set={1} key={2}", key.ns, key.setName, key.userKey);
Record record = client.Get(args.policy, key);
if (record == null)
{
throw new Exception(string.Format("Failed to get: namespace={0} set={1} key={2}",
key.ns, key.setName, key.userKey));
}
if (record.GetValue(bin1.name) == null)
{
console.Info(bin1.name + " was deleted as expected.");
}
else
{
console.Error(bin1.name + " found when it should have been deleted.");
}
if (record.GetValue(bin2.name) == null)
{
console.Info(bin2.name + " was deleted as expected.");
}
else
{
console.Error(bin2.name + " found when it should have been deleted.");
}
ValidateBin(key, bin3, record);
}
示例4: RunExample
/// <summary>
/// Demonstrate multiple operations on a single record in one call.
/// </summary>
public override void RunExample(AerospikeClient client, Arguments args)
{
// Write initial record.
Key key = new Key(args.ns, args.set, "opkey");
Bin bin1 = new Bin("optintbin", 7);
Bin bin2 = new Bin("optstringbin", "string value");
console.Info("Put: namespace={0} set={1} key={2} binname1={3} binvalue1={4} binname1={5} binvalue1={6}",
key.ns, key.setName, key.userKey, bin1.name, bin1.value, bin2.name, bin2.value);
client.Put(args.writePolicy, key, bin1, bin2);
// Add integer, write new string and read record.
Bin bin3 = new Bin(bin1.name, 4);
Bin bin4 = new Bin(bin2.name, "new string");
console.Info("Add: " + bin3.value);
console.Info("Write: " + bin4.value);
console.Info("Read:");
Record record = client.Operate(args.writePolicy, key, Operation.Add(bin3), Operation.Put(bin4), Operation.Get());
if (record == null)
{
throw new Exception(string.Format("Failed to get: namespace={0} set={1} key={2}",
key.ns, key.setName, key.userKey));
}
ValidateBin(key, record, bin3.name, 11L, record.GetValue(bin3.name));
ValidateBin(key, record, bin4.name, bin4.value.ToString(), record.GetValue(bin4.name));
}
示例5: Button_Click
private void Button_Click(object sender, RoutedEventArgs e)
{
// Establish connection the server
try
{
AerospikeClient client = new AerospikeClient("45.55.231.46", 3000);
// Create key
Aerospike.Client.Key key = new Aerospike.Client.Key("test", "myset", "mykey");
// Create Bins
Bin bin1 = new Bin("name", "John");
Bin bin2 = new Bin("age", 25);
// Write record
client.Put(null, key, bin1, bin2);
// Read record
Record record = client.Get(null, key);
Record userRecord = client.Get(null, key);
Console.WriteLine("Info:");
Console.WriteLine("Name: " + userRecord.GetValue("name"));
Console.WriteLine("Age: " + userRecord.GetValue("age"));
// Close connection
client.Close();
}
catch (AerospikeException.Connection conError)
{
Console.Write(conError);
}
}
示例6: TestArray
/// <summary>
/// Write array of integers using standard C# serializer.
/// </summary>
public virtual void TestArray(AerospikeClient client, Arguments args)
{
Key key = new Key(args.ns, args.set, "serialarraykey");
// Delete record if it already exists.
client.Delete(args.writePolicy, key);
console.Info("Initialize array");
int[] array = new int[10000];
for (int i = 0; i < 10000; i++)
{
array[i] = i * i;
}
Bin bin = new Bin(args.GetBinName("serialbin"), (object)array);
// Do a test that pushes this complex object through the serializer
console.Info("Write array using serializer.");
client.Put(args.writePolicy, key, bin);
console.Info("Read array using serializer.");
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));
}
int[] received;
try
{
received = (int[])record.GetValue(bin.name);
}
catch (Exception)
{
throw new Exception(string.Format("Failed to parse returned value: namespace={0} set={1} key={2} bin={3}",
key.ns, key.setName, key.userKey, bin.name));
}
if (received.Length != 10000)
{
throw new Exception(string.Format("Array length mismatch: Expected={0:D} Received={1:D}",
10000, received.Length));
}
for (int i = 0; i < 10000; i++)
{
if (received[i] != i * i)
{
throw new Exception(string.Format("Mismatch: index={0:D} expected={1:D} received={2:D}",
i, i * i, received[i]));
}
}
console.Info("Read array successful.");
}
示例7: AddRecords
private static void AddRecords(AerospikeClient client,
WritePolicy writePolicy)
{
const int size = 1024;
for (var i = 0; i < size; i++)
{
var key = new Key("test", "myset", (i + 1));
client.Put(writePolicy, key, new Bin("dots", i + " dots"));
}
Console.WriteLine("Added " + size + " Records");
Console.WriteLine("");
}
示例8: RunExample
/// <summary>
/// Demonstrate touch command.
/// </summary>
public override void RunExample(AerospikeClient client, Arguments args)
{
Key key = new Key(args.ns, args.set, "touchkey");
Bin bin = new Bin(args.GetBinName("touchbin"), "touchvalue");
console.Info("Create record with 2 second expiration.");
WritePolicy writePolicy = new WritePolicy();
writePolicy.expiration = 2;
client.Put(writePolicy, key, bin);
console.Info("Touch same record with 5 second expiration.");
writePolicy.expiration = 5;
Record record = client.Operate(writePolicy, key, Operation.Touch(), Operation.GetHeader());
if (record == null)
{
throw new Exception(string.Format("Failed to get: namespace={0} set={1} key={2} bin={3} value={4}",
key.ns, key.setName, key.userKey, bin.name, null));
}
if (record.expiration == 0)
{
throw new Exception(string.Format("Failed to get record expiration: namespace={0} set={1} key={2}",
key.ns, key.setName, key.userKey));
}
console.Info("Sleep 3 seconds.");
Thread.Sleep(3000);
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));
}
console.Info("Success. Record still exists.");
console.Info("Sleep 4 seconds.");
Thread.Sleep(4000);
record = client.Get(args.policy, key, bin.name);
if (record == null)
{
console.Info("Success. Record expired as expected.");
}
else
{
console.Error("Found record when it should have expired.");
}
}
示例9: RunExample
/// <summary>
/// Write and twice read a bin value, demonstrating record expiration.
/// </summary>
public override void RunExample(AerospikeClient client, Arguments args)
{
Key key = new Key(args.ns, args.set, "expirekey");
Bin bin = new Bin(args.GetBinName("expirebin"), "expirevalue");
console.Info("Put: namespace={0} set={1} key={2} bin={3} value={4} expiration=2",
key.ns, key.setName, key.userKey, bin.name, bin.value);
// Specify that record expires 2 seconds after it's written.
WritePolicy writePolicy = new WritePolicy();
writePolicy.expiration = 2;
client.Put(writePolicy, key, bin);
// Read the record before it expires, showing it's there.
console.Info("Get: namespace={0} set={1} key={2}", key.ns, key.setName, key.userKey);
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));
}
object received = record.GetValue(bin.name);
string expected = bin.value.ToString();
if (received.Equals(expected))
{
console.Info("Get successful: namespace={0} set={1} key={2} bin={3} value={4}",
key.ns, key.setName, key.userKey, bin.name, received);
}
else
{
throw new Exception(string.Format("Expire mismatch: Expected {0}. Received {1}.", expected, received));
}
// Read the record after it expires, showing it's gone.
console.Info("Sleeping for 3 seconds ...");
Thread.Sleep(3 * 1000);
record = client.Get(args.policy, key, bin.name);
if (record == null)
{
console.Info("Expiry successful. Record not found.");
}
else
{
console.Error("Found record when it should have expired.");
}
}
示例10: ServerSideExists
private void ServerSideExists(AerospikeClient client, Arguments args)
{
console.Info("Write list.");
List<int> list = new List<int>();
list.Add(64);
list.Add(3702);
list.Add(-5);
Key key = new Key(args.ns, args.set, "udfkey7");
Bin bin = new Bin("udfbin7", list);
client.Put(args.writePolicy, key, bin);
ServerSideExists(client, args.writePolicy, key, bin, 3702, true);
ServerSideExists(client, args.writePolicy, key, bin, 65, false);
}
示例11: Write
public void Write(AerospikeClient client, WritePolicy policy, string ns, string set)
{
Key key = new Key(ns, set, ticker);
Bin binTicker = new Bin("ticker", ticker);
// Double not supported directly, so convert to bytes.
Bin binPrice = new Bin("price", BitConverter.GetBytes(price));
client.Put(policy, key, binTicker, binPrice);
}
示例12: RunExample
/// <summary>
/// Exercise record generation functionality.
/// </summary>
public override void RunExample(AerospikeClient client, Arguments args)
{
Key key = new Key(args.ns, args.set, "genkey");
string binName = args.GetBinName("genbin");
// Delete record if it already exists.
client.Delete(args.writePolicy, key);
// Set some values for the same record.
Bin bin = new Bin(binName, "genvalue1");
console.Info("Put: namespace={0} set={1} key={2} bin={3} value={4}",
key.ns, key.setName, key.userKey, bin.name, bin.value);
client.Put(args.writePolicy, key, bin);
bin = new Bin(binName, "genvalue2");
console.Info("Put: namespace={0} set={1} key={2} bin={3} value={4}",
key.ns, key.setName, key.userKey, bin.name, bin.value);
client.Put(args.writePolicy, key, bin);
// Retrieve record and its generation count.
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));
}
object received = record.GetValue(bin.name);
string expected = bin.value.ToString();
if (received.Equals(expected))
{
console.Info("Get successful: namespace={0} set={1} key={2} bin={3} value={4} generation={5}",
key.ns, key.setName, key.userKey, bin.name, received, record.generation);
}
else
{
throw new Exception(string.Format("Get mismatch: Expected {0}. Received {1}.", expected, received));
}
// Set record and fail if it's not the expected generation.
bin = new Bin(binName, "genvalue3");
console.Info("Put: namespace={0} set={1} key={2} bin={3} value={4} expected generation={5}",
key.ns, key.setName, key.userKey, bin.name, bin.value, record.generation);
WritePolicy writePolicy = new WritePolicy();
writePolicy.generationPolicy = GenerationPolicy.EXPECT_GEN_EQUAL;
writePolicy.generation = record.generation;
client.Put(writePolicy, key, bin);
// Set record with invalid generation and check results .
bin = new Bin(binName, "genvalue4");
writePolicy.generation = 9999;
console.Info("Put: namespace={0} set={1} key={2} bin={3} value={4} expected generation={5}",
key.ns, key.setName, key.userKey, bin.name, bin.value, writePolicy.generation);
try
{
client.Put(writePolicy, key, bin);
throw new Exception("Should have received generation error instead of success.");
}
catch (AerospikeException ae)
{
if (ae.Result == ResultCode.GENERATION_ERROR)
{
console.Info("Success: Generation error returned as expected.");
}
else
{
throw new Exception(string.Format("Unexpected set return code: namespace={0} set={1} key={2} bin={3} value={4} code={5}",
key.ns, key.setName, key.userKey, bin.name, bin.value, ae.Result));
}
}
// Verify results.
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));
}
received = record.GetValue(bin.name);
expected = "genvalue3";
if (received.Equals(expected))
{
console.Info("Get successful: namespace={0} set={1} key={2} bin={3} value={4} generation={5}",
key.ns, key.setName, key.userKey, bin.name, received, record.generation);
}
else
{
throw new Exception(string.Format("Get mismatch: Expected {0}. Received {1}.", expected, received));
//.........这里部分代码省略.........
示例13: TestMapComplex
/// <summary>
/// Write/Read HashMap<Object,Object> directly instead of relying on default serializer.
/// </summary>
private void TestMapComplex(AerospikeClient client, Arguments args)
{
console.Info("Read/Write HashMap<Object,Object>");
Key key = new Key(args.ns, args.set, "mapkey2");
client.Delete(args.writePolicy, key);
byte[] blob = new byte[] {3, 52, 125};
List<int> list = new List<int>();
list.Add(100034);
list.Add(12384955);
list.Add(3);
list.Add(512);
Dictionary<object, object> map = new Dictionary<object, object>();
map["key1"] = "string1";
map["key2"] = 2;
map["key3"] = blob;
map["key4"] = list;
Bin bin = new Bin(args.GetBinName("mapbin2"), map);
client.Put(args.writePolicy, key, bin);
Record record = client.Get(args.policy, key, bin.name);
Dictionary<object, object> receivedMap = (Dictionary<object, object>)record.GetValue(bin.name);
ValidateSize(4, receivedMap.Count);
Validate("string1", receivedMap["key1"]);
// Server convert numbers to long, so must expect long.
Validate(2L, receivedMap["key2"]);
Validate(blob, (byte[])receivedMap["key3"]);
IList receivedInner = (IList)receivedMap["key4"];
ValidateSize(4, receivedInner.Count);
Validate(100034L, receivedInner[0]);
Validate(12384955L, receivedInner[1]);
Validate(3L, receivedInner[2]);
Validate(512L, receivedInner[3]);
console.Info("Read/Write HashMap<Object,Object> successful");
}
示例14: TestComplex
/// <summary>
/// Write complex object using standard C# serializer.
/// </summary>
public virtual void TestComplex(AerospikeClient client, Arguments args)
{
Key key = new Key(args.ns, args.set, "serialcomplexkey");
// Delete record if it already exists.
client.Delete(args.writePolicy, key);
console.Info("Initialize complex object");
List<object> inner = new List<object>();
inner.Add("string2");
inner.Add(8);
Dictionary<object, object> innerMap = new Dictionary<object, object>();
innerMap["a"] = 1;
innerMap[2] = "b";
innerMap["list"] = inner;
List<object> list = new List<object>();
list.Add("string1");
list.Add(4);
list.Add(inner);
list.Add(innerMap);
Bin bin = new Bin(args.GetBinName("complexbin"), (object)list);
console.Info("Write complex object using serializer.");
client.Put(args.writePolicy, key, bin);
console.Info("Read complex object using serializer.");
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));
}
string expected = Util.ListToString(list);
string received;
try
{
object val = record.GetValue(bin.name);
received = Util.ObjectToString(val);
}
catch (Exception)
{
throw new Exception(string.Format("Failed to parse returned value: namespace={0} set={1} key={2} bin={3}",
key.ns, key.setName, key.userKey, bin.name));
}
if (received != null && received.Equals(expected))
{
console.Info("Data matched: namespace={0} set={1} key={2} bin={3} value={4}",
key.ns, key.setName, key.userKey, bin.name, received);
}
else
{
console.Error("Data mismatch");
console.Error("Expected " + expected);
console.Error("Received " + received);
}
console.Info("Read complex object successful.");
}
示例15: RunMultiBinTest
/// <summary>
/// Execute put and get on a server configured as multi-bin. This is the server default.
/// </summary>
private void RunMultiBinTest(AerospikeClient client, Arguments args)
{
Key key = new Key(args.ns, args.set, "putgetkey");
Bin bin1 = new Bin("bin1", "value1");
Bin bin2 = new Bin("bin2", "value2");
console.Info("Put: namespace={0} set={1} key={2} bin1={3} value1={4} bin2={5} value2={6}",
key.ns, key.setName, key.userKey, bin1.name, bin1.value, bin2.name, bin2.value);
client.Put(args.writePolicy, key, bin1, bin2);
console.Info("Get: namespace={0} set={1} key={2}", key.ns, key.setName, key.userKey);
Record record = client.Get(args.policy, key);
if (record == null)
{
throw new Exception(string.Format("Failed to get: namespace={0} set={1} key={2}",
key.ns, key.setName, key.userKey));
}
ValidateBin(key, bin1, record);
ValidateBin(key, bin2, record);
}