本文整理汇总了C#中Aerospike.Client.AerospikeClient.CreateIndex方法的典型用法代码示例。如果您正苦于以下问题:C# AerospikeClient.CreateIndex方法的具体用法?C# AerospikeClient.CreateIndex怎么用?C# AerospikeClient.CreateIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Aerospike.Client.AerospikeClient
的用法示例。
在下文中一共展示了AerospikeClient.CreateIndex方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateIndex
private void CreateIndex(AerospikeClient client, Arguments args, IndexCollectionType indexType, string indexName, string binName)
{
console.Info("Create GeoJSON {0} index: ns={1} set={2} index={3} bin={4}", indexType, args.ns, args.set, indexName, binName);
Policy policy = new Policy();
policy.timeout = 0; // Do not timeout on index create.
IndexTask task = client.CreateIndex(policy, args.ns, args.set, indexName, binName, IndexType.GEO2DSPHERE, indexType);
task.Wait();
}
示例2: CreateIndex
private void CreateIndex(AerospikeClient client, Arguments args, string indexName, string binName)
{
console.Info("Create index: ns={0} set={1} index={2} bin={3}",
args.ns, args.set, indexName, binName);
Policy policy = new Policy();
policy.timeout = 0; // Do not timeout on index create.
IndexTask task = client.CreateIndex(policy, args.ns, args.set, indexName, binName, IndexType.NUMERIC);
task.Wait();
}
示例3: 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"));
//.........这里部分代码省略.........