惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
云风的 BLOG
云风的 BLOG
aimingoo的专栏
aimingoo的专栏
Vercel News
Vercel News
T
The Blog of Author Tim Ferriss
F
Full Disclosure
A
About on SuperTechFans
C
Check Point Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
量子位
Know Your Adversary
Know Your Adversary
K
Kaspersky official blog
L
LINUX DO - 热门话题
Recorded Future
Recorded Future
C
Cisco Blogs
M
MIT News - Artificial intelligence
T
Tenable Blog
G
GRAHAM CLULEY
月光博客
月光博客
Recent Announcements
Recent Announcements
V
Visual Studio Blog
IT之家
IT之家
T
The Exploit Database - CXSecurity.com
The GitHub Blog
The GitHub Blog
T
Threat Research - Cisco Blogs
D
DataBreaches.Net
P
Privacy International News Feed
P
Proofpoint News Feed
I
Intezer
博客园 - 叶小钗
C
CXSECURITY Database RSS Feed - CXSecurity.com
The Hacker News
The Hacker News
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - Franky
SecWiki News
SecWiki News
宝玉的分享
宝玉的分享
P
Palo Alto Networks Blog
Last Week in AI
Last Week in AI
小众软件
小众软件
Hacker News - Newest:
Hacker News - Newest: "LLM"
O
OpenAI News
N
News and Events Feed by Topic
Microsoft Security Blog
Microsoft Security Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
N
News and Events Feed by Topic
The Cloudflare Blog
Spread Privacy
Spread Privacy
酷 壳 – CoolShell
酷 壳 – CoolShell
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
B
Blog RSS Feed

博客园 - xhan

提交给mysql java驱动的优化下个版本要发布了^_^ java 可伸缩阻塞队列实现 java mysql大数据量批量插入与流式读取分析 innodb next-key lock引发的死锁 jremoting的功能扩展点 java开源项目jremoting largest remainder method java impl 数据库单元测试 元数据编程实战_使用Emit运行时生成Protobuf编码类 redis入门系列文章广告贴 九 redis学习笔记之虚拟内存 八 redis学习笔记之主从复制 七 redis学习笔记之持久化 六 redis学习笔记之发布订阅 五 redis学习笔记之pipeline 四 redis学习笔记之事务 三 redis学习笔记之排序 二 redis学习笔记之数据类型 - xhan - 博客园 一 redis学习笔记之环境搭建
发布个c#版的HandlerSocket客户端类库
xhan · 2011-03-24 · via 博客园 - xhan

HandlerSocket 是一个mysql 数据库的插件,它可以绕过mysql的查询分析和优化的过程,直接与innodb存储引擎进行交互。尤其是当大多数数据都被innodb缓存到内存中的时候,

查询分析和优化过程就会是整个查询处理过程的瓶颈。通过使用HandlerSocket可以绕过这个瓶颈,从而提升性能。这要比mysql+memched要有优势,因为HandlerSocket不需要处理缓存失效的问题。下面看下HsClient访问mysql的一个例子代码

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using HsClient;
 6 
 7 namespace HsClientTest
 8 {
 9     class Program
10     {
11         private static HsIndexSessionFactory client = new HsIndexSessionFactory("192.168.200.9"9999);
12         static void Main(string[] args)
13         {
14             HsIndexSession session = null;
15             try
16             {
17                 session = client.OpenIndex(0"test""FUser""PRIMARY",
18                     new string[] { "UserId""Nickname""Email" });
19 
20                 HsResultSet rs = session.Find(HsOperator.GreatEqual, new string[] { "0" }, 200);
21 
22                 while (rs.Next())
23                 {
24                     Console.WriteLine("id:{0},nickname:{1},email:{2}", rs.GetInt(0), rs.GetString(1), rs.GetString(2));
25                 }
26 
27                 int count = session.Update(HsOperator.Equal, new string[] { "6" }, 10new string[] { "6""c#""x@x.net" });
28                 Console.WriteLine("update count {0}", count);
29 
30 
31                 count = session.Delete(HsOperator.Equal, new string[] { "6" }, 10);
32                 Console.WriteLine("delete count {0}", count);
33 
34 
35                 bool insertResult = session.Insert(new string[] { "6""haha""you@aa.ss" });
36                 Console.WriteLine("insert success {0}", insertResult);
37             }
38             finally
39             {
40                 if (session != null)
41                 {
42                     session.Close();
43                 }
44             }
45 
46 
47             //close all socket in the end
48             client.Shutdown();
49             Console.ReadKey();
50         }
51     }
52 }

 要访问mysql必须首先打开一个IndexSession.指明我们要访问的索引名称和要访问的字段。很容易理解,因为没有了mysql原来的查询分析和优化。所以访问表数据使用那个索引

就必须我们自己来选择。 注意通过IndexSession发起的CRUD操作的字段数量很顺序必须和打开IndexSession时提供的字段是一样的。使用完IndexSession要记得关闭,关闭会吧IndexSession使用的Socket连接,交还给连接池。最后Shutdown操作会关闭连接池中所有连接.

下载/Files/xhan/HsClient.rar 源代码也就500行左右,学习网络编程的同学可以看看。

代码还没经过生产环境测试,慎重使用,仅供学习交流