本文整理汇总了C#中CouchbaseClient.ExecuteStore方法的典型用法代码示例。如果您正苦于以下问题:C# CouchbaseClient.ExecuteStore方法的具体用法?C# CouchbaseClient.ExecuteStore怎么用?C# CouchbaseClient.ExecuteStore使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CouchbaseClient
的用法示例。
在下文中一共展示了CouchbaseClient.ExecuteStore方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
public override void Run()
{
var config = new CouchbaseClientConfiguration();
config.Urls.Add(new Uri("http://localhost:8091/pools/"));
config.Bucket = "default";
var client = new CouchbaseClient(config);
//Store a key, but don't return success until it is written
//to disk on the master (or times out)
var success = client.ExecuteStore(StoreMode.Set, "key_1", 2, PersistTo.One);
Console.WriteLine(success.Success); //will return false
//Store a key, but don't return success until it is
//replicated to 2 nodes (or times out)
//will fail on a single or two node cluster
success = client.ExecuteStore(StoreMode.Set, "key_1", 2, ReplicateTo.Two);
Console.WriteLine(success.Success); //will return false
//Store a key, but don't return success until it is written
//to disk on the master and replicated to 2 nodes (or times out)
//will fail on a single or two node cluster
success = client.ExecuteStore(StoreMode.Set, "key_1", 2, PersistTo.One, ReplicateTo.Two);
Console.WriteLine(success.Success); //will return false
client.Remove("key_1");
client.Remove("key_2");
}
示例2: Run
public override void Run()
{
var config = new CouchbaseClientConfiguration();
config.Urls.Add(new Uri("http://localhost:8091/pools/"));
config.Bucket = "default";
var client = new CouchbaseClient(config);
var user1 = new User
{
Username = "cmathison",
Name = "Carrie Mathison",
Email = "[email protected]",
Password = "IHeartNick",
Logins = 0
};
var user2 = new User
{
Username = "nbrody",
Name = "Nicholas Brody",
Email = "[email protected]",
Password = "issa",
Logins = 0
};
//store the user - ExecuteStore returns detailed error info, if any
var result1 = client.ExecuteStore(StoreMode.Set, user1.Email, user1);
if (!result1.Success)
{
Console.WriteLine("Store failed with message {0} and status code {1}", result1.Message, result1.StatusCode);
if (result1.Exception != null)
{
throw result1.Exception;
}
}
var result2 = client.ExecuteStore(StoreMode.Set, user2.Email, user2);
//same check as result1 would be useful
var doc = client.Get<User>(user1.Email);
Console.WriteLine(doc.Name);
//get doc with extended info
var result = client.ExecuteGet<User>(user1.Email);
//update login count
doc.Logins += 1;
//update document (ignore errors for lab)
client.ExecuteStore(StoreMode.Replace, user1.Email, doc);
doc = client.Get<User>(user1.Email);
Console.WriteLine("User {0} had {1} logins", doc.Name, doc.Logins);
client.Remove(user1.Email);
client.Remove(user2.Email);
}
示例3: ParallerInsert
static void ParallerInsert(CouchbaseClient client, int n)
{
var options = new ParallelOptions { MaxDegreeOfParallelism = 4 };
Parallel.For(0, n, options, i =>
{
var key = "key" + i;
var value = "value" + i;
var result = client.ExecuteStore(StoreMode.Set, key, value);
if (result.Success)
{
Console.WriteLine("Write Key: {0} - Value: {1}", key, value);
var result2 = client.ExecuteGet<string>(key);
if (result2.Success)
{
Console.WriteLine("Read Key: {0} - Value: {1}", key, result2.Value);
}
else
{
Console.WriteLine("Read Error: {0} - {1}", key, result.Message);
}
}
else
{
Console.WriteLine("Write Error: {0} - {1}", key, result.Message);
}
});
}
示例4: SynchronousInsert
static void SynchronousInsert(CouchbaseClient client, int n)
{
for (int i = 0; i < n; i++)
{
var key = "key" + i;
var value = "value" + i;
var result = client.ExecuteStore(StoreMode.Set, key, value);
if (result.Success)
{
Console.WriteLine("Write Key: {0} - Value: {1}", key, value);
var result2 = client.ExecuteGet<string>(key);
if (result2.Success)
{
Console.WriteLine("Read Key: {0} - Value: {1}", key, result2.Value);
}
else
{
Console.WriteLine("Read Error: {0} - {1}", key, result.Message);
}
}
else
{
Console.WriteLine("Write Error: {0} - {1}", key, result.Message);
}
}
}
示例5: Client_Operations_Succeed_When_Bootstrapping_To_Pools_Root_Uri
public void Client_Operations_Succeed_When_Bootstrapping_To_Pools_Root_Uri()
{
var config = ConfigSectionUtils.GetConfigSection<CouchbaseClientSection>("pools-config");
var client = new CouchbaseClient(config);
string key = GetUniqueKey(), value = GetRandomString();
var storeResult = client.ExecuteStore(StoreMode.Add, key, value);
StoreAssertPass(storeResult);
var getResult = client.ExecuteGet(key);
GetAssertPass(getResult, value);
}
示例6: Client_Operations_Succeed_When_Heartbeat_Is_Not_Configured
public void Client_Operations_Succeed_When_Heartbeat_Is_Not_Configured()
{
var config = ConfigSectionUtils.GetConfigSection<CouchbaseClientSection>("min-config");
var client = new CouchbaseClient(config);
string key = GetUniqueKey(), value = GetRandomString();
var storeResult = client.ExecuteStore(StoreMode.Add, key, value);
StoreAssertPass(storeResult);
var getResult = client.ExecuteGet(key);
GetAssertPass(getResult, value);
}
示例7: When_Storing_A_Key_From_A_Down_Node_No_Exception_Is_Thrown_And_Success_Is_False
public void When_Storing_A_Key_From_A_Down_Node_No_Exception_Is_Thrown_And_Success_Is_False()
{
var config = new CouchbaseClientConfiguration();
config.Urls.Add(new Uri("http://doesnotexist:8091/pools/"));
config.Bucket = "default";
var client = new CouchbaseClient(config);
var storeResult = client.ExecuteStore(StoreMode.Set, "foo", "bar");
Assert.That(storeResult.Success, Is.False);
Assert.That(storeResult.Message, Is.StringContaining(ClientErrors.FAILURE_NODE_NOT_FOUND));
}
示例8: Client_Operations_Succeed_When_Bootstrapping_To_Pools_Default_Root_Uri
public void Client_Operations_Succeed_When_Bootstrapping_To_Pools_Default_Root_Uri()
{
var config = ConfigSectionUtils.GetConfigSection<CouchbaseClientSection>("pools-default-config");
var client = new CouchbaseClient(config);
string key = GetUniqueKey(), value = GetRandomString();
var storeResult = client.ExecuteStore(StoreMode.Add, key, value);
Assert.That(storeResult.Success, Is.True, "Success was false");
Assert.That(storeResult.Message, Is.Null.Or.Empty, "Message was not empty");
var getResult = client.ExecuteGet(key);
GetAssertPass(getResult, value);
}
示例9: Client_Operations_Succeed_When_Heartbeat_Is_Disabled
public void Client_Operations_Succeed_When_Heartbeat_Is_Disabled()
{
var config = ConfigSectionUtils.GetConfigSection<CouchbaseClientSection>("heartbeat-config-off");
using (var client = new CouchbaseClient(config))
{
string key = TestUtils.GetUniqueKey(), value = TestUtils.GetRandomString();
var storeResult = client.ExecuteStore(StoreMode.Add, key, value);
TestUtils.StoreAssertPass(storeResult);
var getResult = client.ExecuteGet(key);
TestUtils.GetAssertPass(getResult, value);
}
}
示例10: import
private static void import(CouchbaseClient client, string directory)
{
var dir = new DirectoryInfo(directory);
foreach (var file in dir.GetFiles())
{
if (file.Extension != ".json") continue;
Console.WriteLine("Adding {0}", file);
var json = File.ReadAllText(file.FullName);
var key = file.Name.Replace(file.Extension, "");
json = Regex.Replace(json.Replace(key, "LAZY"), "\"_id\":\"LAZY\",","");
var storeResult = client.ExecuteStore(StoreMode.Set, key, json);
Console.WriteLine(storeResult.Message);
}
}
示例11: Client_Operations_Succeed_When_Bootstrapping_To_Pools_Root_Uri
public void Client_Operations_Succeed_When_Bootstrapping_To_Pools_Root_Uri()
{
var config = new CouchbaseClientConfiguration();
config.Urls.Add(new Uri("http://localhost:8091/pools"));
config.Bucket = "default";
var client = new CouchbaseClient(config);
string key = GetUniqueKey(), value = GetRandomString();
var storeResult = client.ExecuteStore(StoreMode.Add, key, value);
StoreAssertPass(storeResult);
var getResult = client.ExecuteGet(key);
GetAssertPass(getResult, value);
}
示例12: Client_Operations_Succeed_When_Bootstrapping_To_Pools_Default_Root_Uri
public void Client_Operations_Succeed_When_Bootstrapping_To_Pools_Default_Root_Uri()
{
var config = new CouchbaseClientConfiguration();
config.Urls.Add(new Uri("http://localhost:8091/pools/default"));
config.Bucket = "default";
var client = new CouchbaseClient(config);
string key = GetUniqueKey(), value = GetRandomString();
var storeResult = client.ExecuteStore(StoreMode.Add, key, value);
Assert.That(storeResult.Success, Is.True, "Success was false");
Assert.That(storeResult.Message, Is.Null.Or.Empty, "Message was not empty");
var getResult = client.ExecuteGet(key);
GetAssertPass(getResult, value);
}
示例13: Main
public static void Main()
{
var clientA = new CouchbaseClient("couchbase");
var clientB = new CouchbaseClient();
clientA.Remove("fooA");
IStoreOperationResult result = clientA.ExecuteStore(StoreMode.Set, "fooA", "barA");
var itemA = clientA.Get<string>("fooA");
Console.WriteLine(itemA);
clientB.ExecuteStore(StoreMode.Set, "fooB", "barB");
var itemB = clientB.Get<string>("fooB");
Console.WriteLine(itemB);
Console.ReadLine();
}
示例14: Client_Operations_Succeed_When_Heartbeat_Is_Configured
public void Client_Operations_Succeed_When_Heartbeat_Is_Configured()
{
var config = new CouchbaseClientConfiguration();
config.Urls.Add(new Uri("http://localhost:8091/pools"));
config.Bucket = "default";
config.HeartbeatMonitor = new HeartbeatMonitorElement();
config.HeartbeatMonitor.Enabled = true;
config.HeartbeatMonitor.Interval = 100;
config.HeartbeatMonitor.Uri = "http://localhost:8091/pools";
var client = new CouchbaseClient(config);
string key = GetUniqueKey(), value = GetRandomString();
var storeResult = client.ExecuteStore(StoreMode.Add, key, value);
StoreAssertPass(storeResult);
var getResult = client.ExecuteGet(key);
GetAssertPass(getResult, value);
}
示例15: When_Using_Code_Config_And_HttpClient_Factory_Is_Not_Set_Operations_Succeed
public void When_Using_Code_Config_And_HttpClient_Factory_Is_Not_Set_Operations_Succeed()
{
var config = new CouchbaseClientConfiguration();
config.Urls.Add(new Uri("http://localhost:8091/pools"));
Assert.That(config.HttpClientFactory, Is.InstanceOf<DefaultHttpClientFactory>());
Assert.That(config, Is.Not.Null, "min-config section missing from app.config");
Assert.That(config.HttpClientFactory, Is.InstanceOf<DefaultHttpClientFactory>());
var client = new CouchbaseClient(config);
var kv = KeyValueUtils.GenerateKeyAndValue("default_config");
var result = client.ExecuteStore(StoreMode.Add, kv.Item1, kv.Item2);
Assert.That(result.Success, Is.True, "Store failed: " + result.Message);
var value = client.Get(kv.Item1);
Assert.That(value, Is.StringMatching(kv.Item2));
}