By offering pipelined, asynchronous, multiplexed and thread-safe access to redis, BookSleeve enables efficient redis access even for the busiest applications.

How can I get started?

The easiest way is via nuget; in VS2010, add a "Library Package Reference"; make sure you are looking at the Online gallery and enter "booksleeve". Then just click "Install" and you should get everything you need:

Why does it exist?

For full details, see http://marcgravell.blogspot.com/2011/04/async-redis-await-booksleeve.html

Note the API may change a little going to 1.0, but is stable enough to drive Stack Exchange...

How do I use it?

The entire API is async; if you don't need the result, just queue it up:

using(var conn =newRedisConnection("localhost"))
{
    conn.Open();
    conn.Set(12,"foo","bar");
    ...

You can query the result of an operation as a future, by:

var value = conn.GetString(12,"foo");
// do something else, perhaps some TSQL, while
// that flies over the network and back
string s = conn.Wait(value);

Note that the value variable here is a Task<string>; we could also use the Task API to wait (or add a continuation), but the conn.Wait(value) approach simplifies timeout-handling (waiting forever is very rarely a good idea), aggregate-exception handling, and obtaining the result value. Wait acts as a blocking call.

Alternatively, if you are using the Async CTP, continuations are a breeze:

var value = conn.GetString(12,"foo");
...
string s = await value;

A connection is thread-safe and (with the exception of Wait) non-blocking, so you can share the connection between as many callers as you need - this allows a web-site to make very effective use of just a single redis connection. Additionally, database-switching (the 12 in the examples above) is handled at the message level, so you don't need to issue separate SELECT commands - this allows multi-tenancy usage over a set of databases without having to synchronize operations.

But what if something goes badly wrong? How do I see the exceptions?

If you capture the result and use it in a Wait or a continuation, then you'll get the exception then. Otherwise the Task API exposes the exception on the TaskScheduler.UnobservedTaskException event; even if the data is "nice to have", you should handle this event, do something useful (like log it to your failure logs), and mark the exception as observed. If you don't do this unobserved exceptions will kill your process. Which sucks, but:

TaskScheduler.UnobservedTaskException+=(sender, args)=>
{
    Trace.WriteLine(args.Exception,"UnobservedTaskException");
    args.SetObserved();
};

(I should note that this is nothing to do with BookSleeve; this is a feature of the Task API; if you are doing async work you should be familiar with this already)

参考网站:http://code.google.com/p/booksleeve/

booksleeve 使用的更多相关文章

  1. Redis 详解 (一) StackExchange.Redis Client

    这期我们来看StackExchange.Redis,这是redis 的.net客户端之一.Redis是一个开源的内存数据存储,可以用来做数据库,缓存或者消息代理服务.目前有不少人在使用ServiceS ...

  2. Redis基础(转)

    ServiceStack.Redis实践    Redis的C#客户端我选择的是ServiceStack.Redis,相比Booksleeve redis-sharp等方案,它提供了一整套从 Redi ...

  3. 高性能网站架构设计之缓存篇(2)- Redis C#客户端

    在上一篇中我简单的介绍了如何利用redis自带的客户端连接server并执行命令来操作它,但是如何在我们做的项目或产品中操作这个强大的内存数据库呢?首先我们来了解一下redis的原理吧. 官方文档上是 ...

  4. Stackoverflow架构

    Stackoverflow用的是.net开发的,用的缓存是Redis,Stackoverflow架构的演讲地址是:http://www.infoq.com/cn/presentations/archi ...

  5. 分布式系统状态下redis存储asp.net session使用第三方Providers驱动

    https://github.com/ServiceStack/ServiceStack.Redis (redis客户端组件) 注:redis服务端在windows不太稳定,一般部署在Linux下. ...

  6. Redis 实践笔记

    本文来自:http://www.cnblogs.com/me-sa/archive/2012/03/13/redis-in-action.html 最近在项目中实践了一下Redis,过程中遇到并解决了 ...

  7. StackExchange.Redis Client

    StackExchange.Redis Client 这期我们来看StackExchange.Redis,这是redis 的.net客户端之一.Redis是一个开源的内存数据存储,可以用来做数据库,缓 ...

  8. StackExchange.Redis 官方文档(二) Configuration

    配置 有多种方式可以配置redis,StackExchange.Redis提供了一个丰富的配置模型,在执行Connect (or ConnectAsync) 时被调用: var conn = Conn ...

  9. redis安装使用配置

    一.安装前的准备 下载redis http://redis.io/download https://github.com/mythz/redis-windows 下载Windows版客户端net版sd ...

随机推荐

  1. unittest单元测试

    unittest单元测试框架不仅可以适用于单元测试,还可以适用WEB自动化测试用例的开发与执行,该测试框架可组织执行测试用例,并且提供了丰富的断言方法,判断测试用例是否通过,最终生成测试结果.今天笔者 ...

  2. 【UOJ】#79. 一般图最大匹配

    题解 板子!我相信其实没人来看我的板子!但是为了防止我忘记,我还是要写点什么 我们考虑二分图,为什么二分图就能那么轻松地写出匹配的代码呢?因为匹配只会发生在黑点和白点之间,我们找寻增广路,必然是一黑一 ...

  3. 了解PHP中Stream(流)的概念与用法

    Stream是PHP开发里最容易被忽视的函数系列(SPL系列,Stream系列,pack函数,封装协议)之一,但其是个很有用也很重要的函数.Stream可以翻译为“流”,在Java里,流是一个很重要的 ...

  4. (13) go map

    1.定义 map 无序, key唯一 (1) (2) (3)定义+赋值 2. map的值时map, 记得要make 3.增删改查 (1)增 改 (2)删除 (3)查 4.遍历 值map 嵌套for, ...

  5. Python数据类型-列表(list)增删改查

    1.添加元素 添加单个元素:使用append(object)函数可以为列表添加单个元素,参数object为对象:也就是说所有Python的对象都可以添加到列表中. 添加多个元素(合并列表):使用ext ...

  6. MAC OS 10.11.1虚拟机免费下载已安装Xcode7图片后有下载地址

    MAC OS 10.11.1虚拟机免费下载已安装Xcode7图片后有下载地址 注意:已经下载过MAC OS 10.10.5虚拟机免费下载(可安装Xcode7)链接:http://www.cnblogs ...

  7. 「UOJ218」火车管理

    「UOJ218」火车管理 解题思路:观察发现,在弹出 \(x\) 之前,它前面这个元素都是保持不变的,所以可以用一棵可持久化线段树维护每一个栈顶元素的插入时间,每次找到当前时间\(-1\) 的版本就可 ...

  8. BZOJ 4566 JZYZOJ 1547 [haoi2016T5]找相同子串 后缀数组 并查集

    http://172.20.6.3/Problem_Show.asp?id=1547 http://www.lydsy.com/JudgeOnline/problem.php?id=4566 单纯后缀 ...

  9. PHP多个版本爆出远程DOS漏洞

    近日,php多个版本爆出远程DoS漏洞(官方编号69364),利用该漏洞构造poc发起链接,很容易导致目标主机cpu的100%占用率,绿盟科技威胁响应中心随即启动应急机制, 启动应急响应工作,总结PH ...

  10. 注解@Aspect实现AOP功能

    springboot中pom引入jar <!-- aop 切面 --> <dependency> <groupId>org.springframework.boot ...