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 ...
随机推荐
- Effective STL 阅读笔记: Item 3: Make copying cheap and correct for objects in containers
容器 (Containers) 用来存储对象 (Objects), 但是被存储的对象却并非原原本本是你给他的那一个, 而是你指定对象的一个拷贝.而后续对该容器内存储对象的操作,大多也是基于拷贝的. 拷 ...
- Graves of the Internet - 互联网坟墓
Graves of the Internet - 互联网坟墓 互联网公司逝去产品列表 以此祭奠那些夕阳下的奔跑,祭奠那些逝去的青春 演示地址 点击 这里 https://myvin.github.io ...
- js_数组对象的浅克隆
如果再考虑更奇葩更复杂的情况,例如我们定义: var obj = [{ "a": { "a1": ["a11", "a12&q ...
- js获取url链接地址的参数
访问地址为:http://XXX.com?style=green <script language="javascript"> var getArgs = functi ...
- Python全栈开发之11、进程和线程
一.线程 多任务可以由多进程完成,也可以由一个进程内的多线程完成,一个进程内的所有线程,共享同一块内存python中创建线程比较简单,导入threading模块,下面来看一下代码中如何创建多线程. d ...
- 简单的oracle sql语句练习
简单的oracle sql语句练习 求每个部门的平均薪水 select deptno,avg(sal) from emp group by deptno 每个部门同一个职位的最大工资 select d ...
- C# 字符串提取数字
转自:http://www.cnblogs.com/dolphin-gjh/p/6121792.html 一.使用正则表达式 1 string str = "sztq数字提取123sztq数 ...
- linux关闭地址空间随机化(ASLR)
转:http://www.xuebuyuan.com/1571079.html 确认ASLR是否已经被打开,"2"表示已经打开 shanks@shanks-ubuntu:/home ...
- vue-router在IE11中页面不跳转
情景: IE11浏览器中,在进行正常页面跳转操作后(页面A跳转到页面B),点击浏览器的左上角的‘后退’按钮,点击后,可以看到url地址已经发生了变化(url由页面B变为页面A),hash值也已经是上一 ...
- Codeforces Round 548 (Div. 2)
layout: post title: Codeforces Round 548 (Div. 2) author: "luowentaoaa" catalog: true tags ...