博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
booksleeve 使用
阅读量:5880 次
发布时间:2019-06-19

本文共 2834 字,大约阅读时间需要 9 分钟。

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 

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/

分类: 
本文转自快乐就好博客园博客,原文链接:http://www.cnblogs.com/happyday56/p/3445400.html,如需转载请自行联系原作者
你可能感兴趣的文章
麦子学院与阿里云战略合作 在线教育领军者技术实力被认可
查看>>
正确看待大数据
查看>>
Facebook通过10亿单词构建有效的神经网络语言模型
查看>>
2016股市投资风向标 大数据说了算
查看>>
发展大数据不能抛弃“小数据”
查看>>
25000个布满恶意软件的摄像头组成的僵尸网络
查看>>
FB全球开放360度直播功能 首先需要一个FB账号
查看>>
量子通信成信息安全领域发展重点 潜在市场望达1000亿元
查看>>
数据中心新的自动化运维技术
查看>>
OpenFlow下一步该怎么走?
查看>>
CoreOS为容器安全带来不同方法
查看>>
用EXCEL导入QC需求和测试用例详解
查看>>
中了WannaCry病毒的电脑几乎都是Win 7
查看>>
iOS开发月报#2|201808
查看>>
SMSSDK进化之路
查看>>
【干货来袭】使用 Python 扩展 UiBot 的功能
查看>>
node之搭建一个http完整的静态服务器(命令行工具)
查看>>
阿里云IPv6 DDoS防御被工信部认定为“网络安全技术应用试点示范项目
查看>>
史上最快Docker入门实战! (二) - Docker环境的搭建方法
查看>>
【思维导图】PHP基础
查看>>