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 ...
随机推荐
- prototype 与 __proto__
原文:http://rockyuse.iteye.com/blog/1426510 说到prototype,就不得不先说下new的过程. 我们先看看这样一段代码: 1 <script type= ...
- 完全禁用Wordpress的升级功能
wordpress自己带有一个自动升级的功能,也就是说,如果wp检测到官方已经有新的升级可用的话他就会自己升级上去.这可能对于某些场合是个不错的功能,但是对于一些已经对系统大量魔改或者对插件稳定性不抱 ...
- 微信小程序-textarea中的文本读取以及换行问题
今天客户那边要求textarea中输入的问题可以按回车键换行,而我使用的是bindinput获取值,但是呢bindinput 处理函数的返回值并不会反映到 textarea 上,按回车键导致点击换行符 ...
- day1 作业编写登录窗口
作业一:编写登录接口 (1)输入用户名和密码: (2)认证成功后显示欢迎信息: (3)输错三次后锁定. 思路:我们知道,要想让程序记住之前输入多少次,锁定用户,那么可以使用数据库来保存用户的状态,然而 ...
- linux 大法
实验楼 练习 小笔记 可以输出图形字符的命令banner 你可以先使用如下命令安装: $ sudo apt-get update $ sudo apt-get install sysvbanner 然 ...
- SPOJ GSS3-Can you answer these queries III-分治+线段树区间合并
Can you answer these queries III SPOJ - GSS3 这道题和洛谷的小白逛公园一样的题目. 传送门: 洛谷 P4513 小白逛公园-区间最大子段和-分治+线段树区间 ...
- codeforces-727A
题目连接:http://codeforces.com/contest/727/problem/A A. Transformation: from A to B time limit per test ...
- redis环境搭建和java应用
安装 连接 Java连接redis 下载 wget http://download.redis.io/releases/redis-4.0.9.tar.gz 解压移动 tar -xvf redis-4 ...
- Hibernate 过滤查询(hibernate过滤器的使用)
我们在开发过程中过滤查询使用的还是挺多的,今天来学习一下hibernate的过滤器的使用,首先学习在配置文件中如何使用,然后再介绍如何使用注解配置. 1.使用配置文件配置过滤器 1)首先我们使用my ...
- 【BZOJ 2916】 2916: [Poi1997]Monochromatic Triangles (容斥)
2916: [Poi1997]Monochromatic Triangles Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 310 Solved: 1 ...