Memcached 是一個高效能的分布式記憶體對象緩衝系統,用於動態Web應用以減輕資料庫負載。它通過在記憶體中快取資料和對象來減少讀取資料庫的次數,從而提供動態、資料庫驅動網站的速度。Memcached基於一個儲存鍵/值對的hashmap。其守護進程(daemon )是用C寫的,但是用戶端可以用任何語言來編寫,並通過memcached協議與守護進程通訊。但是它並不提供冗餘(例如,複製其hashmap條目);當某個伺服器S停止運行或崩潰了,所有存放在S上的鍵/值對都將丟失。
Memcached官方:http://danga.com/memcached/
關於Memcached的介紹請參考:Memcached深度分析
下載Windows的Server端
下載地址:http://code.jellycan.com/memcached/
安裝Memcache Server(也可以不安裝直接啟動)
1. 下載memcached的windows穩定版,解壓放某個盤下面,比如在c:\memcached
2. 在CMD下輸入 "c:\memcached\memcached.exe -d install" 安裝.
3. 再輸入:"c:\memcached\memcached.exe -d start" 啟動。NOTE: 以後memcached將作為windows的一個服務每次開機時自動啟動。這樣伺服器端已經安裝完畢了。
如果下載的是二進位的版本,直接運行就可以了,可以加上參數來加以設定。
常用設定:
-p <num> 監聽的連接埠
-l <ip_addr> 串連的IP地址, 預設是本機
-d start 啟動memcached服務
-d restart 重起memcached服務
-d stop|shutdown 關閉正在啟動並執行memcached服務
-d install 安裝memcached服務
-d uninstall 卸載memcached服務
-u <username> 以<username>的身份運行 (僅在以root啟動並執行時候有效)
-m <num> 最大記憶體使用量,單位MB。預設64MB
-M 記憶體耗盡時返回錯誤,而不是刪除項
-c <num> 最大同時串連數,預設是1024
-f <factor> 塊大小增長因子,預設是1.25
-n <bytes> 最小分配空間,key+value+flags預設是48
-h 顯示協助
然後就可以用.net 的memcached用戶端來試一下了。
C# 下可用的API(每個用戶端API中都有詳細的說明和注釋)
https://sourceforge.net/projects/memcacheddotnet/
http://www.codeplex.com/EnyimMemcached/ - Client developed in .NET 2.0 keeping performance and extensibility in
mind. (Supports consistent hashing.)
http://code.google.com/p/beitmemcached/ - Client developed by BeIT with many new features
轉載出處: http://www.yaosansi.com/
----------------------------------------------------------------------------------------
Client調用:
下載範例程式碼網址: http://sourceforge.net/projects/memcacheddotnet/
C#/.NET memcached client library. This library can be used by .NET projects to access memcached servers. Ported from the Java memcached library located athttp://www.whalin.com/memcached/.
e.g.: view source print ?
005 |
* Tim Gebhardt <tim@gebhardtcomputing.com> |
007 |
* Based off of code written by |
008 |
* Greg Whalin <greg@meetup.com> |
009 |
* for his Java Memcached client: |
010 |
* http://www.whalin.com/memcached/ |
013 |
* See the memcached website: |
014 |
* http://www.danga.com/memcached/ |
016 |
* This module is Copyright (c) 2005 Tim Gebhardt. |
017 |
* All rights reserved. |
019 |
* This library is free software; you can redistribute it and/or |
020 |
* modify it under the terms of the GNU Lesser General Public |
021 |
* License as published by the Free Software Foundation; either |
022 |
* version 2.1 of the License, or (at your option) any later |
025 |
* This library is distributed in the hope that it will be |
026 |
* useful, but WITHOUT ANY WARRANTY; without even the implied |
027 |
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
028 |
* PURPOSE. See the GNU Lesser General Public License for more |
031 |
* You should have received a copy of the GNU Lesser General Public |
032 |
* License along with this library; if not, write to the Free Software |
033 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
035 |
* @author Tim Gebhardt<tim@gebhardtcomputing.com> |
038 |
namespace Memcached.MemcachedBench |
041 |
using System.Collections; |
043 |
using Memcached.ClientLibrary; |
045 |
public class MemcachedBench |
049 |
/// arg[0] = the number of runs to do |
050 |
/// arg[1] = the run at which to start benchmarking |
052 |
/// <param name="args"></param> |
054 |
public static void Main(String[] args) |