本文整理汇总了C#中CouchbaseClient.Store方法的典型用法代码示例。如果您正苦于以下问题:C# CouchbaseClient.Store方法的具体用法?C# CouchbaseClient.Store怎么用?C# CouchbaseClient.Store使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CouchbaseClient
的用法示例。
在下文中一共展示了CouchbaseClient.Store方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Test_Store_StoreMode_Set
public void Test_Store_StoreMode_Set()
{
var client = new CouchbaseClient("memcached-config");
var result = client.Store(StoreMode.Set, Key, "value");
Assert.AreEqual(result, true);
client.Remove(Key);
}
示例2: using
bool ICacheManager.Set(string key, object value, DateTime expiry)
{
bool bRet = false;
using (var client = new CouchbaseClient(config))
{
bRet = client.Store(Enyim.Caching.Memcached.StoreMode.Set, key, value, expiry);
}
return bRet;
}
示例3: 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);
//add or replace a key
client.Store(StoreMode.Set, "key_1", 1);
Console.WriteLine(client.Get("key_1"));
var success = client.Store(StoreMode.Add, "key_1", 2);
Console.WriteLine(success); //will return false
success = client.Store(StoreMode.Replace, "key_1", 2);
Console.WriteLine(success); //will return true
success = client.Store(StoreMode.Replace, "key_2", 2);
Console.WriteLine(success); //will return false
//add a new key
client.Store(StoreMode.Set, "key_3", 1);
Console.WriteLine(client.Get("key_3"));
client.Remove("key_1");
client.Remove("key_2");
}
示例4: Main
public Main()
{
InitializeComponent();
var bucketASection = (CouchbaseClientSection) ConfigurationManager.GetSection("couchbase/xCMS");
var client = new CouchbaseClient(bucketASection, "xCMS", "");
var data = client.Store(StoreMode.Add, "0000", "SomeValue");
textBox1.Text = data.ToString();
}
示例5: Main
static void Main(string[] args)
{
log4net.Config.XmlConfigurator.Configure();
//Manually configure CouchbaseClient
//May also use app/web.config section
var config = new CouchbaseClientConfiguration();
config.Bucket = "default";
config.BucketPassword = "";
config.Urls.Add(new Uri("http://10.0.0.79:8091/pools"));
config.DesignDocumentNameTransformer = new ProductionModeNameTransformer();
config.HttpClientFactory = new HammockHttpClientFactory();
//Quick test of Store/Get operations
var client = new CouchbaseClient(config);
var result = client.Store(StoreMode.Set, "foo", "bar");
Debug.Assert(result, "Store failed");
Console.WriteLine("Item saved successfully");
var value = client.Get<string>("foo");
Debug.Assert(value == "bar", "Get failed");
Console.WriteLine("Item retrieved succesfully");
processJson(client);
Console.WriteLine("\r\n\r\n*** SAMPLE VIEWS MUST BE CREATED - SEE SampleViews.js in Data directory ***");
Console.WriteLine("\r\n\r\nRequesting view all_breweries");
var allBreweries = client.GetView<Brewery>("breweries", "all_breweries");
foreach (var item in allBreweries)
{
Console.WriteLine(item.Name);
}
Console.WriteLine("\r\n\r\nRequesting view beers_by_name");
var beersByName = client.GetView<Beer>("beers", "beers_by_name").StartKey("T");
foreach (var item in beersByName)
{
Console.WriteLine(item.Name);
}
Console.WriteLine("\r\n\r\nRequesting view beers_by_name_and_abv");
var beersByNameAndABV = client.GetView<Beer>("beers", "beers_by_name_and_abv")
.StartKey(new object[] { "T", 6 });
foreach (var item in beersByNameAndABV)
{
Console.WriteLine(item.Name);
}
}
示例6: When_Using_App_Config_And_Http_Client_Factory_Is_Not_Set_Operations_Succeed
public void When_Using_App_Config_And_Http_Client_Factory_Is_Not_Set_Operations_Succeed()
{
var config = ConfigurationManager.GetSection("min-config") as CouchbaseClientSection;
Assert.That(config, Is.Not.Null, "min-config section missing from app.config");
Assert.That(config.HttpClientFactory, Is.InstanceOf<ProviderElement<IHttpClientFactory>>());
var client = new CouchbaseClient(config);
var kv = KeyValueUtils.GenerateKeyAndValue("default_config");
var result = client.Store(StoreMode.Add, kv.Item1, kv.Item2);
Assert.That(result, Is.True, "Store failed");
var value = client.Get(kv.Item1);
Assert.That(value, Is.StringMatching(kv.Item2));
}
示例7: import
private static void import(CouchbaseClient client, string type, 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 jObj = JsonConvert.DeserializeObject(json) as JObject;
jObj.Add("type", type);
if (type == "beer")
{
jObj["brewery"] = "brewery_" + jObj["brewery"].ToString().Replace(" ", "_");
}
var storeResult = client.Store(StoreMode.Set, key, jObj.ToString());
Console.WriteLine(storeResult);
}
}
示例8: import
private static void import(CouchbaseClient client, string type, string rootDir, string zipFile)
{
unzipDataFiles(rootDir, zipFile);
var dataFilesPath = Path.Combine(rootDir, zipFile.Replace(".zip", ""));
var dir = new DirectoryInfo(dataFilesPath);
foreach (var file in dir.GetFiles("*.json"))
{
var json = System.IO.File.ReadAllText(file.FullName);
var key = file.Name.Replace(file.Extension, "");
var jObj = JsonConvert.DeserializeObject(json) as JObject;
jObj.Remove("_id");
jObj.Add("type", type);
if (type == "beer")
{
jObj["brewery"] = "brewery_" + jObj["brewery"].ToString().Replace(" ", "_");
}
var storeResult = client.Store(StoreMode.Set, key, jObj.ToString());
Console.WriteLine("Store result for {0}: {1}", file.Name, storeResult);
}
}
示例9: processJson
private static void processJson(CouchbaseClient client)
{
var dict = new Dictionary<string, string>();
Action<string> process = s =>
{
using (StreamReader reader = new StreamReader(@"..\..\Data\" + s + ".json"))
{
string line;
while ((line = reader.ReadLine()) != null)
{
var jsonLine = JsonSerializer.DeserializeFromString(line, typeof(JsonObject));
var jsonDict = jsonLine.ToStringDictionary();
var id = jsonDict["_id"];
//_id is reserved and can't be in JSON document
var idPropAndVal = "\"_id\" : \"" + id + "\", ";
//HACK://This is just data loading code, it's OK, right?
if (s == "breweries")
{
var key = id.Split('_')[0];
dict[key] = id;
}
else if (s == "beers")
{
var bid = jsonDict["breweryId"];
if (dict.ContainsKey(bid))
{
line = line.Replace(bid.ToString(), dict[bid]);
Console.WriteLine(line);
}
else
{
continue;
}
}
client.Store(StoreMode.Set, id, line.Replace(idPropAndVal, ""));
}
}
};
process("breweries");
process("beers");
//using (StreamReader reader = new StreamReader(@"..\..\Data\SampleDocuments.json")) {
// string line;
// while ((line = reader.ReadLine()) != null) {
// var jsonLine = JsonSerializer.DeserializeFromString(line, typeof(JsonObject));
// var id = jsonLine.ToStringDictionary()["_id"];
// //_id is reserved and can't be in JSON document
// var idPropAndVal = "\"_id\" : \"" + id + "\", ";
// client.Remove(id);
// //client.Store(StoreMode.Set, id, line.Replace(idPropAndVal, ""));
// }
//}
}
示例10: When_Using_Code_Config_And_Http_Client_Factory_Is_Not_Set_Operations_Succeed
public void When_Using_Code_Config_And_Http_Client_Factory_Is_Not_Set_Operations_Succeed()
{
var config = new CouchbaseClientConfiguration();
config.Urls.Add(new Uri("http://10.0.0.79:8091/pools"));
Assert.That(config.HttpClientFactory, Is.InstanceOf<HammockHttpClientFactory>());
Assert.That(config, Is.Not.Null, "min-config section missing from app.config");
Assert.That(config.HttpClientFactory, Is.InstanceOf<HammockHttpClientFactory>());
var client = new CouchbaseClient(config);
var kv = KeyValueUtils.GenerateKeyAndValue("default_config");
var result = client.Store(StoreMode.Add, kv.Item1, kv.Item2);
Assert.That(result, Is.True, "Store failed");
var value = client.Get(kv.Item1);
Assert.That(value, Is.StringMatching(kv.Item2));
}
示例11: TestRemoveNode
public void TestRemoveNode(string bucketType)
{
ClearCluster();
Assert.True(CreateBucket(_servers[0].Ip, _servers[0].Port, _membaseUserName, _membasePassword, "default", 256, bucketType), "Could not ctreate bucket");
Thread.Sleep(10000);
var config = new CouchbaseClientConfiguration
{
SocketPool = { ReceiveTimeout = new TimeSpan(0, 0, 2), DeadTimeout = new TimeSpan(0, 0, 10) }
};
string node1 = _servers[1].Ip + ":" + _servers[1].Port;
string node2 = _servers[2].Ip + ":" + _servers[2].Port;
Assert.True(AddNode(_servers[0].Ip, _servers[0].Port, _membaseUserName, _membasePassword, node1), "Could not add node");
Assert.True(StartRebalance(_servers[0].Ip, _servers[0].Port, _membaseUserName, _membasePassword), "Could not start rebalancing");
while (CheckStillRebalancing(_servers[0].Ip, _servers[0].Port, _membaseUserName, _membasePassword))
{
Thread.Sleep(1000);
}
config.Urls.Add(new Uri("http://" + _servers[0].Ip + ":" + _servers[0].Port + "/pools/default"));
var couchbase = new CouchbaseClient(config);
for (int i = 0; i < ItemsToLoad; i++)
{
couchbase.Store(StoreMode.Set, "TEST_KEY" + i, "Hello World" + i);
}
for (int i = 0; i < ItemsToLoad; i++)
{
Assert.AreEqual("Hello World" + i, couchbase.Get("TEST_KEY" + i), "Missing data");
}
Assert.True(RemoveNode(_servers[0].Ip, _servers[0].Port, _membaseUserName, _membasePassword, node2), "Could not remove node");
Assert.True(StartRebalance(_servers[0].Ip, _servers[0].Port, _membaseUserName, _membasePassword), "Could not start rebalancing");
for (int i = 0; i < ItemsToLoad; i++)
{
Assert.AreEqual("Hello World" + i, couchbase.Get("TEST_KEY" + i), "Missing data");
}
var rand = new Random();
while (CheckStillRebalancing(_servers[0].Ip, _servers[0].Port, _membaseUserName, _membasePassword))
{
for (int i = 0; i < ItemsToLoad; i++)
{
int value = rand.Next(1000);
couchbase.Store(StoreMode.Set, "RAND_KEY", value);
Assert.AreEqual(value, couchbase.Get("RAND_KEY"), "Missing data");
}
}
for (int i = 0; i < ItemsToLoad; i++)
{
Assert.AreEqual("Hello World" + i, couchbase.Get("TEST_KEY" + i));
}
}
示例12: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
string id = "";
Resume theresume=new Resume();
var Couchbase = new CouchbaseClient();
if (Request.QueryString["id"] as string != null)
{
id = Request.QueryString["id"];
}
if(Page.RouteData.Values["id"] as string != null){
id = Page.RouteData.Values["id"] as string;
}
if(id!= ""){
theresume = Resume.ParseJSON(Couchbase.Get<String>(id));
initalobject.InnerHtml = String.Format("<script>var resume = {0};</script>", theresume.toJSON());
if(theresume.EditPassword == null ||theresume.EditPassword == EditPassword.Value){
//Check for password
}else{
;//Prompt for password.
}
}
if(Request.HttpMethod =="POST" && json.Value.Length>0 && (theresume.EditPassword == null || theresume.EditPassword == EditPassword.Value)){
bool okay =false;
string reason ="";
Resume newResume = Resume.ParseJSON(json.Value);
if(newResume.Id == null || newResume.Id ==""){
newResume.Id= Guid.NewGuid().ToString();
okay = Couchbase.Store(Enyim.Caching.Memcached.StoreMode.Add, newResume.Id, newResume.toJSON(false));
if(!okay){
reason = " Could not save resume, likley due to a server failure, ";
}
}
else{
if (theresume.EditPassword == newResume.EditPassword){
okay = Couchbase.Store(Enyim.Caching.Memcached.StoreMode.Replace, newResume.Id, newResume.toJSON(false));
if (!okay)
{
reason = " Could not save resume, likley due to a server failure, ";
}
}
else{
reason = "Incorrect Edit Password";
}
}
Response.Clear();
Response.ContentType = @"application\json";
if(okay){
Response.Write(String.Format("{{\"Response\":\"okay\",\"id\":\"{0}\"}}", newResume.Id));
}
else{
Response.Write(String.Format("{{\"Response\":\"error\",\"id\":\"{0}\",\"reason\":\"{1}\"}}", newResume.Id, reason));
}
}
//TODO Populate forms fields
}
示例13: Test_Store_StoreMode_Add_Will_Fail_If_Key_Exists
public void Test_Store_StoreMode_Add_Will_Fail_If_Key_Exists()
{
var client = new CouchbaseClient("memcached-config");
var result = client.Store(StoreMode.Set, Key, "value");
var resultWhenKeyExists = client.Store(StoreMode.Add, Key, "value");
Assert.AreEqual(resultWhenKeyExists, false);
client.Remove(Key);
}