本文整理汇总了C#中Aerospike.Client.AerospikeClient.Query方法的典型用法代码示例。如果您正苦于以下问题:C# AerospikeClient.Query方法的具体用法?C# AerospikeClient.Query怎么用?C# AerospikeClient.Query使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Aerospike.Client.AerospikeClient
的用法示例。
在下文中一共展示了AerospikeClient.Query方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RunQuery
private void RunQuery(AerospikeClient client, Arguments args, string indexName, string binName, string valuePrefix)
{
string filter = valuePrefix + 3;
console.Info("Query for: ns={0} set={1} index={2} bin={3} filter={4}",
args.ns, args.set, indexName, binName, filter);
Statement stmt = new Statement();
stmt.SetNamespace(args.ns);
stmt.SetSetName(args.set);
stmt.SetBinNames(binName);
stmt.SetFilters(Filter.Equal(binName, filter));
RecordSet rs = client.Query(null, stmt);
try
{
int count = 0;
while (rs.Next())
{
Key key = rs.Key;
Record record = rs.Record;
string result = (string)record.GetValue(binName);
if (result.Equals(filter))
{
console.Info("Record found: namespace={0} set={1} digest={2} bin={3} value={4}",
key.ns, key.setName, ByteUtil.BytesToHexString(key.digest), binName, result);
}
else
{
console.Error("Query mismatch: Expected {0}. Received {1}.", filter, result);
}
count++;
}
if (count == 0)
{
console.Error("Query failed. No records returned.");
}
}
finally
{
rs.Close();
}
}
示例2: RunQuery
private void RunQuery(AerospikeClient client, Arguments args, string indexName, string binName)
{
int begin = 14;
int end = 18;
console.Info("Query for: ns={0} set={1} index={2} bin={3} >= {4} <= {5}",
args.ns, args.set, indexName, binName, begin, end);
Statement stmt = new Statement();
stmt.SetNamespace(args.ns);
stmt.SetSetName(args.set);
stmt.SetBinNames(binName);
stmt.SetFilters(Filter.Range(binName, begin, end));
RecordSet rs = client.Query(null, stmt);
try
{
int count = 0;
while (rs.Next())
{
Key key = rs.Key;
Record record = rs.Record;
long result = record.GetLong(binName);
console.Info("Record found: namespace={0} set={1} digest={2} bin={3} value={4}",
key.ns, key.setName, ByteUtil.BytesToHexString(key.digest), binName, result);
count++;
}
if (count != 5)
{
console.Error("Query count mismatch. Expected 5. Received " + count);
}
}
finally
{
rs.Close();
}
}
示例3: ValidateRecords
private void ValidateRecords(AerospikeClient client, Arguments args, string indexName, string binName1, string binName2, int size)
{
int begin = 1;
int end = size + 100;
console.Info("Validate records");
Statement stmt = new Statement();
stmt.SetNamespace(args.ns);
stmt.SetSetName(args.set);
stmt.SetFilters(Filter.Range(binName1, begin, end));
RecordSet rs = client.Query(null, stmt);
try
{
int[] expectedList = new int[] {1,2,3,104,5,106,7,108,-1,10};
int expectedSize = size - 1;
int count = 0;
while (rs.Next())
{
Key key = rs.Key;
Record record = rs.Record;
object value1 = null;
object value2 = null;
record.bins.TryGetValue(binName1, out value1);
record.bins.TryGetValue(binName2, out value2);
console.Info("Record found: ns={0} set={1} bin1={2} value1={3} bin2={4} value2={5}",
key.ns, key.setName, binName1, value1, binName2, value2);
if (value1 == null)
{
console.Error("Data mismatch. value1 is null");
break;
}
long val1 = (long)value1;
if (val1 == 9)
{
console.Error("Data mismatch. value1 " + val1 + " should not exist");
break;
}
if (val1 == 5)
{
if (value2 != null)
{
console.Error("Data mismatch. value2 " + value2 + " should be null");
break;
}
}
else
{
long val2 = (long)value2;
if (val1 != expectedList[val2 - 1])
{
console.Error("Data mismatch. Expected " + expectedList[val2 - 1] + ". Received " + value1);
break;
}
}
count++;
}
if (count != expectedSize)
{
console.Error("Query count mismatch. Expected " + expectedSize + ". Received " + count);
}
}
finally
{
rs.Close();
}
}
示例4: RunQuery
private void RunQuery(AerospikeClient client, Arguments args, string binName, string binName2, IndexCollectionType indexType)
{
console.Info("Query for: ns={0} set={1} bin={2} {3} within <region>", args.ns, args.set, binName, indexType.ToString());
StringBuilder rgnsb = GenerateQueryRegion();
Statement stmt = new Statement();
stmt.SetNamespace(args.ns);
stmt.SetSetName(args.set);
stmt.SetFilters(Filter.GeoWithinRegion(binName, indexType, rgnsb.ToString()));
RecordSet rs = client.Query(null, stmt);
try
{
int count = 0;
HashSet<string> uniques = new HashSet<string>();
while (rs.Next())
{
Record record = rs.Record;
string val = record.GetString(binName2);
uniques.Add(val);
count++;
}
if (count != 697)
{
console.Error("Query failed. {0} records expected. {1} returned.", 697, count);
}
else if (uniques.Count != 21)
{
console.Error("Query failed. {0} unique records expected. {1} unique returned.", 21, uniques.Count);
}
else
{
console.Info("query succeeded with {0} records {1} unique", count, uniques.Count);
}
}
finally
{
rs.Close();
}
}
示例5: Main
public static void Main(string[] args)
{
String ns = "test";
String set = "demo";
String host = "127.0.0.1";
int port = 3000;
const int MAX_RECORDS = 1000;
AerospikeClient client = new AerospikeClient(host, port);
/*
* Create an index on list values
*/
IndexTask creator = client.CreateIndex(null, ns, set,
"list_value_index", "interests", IndexType.STRING,
IndexCollectionType.LIST);
creator.IsDone();
Console.WriteLine("created list value index");
/*
* Create an index on map keys
*/
creator = client.CreateIndex(null, ns, set,
"map_key_index", "email", IndexType.STRING,
IndexCollectionType.MAPKEYS);
creator.IsDone();
Console.WriteLine("created map keys index");
/*
* Create an index on map keys
*/
creator = client.CreateIndex(null, ns, set,
"map_value_index", "email", IndexType.STRING,
IndexCollectionType.MAPVALUES);
creator.IsDone();
Console.WriteLine("created map values index");
/*
* Load some data
*/
String[] possibleInterests = new String[]{"cats", "dogs", "mice", "birds", "snakes", "fish", "pigs", "cows"};
String[] emailPostFix = new String[]{"@gmail.com", "@hotmail.com", "@yahoo.com"};
String[] emailType = new String[]{"home", "work", "private"};
Random rand1 = new Random();
Random rand2 = new Random();
for (int i = 0; i < MAX_RECORDS; i++){
/*
* create key
*/
String userName = "user"+i;
Key key = new Key(ns, set, userName);
Bin user = new Bin("user", userName);
/*
* create interests
*/
List<String> interestList = new List<String>();
int interest_count = rand1.Next(possibleInterests.Length-1);
for (int j = 0; j < interest_count; j++){
interestList.Add(possibleInterests[rand2.Next(possibleInterests.Length-1)]);
}
Bin interests = new Bin("interests", interestList);
/*
* create email addresses
*/
Dictionary<String, String> emailAddresses = new Dictionary<String, String>();
int email_count = rand1.Next(emailPostFix.Length-1);
for (int j = 0; j < email_count; j++){
String type = emailType[rand2.Next(emailType.Length-1)];
String emailString = userName + emailPostFix[rand2.Next(emailPostFix.Length-1)];
emailAddresses.Add(type, emailString);
}
Bin emails = new Bin("email", emailAddresses);
client.Put(null, key, user, interests, emails);
}
Console.WriteLine(String.Format("created {0} users", MAX_RECORDS));
/*
* Query for users interested in "cats"
*/
Statement stmt = new Statement();
stmt.SetNamespace(ns);
stmt.SetSetName(set);
stmt.SetBinNames("user", "interests");
stmt.SetFilters(Filter.Contains("interests", IndexCollectionType.LIST, "cats"));
RecordSet recordSet = client.Query(null, stmt);
int recordCount = 0;
try {
while(recordSet.Next()){
Console.WriteLine(recordSet.Record);
recordCount++;
}
} finally {
recordSet.Close();
}
Console.WriteLine(String.Format("Found {0} users interested in cats", recordCount));
/*
* Query for users with "work" email addresses.
*/
stmt.SetBinNames("user", "email");
stmt.SetFilters(Filter.Contains("email", IndexCollectionType.MAPKEYS, "work"));
//.........这里部分代码省略.........
示例6: RunQuery
private void RunQuery(AerospikeClient client, Arguments args, string indexName, string binName)
{
StringBuilder rgnsb = new StringBuilder();
rgnsb.Append("{ ");
rgnsb.Append(" \"type\": \"Polygon\", ");
rgnsb.Append(" \"coordinates\": [ ");
rgnsb.Append(" [[-122.500000, 37.000000],[-121.000000, 37.000000], ");
rgnsb.Append(" [-121.000000, 38.080000],[-122.500000, 38.080000], ");
rgnsb.Append(" [-122.500000, 37.000000]] ");
rgnsb.Append(" ] ");
rgnsb.Append(" } ");
console.Info("QueryRegion: " + rgnsb);
Statement stmt = new Statement();
stmt.SetNamespace(args.ns);
stmt.SetSetName(args.set);
stmt.SetBinNames(binName);
stmt.SetFilters(Filter.GeoWithinRegion(binName, rgnsb.ToString()));
RecordSet rs = client.Query(null, stmt);
try
{
int count = 0;
while (rs.Next())
{
Key key = rs.Key;
Record record = rs.Record;
string result = record.GetGeoJSON(binName);
console.Info("Record found: " + result);
count++;
}
if (count != 6)
{
console.Error("Query count mismatch. Expected 6. Received " + count);
}
}
finally
{
rs.Close();
}
}
示例7: RunRadiusQuery
private void RunRadiusQuery(AerospikeClient client, Arguments args, string indexName, string binName)
{
double lon = -122.0;
double lat = 37.5;
double radius = 50000.0;
console.Info("QueryRadius long=" + lon + " lat= " + lat + " radius=" + radius);
Statement stmt = new Statement();
stmt.SetNamespace(args.ns);
stmt.SetSetName(args.set);
stmt.SetBinNames(binName);
stmt.SetFilters(Filter.GeoWithinRadius(binName, lon, lat, radius));
RecordSet rs = client.Query(null, stmt);
try
{
int count = 0;
while (rs.Next())
{
Key key = rs.Key;
Record record = rs.Record;
string result = record.GetGeoJSON(binName);
console.Info("Record found: " + result);
count++;
}
if (count != 4)
{
console.Error("Query count mismatch. Expected 4. Received " + count);
}
}
finally
{
rs.Close();
}
}