本文整理汇总了C#中RiakObject类的典型用法代码示例。如果您正苦于以下问题:C# RiakObject类的具体用法?C# RiakObject怎么用?C# RiakObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RiakObject类属于命名空间,在下文中一共展示了RiakObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Save
public async Task Save(String endpoint, long position)
{
var id = new RiakObjectId($"{Settings.Bucket}.system", endpoint);
var options = new RiakGetOptions { };
options.SetRw(Quorum.WellKnown.All);
var exists = await _riak.Async.Get(id, options);
if (exists.IsSuccess)
{
var checkpoint = exists.Value.GetObject<Checkpoint>();
checkpoint.Position = position;
exists.Value.SetObject(checkpoint);
var putOpt = new RiakPutOptions { IfNotModified = true, IfNoneMatch = false };
putOpt.SetW(Quorum.WellKnown.All);
await _riak.Async.Put(exists.Value, putOpt);
}
else
{
var checkpoint = new Checkpoint
{
Id = endpoint,
Position = position,
};
var putOpt = new RiakPutOptions { IfNotModified = false, IfNoneMatch = true };
putOpt.SetW(Quorum.WellKnown.All);
var o = new RiakObject(id, checkpoint);
await _riak.Async.Put(o, putOpt);
}
}
示例2: CustomSerializerWillSerializeJson
public void CustomSerializerWillSerializeJson()
{
var testPerson = new Person
{
DateOfBirth = new DateTime(1978, 12, 5, 0, 0, 0, DateTimeKind.Utc),
Email = "[email protected]",
Name = new Name
{
FirstName = "OJ",
Surname = "Reeves"
},
PhoneNumbers = new List<PhoneNumber>
{
new PhoneNumber
{
Number = "12345678",
NumberType = PhoneNumberType.Home
}
}
};
var sots = new SerializeObjectToString<Person>(JsonConvert.SerializeObject);
var obj = new RiakObject("bucket", "key");
obj.SetObject(testPerson, RiakConstants.ContentTypes.ApplicationJson, sots);
obj.Value.ShouldNotBeNull();
obj.ContentType.ShouldEqual(RiakConstants.ContentTypes.ApplicationJson);
var json = obj.Value.FromRiakString();
json.ShouldEqual("{\"Name\":{\"FirstName\":\"OJ\",\"Surname\":\"Reeves\"},\"PhoneNumbers\":[{\"Number\":\"12345678\",\"NumberType\":1}],\"DateOfBirth\":\"\\/Date(281664000000)\\/\",\"Email\":\"[email protected]\"}");
var deserialisedPerson = obj.GetObject<Person>();
deserialisedPerson.ShouldEqual(testPerson);
}
示例3: RangeQuery
public void RangeQuery()
{
var Cluster = RiakCluster.FromConfig("riakConfig");
var Client = Cluster.CreateClient();
var bucket = "rsds";
Client.Batch(batch =>
{
for (var i = 1; i < 11; i++)
{
var d = DateTime.Now.AddDays(0 - i);
var doc = new RiakObject(bucket, i.ToString(), new { value = i, created_date = d });
var position = 100 + i;
doc.BinIndex("position").Set(position.ToString());
batch.Put(doc);
}
});
var query = new RiakMapReduceQuery()
.Inputs(RiakIndex.Range("bucket", "position", 100, 200))
.MapJs(m => m.Name("Riak.mapValuesJson").Keep(true));
var result = Client.MapReduce(query);
//var items = result.Value.PhaseResults.SelectMany(x => x.GetObjects<dynamic>);
}
示例4: InvalidFieldNamesAndTypes
public void InvalidFieldNamesAndTypes()
{
id = new RiakObjectId("indexes", "mykey", "test value");
var obj = new RiakObject("indexes", "mykey", "test value");
var intIdx = obj.IntIndex("test-int-idx");
Assert.Throws<FormatException>(() => intIdx.Add("invalid-value"));
}
示例5: ObjectsAreConvertedProperly
public void ObjectsAreConvertedProperly()
{
var testPerson = new Person
{
DateOfBirth = new DateTime(1978, 12, 5, 0, 0, 0, DateTimeKind.Utc),
Email = "[email protected]",
Name = new Name
{
FirstName = "OJ",
Surname = "Reeves"
},
PhoneNumbers = new List<PhoneNumber>
{
new PhoneNumber
{
Number = "12345678",
NumberType = PhoneNumberType.Home
}
}
};
var obj = new RiakObject("bucket", "key");
obj.SetObject(testPerson);
obj.Value.ShouldNotBeNull();
obj.ContentType.ShouldEqual(RiakConstants.ContentTypes.ApplicationJson);
var json = obj.Value.FromRiakString();
json.ShouldEqual("{\"Name\":{\"FirstName\":\"OJ\",\"Surname\":\"Reeves\"},\"PhoneNumbers\":[{\"Number\":\"12345678\",\"NumberType\":1}],\"DateOfBirth\":\"1978-12-05T00:00:00Z\",\"Email\":\"[email protected]\"}");
var deserialisedPerson = obj.GetObject<Person>();
deserialisedPerson.ShouldEqual(testPerson);
}
示例6: AsyncDeleteIsSuccessful
public void AsyncDeleteIsSuccessful()
{
var riakObject = new RiakObject(TestBucket, TestKey, TestJson, RiakConstants.ContentTypes.ApplicationJson);
var riakObjectId = riakObject.ToRiakObjectId();
var putResult = Client.Put(riakObject);
putResult.IsSuccess.ShouldBeTrue();
RiakResult theResult = null;
var resetEvent = new AutoResetEvent(false);
Client.Async.Delete(riakObjectId, result =>
{
theResult = result;
resetEvent.Set();
});
resetEvent.WaitOne();
theResult.IsSuccess.ShouldBeTrue();
var getResult = Client.Get(riakObjectId);
getResult.IsSuccess.ShouldBeFalse();
getResult.ResultCode.ShouldEqual(ResultCode.NotFound);
getResult.Value.ShouldBeNull();
}
示例7: AsyncDeleteMultipleIsSuccessful
public void AsyncDeleteMultipleIsSuccessful()
{
var one = new RiakObject(TestBucket, "one", TestJson, RiakConstants.ContentTypes.ApplicationJson);
var two = new RiakObject(TestBucket, "two", TestJson, RiakConstants.ContentTypes.ApplicationJson);
Client.Put(one);
Client.Put(two);
var oneObjectId = one.ToRiakObjectId();
var twoObjectId = two.ToRiakObjectId();
var list = new List<RiakObjectId> { oneObjectId, twoObjectId };
var results = Client.Async.Delete(list).Result;
foreach (var riakResult in results)
{
riakResult.IsSuccess.ShouldBeTrue(riakResult.ErrorMessage);
}
var oneResult = Client.Get(oneObjectId);
oneResult.IsSuccess.ShouldBeFalse();
oneResult.ResultCode.ShouldEqual(ResultCode.NotFound);
oneResult.Value.ShouldBeNull();
var twoResult = Client.Get(twoObjectId);
twoResult.IsSuccess.ShouldBeFalse();
twoResult.ResultCode.ShouldEqual(ResultCode.NotFound);
twoResult.Value.ShouldBeNull();
}
示例8: AllKeysReturnsListOfKeys
public void AllKeysReturnsListOfKeys()
{
var bucket = Bucket + "_" + Guid.NewGuid().ToString();
var originalKeys = new List<string>();
for (var i = 0; i < 10; i++)
{
var o = new RiakObject(bucket, Guid.NewGuid().ToString(), "{ value: \"this is an object\" }");
originalKeys.Add(o.Key);
Client.Put(o);
}
var mr = new RiakMapReduceQuery()
.Inputs(RiakIndex.AllKeys(bucket));
var result = Client.MapReduce(mr);
var keys = result.Value.PhaseResults.SelectMany(x => x.GetObjectIds()).ToList();
result.IsSuccess.ShouldBeTrue(result.ErrorMessage);
keys.Count.ShouldEqual(10);
foreach (var key in keys)
{
key.Bucket.ShouldNotBeNullOrEmpty();
key.Key.ShouldNotBeNullOrEmpty();
originalKeys.Contains(key.Key).ShouldBeTrue();
}
}
示例9: CreatingBucketInSpecificBucketType
public void CreatingBucketInSpecificBucketType()
{
id = new RiakObjectId("no_siblings", "sensitive_user_data", "user19735");
var obj = new RiakObject(id, "{\"name\":\"Bob\"}");
var rslt = client.Put(obj);
CheckResult(rslt);
}
示例10: CreateLinkedObjects
protected void CreateLinkedObjects(string bucketName)
{
var oj = new RiakObject(bucketName, OJ, new Person() { Name = "oj" });
var jeremiah = new RiakObject(bucketName, Jeremiah, new Person() { Name = "jeremiah" });
var brent = new RiakObject(bucketName, Brent, new Person() { Name = "brent" });
var rob = new RiakObject(bucketName, Rob, new Person() { Name = "rob" });
oj.ContentType = RiakConstants.ContentTypes.ApplicationJson;
jeremiah.ContentType = RiakConstants.ContentTypes.ApplicationJson;
brent.ContentType = RiakConstants.ContentTypes.ApplicationJson;
rob.ContentType = RiakConstants.ContentTypes.ApplicationJson;
#pragma warning disable 618
oj.LinkTo(jeremiah, "friends");
oj.LinkTo(jeremiah, "coworkers");
jeremiah.LinkTo(oj, "friends");
jeremiah.LinkTo(oj, "coworkers");
jeremiah.LinkTo(oj, "ozzies");
jeremiah.LinkTo(brent, "friends");
jeremiah.LinkTo(brent, "coworkers");
jeremiah.LinkTo(rob, "ozzies");
brent.LinkTo(jeremiah, "coworkers");
brent.LinkTo(jeremiah, "friends");
#pragma warning restore 618
Client.Put(new[] { oj, jeremiah, brent, rob });
}
示例11: StoreData
private static void StoreData()
{
Console.WriteLine("[ChaosMonkeyApp] store thread starting");
IRiakClient client = cluster.CreateClient();
try
{
while (true)
{
var id = new RiakObjectId("chaos-monkey", key.ToString());
var obj = new RiakObject(id, Guid.NewGuid().ToString());
obj.ContentEncoding = RiakConstants.CharSets.Utf8;
obj.ContentType = RiakConstants.ContentTypes.TextPlain;
var rslt = client.Put(obj);
if (rslt.IsSuccess)
{
Console.WriteLine("[ChaosMonkeyApp] stored key: {0}", key);
}
else
{
Console.WriteLine("[ChaosMonkeyApp] error storing key {0}, {1}", key, rslt.ErrorMessage);
}
++key;
Thread.Sleep(storeDataInterval);
ct.ThrowIfCancellationRequested();
}
}
finally
{
Console.WriteLine("[ChaosMonkeyApp] store thread stopping");
}
}
示例12: TestKVOperations
public void TestKVOperations()
{
const string key = "bucket_type_test_key";
var id = new RiakObjectId(TestBucketType, TestBucket, key);
var obj = new RiakObject(id, Value);
// put
var putResult = Client.Put(obj, new RiakPutOptions().SetReturnBody(true).SetDw(3));
putResult.IsSuccess.ShouldBeTrue();
putResult.Value.BucketType.ShouldEqual(TestBucketType);
// get
var getResult = Client.Get(id);
getResult.IsSuccess.ShouldBeTrue();
getResult.Value.BucketType.ShouldEqual(TestBucketType);
// delete
var deleteResult = Client.Delete(id, new RiakDeleteOptions().SetDw(3));
deleteResult.IsSuccess.ShouldBeTrue();
// multiget
var ids = new List<RiakObjectId>();
for (int i = 0; i < 3; i++)
{
obj = new RiakObject(new RiakObjectId(TestBucketType, TestBucket, key + i), Value);
Client.Put(obj, new RiakPutOptions().SetReturnBody(true).SetDw(3));
ids.Add(obj.ToRiakObjectId());
}
var multiGetResult = Client.Get(ids).ToList();
multiGetResult.All(r => r.IsSuccess).ShouldBeTrue();
multiGetResult.All(r => r.Value.BucketType == TestBucketType).ShouldBeTrue();
}
示例13: SettingLegacySearchOnRiakBucketMakesBucketSearchable
public void SettingLegacySearchOnRiakBucketMakesBucketSearchable()
{
var bucket = Guid.NewGuid().ToString();
var key = Guid.NewGuid().ToString();
var props = Client.GetBucketProperties(bucket).Value;
props.SetLegacySearch(true);
var setResult = Client.SetBucketProperties(bucket, props);
setResult.IsSuccess.ShouldBeTrue(setResult.ErrorMessage);
var obj = new RiakObject(bucket, key, new { name = "OJ", age = 34 });
var putResult = Client.Put(obj);
putResult.IsSuccess.ShouldBeTrue(putResult.ErrorMessage);
var q = new RiakFluentSearch(bucket, "name")
.Search("OJ")
.And("age", "34")
.Build();
var search = new RiakSearchRequest
{
Query = q
};
var searchResult = Client.Search(search);
searchResult.IsSuccess.ShouldBeTrue(searchResult.ErrorMessage);
searchResult.Value.NumFound.ShouldEqual(1u);
searchResult.Value.Documents[0].Fields.Count.ShouldEqual(3);
searchResult.Value.Documents[0].Fields.First(x => x.Key == "id").Value.ShouldEqual(key);
}
示例14: ToRiakObjectIdProducesAValidRiakObjectId
public void ToRiakObjectIdProducesAValidRiakObjectId()
{
var riakObject = new RiakObject(Bucket, Key, "value");
var riakObjectId = riakObject.ToRiakObjectId();
riakObjectId.Bucket.ShouldEqual(Bucket);
riakObjectId.Key.ShouldEqual(Key);
}
示例15: CreatingBucketInSpecificBucketTypeExampleTwo
public void CreatingBucketInSpecificBucketTypeExampleTwo()
{
id = new RiakObjectId("no_siblings", "old_memes", "all_your_base");
var obj = new RiakObject(id, "all your base are belong to us",
RiakConstants.ContentTypes.TextPlain);
var rslt = client.Put(obj);
CheckResult(rslt);
}