booksleeve 使用
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 使用的更多相关文章
- Redis 详解 (一) StackExchange.Redis Client
这期我们来看StackExchange.Redis,这是redis 的.net客户端之一.Redis是一个开源的内存数据存储,可以用来做数据库,缓存或者消息代理服务.目前有不少人在使用ServiceS ...
- Redis基础(转)
ServiceStack.Redis实践 Redis的C#客户端我选择的是ServiceStack.Redis,相比Booksleeve redis-sharp等方案,它提供了一整套从 Redi ...
- 高性能网站架构设计之缓存篇(2)- Redis C#客户端
在上一篇中我简单的介绍了如何利用redis自带的客户端连接server并执行命令来操作它,但是如何在我们做的项目或产品中操作这个强大的内存数据库呢?首先我们来了解一下redis的原理吧. 官方文档上是 ...
- Stackoverflow架构
Stackoverflow用的是.net开发的,用的缓存是Redis,Stackoverflow架构的演讲地址是:http://www.infoq.com/cn/presentations/archi ...
- 分布式系统状态下redis存储asp.net session使用第三方Providers驱动
https://github.com/ServiceStack/ServiceStack.Redis (redis客户端组件) 注:redis服务端在windows不太稳定,一般部署在Linux下. ...
- Redis 实践笔记
本文来自:http://www.cnblogs.com/me-sa/archive/2012/03/13/redis-in-action.html 最近在项目中实践了一下Redis,过程中遇到并解决了 ...
- StackExchange.Redis Client
StackExchange.Redis Client 这期我们来看StackExchange.Redis,这是redis 的.net客户端之一.Redis是一个开源的内存数据存储,可以用来做数据库,缓 ...
- StackExchange.Redis 官方文档(二) Configuration
配置 有多种方式可以配置redis,StackExchange.Redis提供了一个丰富的配置模型,在执行Connect (or ConnectAsync) 时被调用: var conn = Conn ...
- redis安装使用配置
一.安装前的准备 下载redis http://redis.io/download https://github.com/mythz/redis-windows 下载Windows版客户端net版sd ...
随机推荐
- LeetCode312. Burst Balloons
Given n balloons, indexed from 0 to n-1. Each balloon is painted with a number on it represented by ...
- javaWeb之写一个最简单的servlet
1. 创建一个类servletTest2 继承HttpServlet类. public class servletTest2 extends HttpServlet { public servletT ...
- php极速后台开发框架LotusAdmin
组件:基于thinkphp5.0.12+layui2.1版本 演示站点:https://www.lotusadmin.top/账号 : admin密码:123456 官方QQ交流群:606645328 ...
- Linux文件系统的详解
这里以 EXT2 文件系统为例 在Linux下,一个磁盘的最前面是MBR,大小为512Byte 在每一个分区下,第一部分是boot sector,接下来是super block,再接下来是inode, ...
- 《构建高性能 Web站点》笔记
书名:构建高性能Web站点 出版社: 电子工业出版社 ISBN:9787121170935 一 绪论 等待的时间: (1) 数据在网络上的传输时间 (2) 站点服务器处理请求并生成回应数据的时间 ( ...
- Git & GitHub 学习
学习资料: Git版本控制软件结合GitHub从入门到精通常用命令学习手册:http://www.ihref.com/read-16369.html 官方中文手册:http://git-scm.com ...
- 编译PHP并与Ngnix整合
nginx本身不能处理PHP,它只是个web服务器,当接收到请求后,如果是php请求,则发给php解释器处理,并把结果返回给客户端. nginx一般是把请求发fastcgi管理进程处理,fascgi管 ...
- Java throw throws try...catch区别
java里的异常多种多样,这是一种非常有用的机制,它能帮助我们处理那些我们未知的错误,在java里,关于异常的有throw throws,还有一个try catch 程序块.接下来我们挨个看看这几个的 ...
- Android之 内容提供器(2)——创建自己的内容提供器将数据共享出去
创建自己的内容提供器非常简单,只需要新建一个类继承ContentProvider类,通过实现ContentProvider的增删改查的方法向内容提供器中增删数据. 1 ContentProvider简 ...
- C51中的xdata
今天在写公司芯片对应的.H文件时,在定义寄存器的时候出现一个问题. 我们芯片的寄存器地址是定义在片外RAM区的,不能使用sfr这样的关键字来进行定义. 后来查阅了对应的资料才发现定义寄存器有很多种方法 ...