本文整理汇总了C#中Aerospike.Client.AerospikeClient.Get方法的典型用法代码示例。如果您正苦于以下问题:C# AerospikeClient.Get方法的具体用法?C# AerospikeClient.Get怎么用?C# AerospikeClient.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Aerospike.Client.AerospikeClient
的用法示例。
在下文中一共展示了AerospikeClient.Get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
}
示例2: 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.");
}
}
示例3: 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.");
}
}
示例4: 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.");
}
示例5: 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);
}
}
示例6: 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");
}
}
示例7: BatchReadRecords
private static void BatchReadRecords(AerospikeClient client, BatchPolicy batchPolicy)
{
Console.WriteLine("Batch Reads");
const int size = 1024;
var keys = new Key[size];
for (var i = 0; i < keys.Length; i++)
{
keys[i] = new Key("test", "myset", (i + 1));
}
var records = client.Get(batchPolicy, keys);
Console.WriteLine("Read " + records.Length + " records");
}
示例8: 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);
}
示例9: RunExample
/// <summary>
/// Prepend string to an existing string.
/// </summary>
public override void RunExample(AerospikeClient client, Arguments args)
{
Key key = new Key(args.ns, args.set, "prependkey");
string binName = args.GetBinName("prependbin");
// Delete record if it already exists.
client.Delete(args.writePolicy, key);
Bin bin = new Bin(binName, "World");
console.Info("Initial prepend will create record. Initial value is " + bin.value + '.');
client.Prepend(args.writePolicy, key, bin);
bin = new Bin(binName, "Hello ");
console.Info("Prepend \"" + bin.value + "\" to existing record.");
client.Prepend(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.
object received = record.GetValue(bin.name);
string expected = "Hello World";
if (received.Equals(expected))
{
console.Info("Prepend successful: namespace={0} set={1} key={2} bin={3} value={4}",
key.ns, key.setName, key.userKey, bin.name, received);
}
else
{
console.Error("Prepend mismatch: Expected {0}. Received {1}.", expected, received);
}
}
示例10: 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));
//.........这里部分代码省略.........
示例11: TestListCompoundList
/// <summary>
/// Write/Read list of compound objects using Aerospike list type with blob entries (Bin.AsList()).
/// </summary>
private void TestListCompoundList(AerospikeClient client, Arguments args)
{
console.Info("Read/Write ArrayList<CompoundObject> using list with blob entries");
Key key = new Key(args.ns, args.set, "listkey5");
client.Delete(args.writePolicy, key);
List<CompoundObject> list = new List<CompoundObject>();
list.Add(new CompoundObject("string1", 7));
list.Add(new CompoundObject("string2", 9));
list.Add(new CompoundObject("string3", 54));
Bin bin = new Bin("listbin", list);
client.Put(args.writePolicy, key, bin);
Record record = client.Get(args.policy, key, bin.name);
IList receivedList = (IList)record.GetValue(bin.name);
ValidateSize(3, receivedList.Count);
Validate(list[0], receivedList[0]);
Validate(list[1], receivedList[1]);
Validate(list[2], receivedList[2]);
console.Info("Read/Write ArrayList<CompoundObject> successful.");
}
示例12: WriteUsingUdf
private void WriteUsingUdf(AerospikeClient client, Arguments args)
{
Key key = new Key(args.ns, args.set, "udfkey1");
Bin bin = new Bin(args.GetBinName("udfbin1"), "string value");
client.Execute(args.writePolicy, key, "record_example", "writeBin", Value.Get(bin.name), bin.value);
Record record = client.Get(args.policy, key, bin.name);
string expected = bin.value.ToString();
string received = (string)record.GetValue(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: Expected {0}. Received {1}.", expected, received);
}
}
示例13: WriteIfNotExists
private void WriteIfNotExists(AerospikeClient client, Arguments args)
{
Key key = new Key(args.ns, args.set, "udfkey3");
string binName = "udfbin3";
// Delete record if it already exists.
client.Delete(args.writePolicy, key);
// Write record only if not already exists. This should succeed.
client.Execute(args.writePolicy, key, "record_example", "writeUnique", Value.Get(binName), Value.Get("first"));
// Verify record written.
Record record = client.Get(args.policy, key, binName);
string expected = "first";
string received = (string)record.GetValue(binName);
if (received != null && received.Equals(expected))
{
console.Info("Record written: namespace={0} set={1} key={2} bin={3} value={4}",
key.ns, key.setName, key.userKey, binName, received);
}
else
{
console.Error("Data mismatch: Expected {0}. Received {1}.", expected, received);
}
// Write record second time. This should fail.
console.Info("Attempt second write.");
client.Execute(args.writePolicy, key, "record_example", "writeUnique", Value.Get(binName), Value.Get("second"));
// Verify record not written.
record = client.Get(args.policy, key, binName);
received = (string)record.GetValue(binName);
if (received != null && received.Equals(expected))
{
console.Info("Success. Record remained unchanged: namespace={0} set={1} key={2} bin={3} value={4}",
key.ns, key.setName, key.userKey, binName, received);
}
else
{
console.Error("Data mismatch: Expected {0}. Received {1}.", expected, received);
}
}
示例14: TestListStrings
/// <summary>
/// Write/Read ArrayList<String> directly instead of relying on default serializer.
/// </summary>
private void TestListStrings(AerospikeClient client, Arguments args)
{
console.Info("Read/Write ArrayList<String>");
Key key = new Key(args.ns, args.set, "listkey1");
client.Delete(args.writePolicy, key);
List<object> list = new List<object>();
list.Add("string1");
list.Add("string2");
list.Add("string3");
Bin bin = new Bin(args.GetBinName("listbin1"), list);
client.Put(args.writePolicy, key, bin);
Record record = client.Get(args.policy, key, bin.name);
List<object> receivedList = (List<object>) record.GetValue(bin.name);
ValidateSize(3, receivedList.Count);
Validate("string1", receivedList[0]);
Validate("string2", receivedList[1]);
Validate("string3", receivedList[2]);
console.Info("Read/Write ArrayList<String> successful.");
}
示例15: RunSingleBinTest
/// <summary>
/// Execute put and get on a server configured as single-bin.
/// </summary>
private void RunSingleBinTest(AerospikeClient client, Arguments args)
{
Key key = new Key(args.ns, args.set, "putgetkey");
Bin bin = new Bin("", "value");
console.Info("Single Bin Put: namespace={0} set={1} key={2} value={3}",
key.ns, key.setName, key.userKey, bin.value);
client.Put(args.writePolicy, key, bin);
console.Info("Single Bin 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, bin, record);
}