本文整理汇总了C#中ServiceCollection.AddRedis方法的典型用法代码示例。如果您正苦于以下问题:C# ServiceCollection.AddRedis方法的具体用法?C# ServiceCollection.AddRedis怎么用?C# ServiceCollection.AddRedis使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ServiceCollection
的用法示例。
在下文中一共展示了ServiceCollection.AddRedis方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetOrAdd
public virtual IServiceProvider GetOrAdd([NotNull] IRedisContextOptions options)
{
unchecked
{
var key = options.Extensions.Aggregate(0, (t, e) => (t * 397) ^ e.GetType().GetHashCode());
return _configurations.GetOrAdd(
key,
k =>
{
var services = new ServiceCollection();
var builder = services.AddRedis();
foreach (var extension in options.Extensions)
extension.ApplyServices(builder);
return services.BuildServiceProvider();
});
}
}
示例2: Main
public static void Main(string[] args)
{
DoTest().Wait();
//return;
var services = new ServiceCollection();
services.AddRedis()
.AddRedisContext<ForumContext>(options => options.UseConnection("localhost")
.UseDatabase(0));
var provider = services.BuildServiceProvider();
//pfx:Discussions:123:CountViews
//pfx:Discussions:123:CountComments
using (var context = provider.GetRequiredService<ForumContext>())
{
context.BeginTransaction()
.When(c => c.HashExists("", ""))
.Done(c =>
{
var currentID = c.Announcement.SetAsync("");
return new[] { currentID }.Select(t => t.Result);
})
.Execute(r =>
{
var aa = r;
});
context.BeginTransaction()
.When(c => c.HashExists("", ""))
.Done(c =>
{
c.Announcement.SetAsync("");
c.Announcement.SetAsync("");
})
.Execute();
}
//context.Discussions["123"].CountViews.Increment();
//var id = context.Discussions["123"].AuthorID.Get();
}