Redis配置文件詳解html
若是不指定配置文件,redis也能夠啓動,此時,redis使用默認的內置配置。不過在正式環境,經常經過配置文件【一般叫redis.conf】來配置redis。git
redis.conf配置格式以下:github
- keyword argument1 argument2 ... argumentN
redis.conf配置參數:web
1)daemonize on|yesredis
redis默認不是以守護進程的方式運行,能夠經過該配置項修改,使用yes時,啓用守護進程算法
2)pidfile /var/run/redis_6379.pid數據庫
redis以守護進程方式運行時,系統默認會把pid寫入/var/run/redis.pid,能夠經過pidfile指定pid文件windows
3)port 6379api
redis默認監聽6379端口,能夠經過port指定redis要監聽的端口緩存
4)bind 127.0.0.1
綁定主機地址
5)unixsocket /tmp/redis.sock
指定redis監聽的unix socket 路徑
6)timeout 300
當客戶端閒置多長時間,關閉鏈接,單位秒
7)loglevel verbose|debug|notice|warning
指定日誌記錄級別,默認是verbose
8)logfile /var/log/redis_6379.log
日誌記錄文件,默認是標準輸出stdout,若是redis以守護進程方式運行,logfile 配置爲stdout時,logs將要輸出到/dev/null
9)syslog-enabled no|yes
當配置爲yes時,日誌輸出到系統日誌,默認是no
10)syslog-ident redis
指定syslog的標示符
11)syslog-facility local0
指定syslog設備(facility),必須是user或則local0到local7
12)databases 16
設置redis中數據庫的個數,默認數據庫是DB 0,能夠經過select <dbid>,選擇使用的數據庫。dbis大於等於0,小於等於databases -1 【這裏是16-1】
13)save <seconds> <changes>
指定多長時間內,有多少次更新操做時,將數據同步到數據庫文件,能夠多個條件配合,系統默認配置以下:
- save 900 1 #900秒 1個修改
- save 300 10 #300秒 10個更新
- save 60 10000<span style="white-space:pre"> </span>#60秒 10000個更新
注意,若是不持久化【不把數據寫入磁盤】,註釋掉save便可。
14)rdbcompression yes|no
數據dump到數據文件時,系統是否壓縮string對象數據,系統默認是yes。若是爲了節省cpu,能夠設置爲no,此時數據文件比用LZF壓縮時要大
15)dbfilename dump.rdb
指定數據庫文件名,默認是dump.rdb
16)dir /var/lib/redis/6379
指定本地數據庫存放目錄
17)slaveof <masterip> <masterport>
當本機是slave服務時,設置master服務的ip和端口
18)masterauth <master-password>
當master服務設置了密碼時,slave服務鏈接master的密碼。若是配置不對,slave服務請求將被拒絕
19)slave-serve-stale-data yes|no
當slave和master之間的鏈接斷開或slave正在於master同步時,若是有slave請求,當slave-serve-stale-data配置爲yes時,slave能夠相應客戶端請求;當爲no時,slave將要響應錯誤,默認是yes
20)requirepass foobared
設置redis鏈接密碼
21)maxclients 128
設置同一時間客戶端最大鏈接數,默認是無限制。若是設置maxclients 0 時,表示不限制
22)maxmemory <bytes>
指定redis最大內存限制,redis在啓動時,會把數據加載到內存中,達到最大內存後,redis會先清除已到期或將過時的key,仍然到達最大內存設置,將沒法再進行寫入操做,但仍然能夠進行讀操做
23)maxmemory-policy volatile-lru|allkeys-lru|volatile-random|allkeys->random|volatile-ttl|noeviction
當redis使用內存達到最大時,使用哪一種策略移除內存中數據
24)appendonly no|yes
指定是否在每次更新操做後進行日誌記錄,默認配置是no,即在採用異步方式把數據寫入到磁盤,若是不開啓,可能會在斷電時致使部分數據丟失
25)appendfilename appendonly.aof
指定更新日誌文件名【aof日誌】,默認爲appendonly.aof
26)appendfsync everysec|no|aways
指定更新日誌條件,no表示等操做系統進行數據緩存同步到磁盤的aof文件(快)always表示每次更新操做後手動調用fsync將數據寫到磁盤的aof文件(慢,安全)
everysec,表示每秒同步一次(拆中,默認值)
27)slowlog-log-slower-than 10000
配置記錄慢日誌的條件,單位是微妙,當是負值時,關閉慢日誌記錄,當是0時,記錄全部操做
28)slowlog-max-len 1024
配置記錄慢查詢的最大條數
29)hash-max-zipmap-entries 512
配置最大元素數,當超過該配置數據時,redis採用特殊hash算法
30)hash-max-zipmap-value 64
配置最大元素值,當草果配置值時,採用特殊hash算法
31)activerehashing yes
指定是否激活充值hash,默認開啓
能夠經過下面命令使用配置文件redis.conf啓動redis服務
Redis安裝管理
C#客戶端Redis服務器的分佈式緩存
在這篇文章中,我想介紹我知道的一種最緊湊的安裝和配置Redis服務器的方式。另外,我想簡短地概述一下在.NET / C#客戶端下Redis hash(哈希類型)和list(鏈表)的使用。
-
做者:小峯來源:碼農網|2015-08-17 09:48
-
介紹
在這篇文章中,我想介紹我知道的一種最緊湊的安裝和配置Redis服務器的方式。另外,我想簡短地概述一下在.NET / C#客戶端下Redis hash(哈希類型)和list(鏈表)的使用。
在這篇文章主要講到:
背景
Redis是最快也是功能最豐富的內存Key-Value數據存儲系統之一。
缺點
優勢
下面我將簡單說明如何在服務器上安裝和配置Redis,並用C#使用它。
Redis的安裝
從https://github.com/dmajkic/redis/downloads(win32 win64直接連接)下載二進制文件,解包檔案到應用程序目錄(如C:\Program Files\Redis)
下載從https://github.com/kcherenkov/redis-windows-service/downloads編譯的Redis服務,而後複製到程序文件夾(如C:\Program Files\Redis)。若是配置文件丟失,也能夠下載複製到應用程序目錄。有效的Redis配置文件的範例在https://raw.github.com/antirez/redis/2.6/redis.conf。
Redis應用程序的完整文件也能夠從壓縮文件(x64)獲得。
當你擁有了全套的應用程序文件(以下圖所示),

導航到應用程序目錄,而後運行如下命令:
sc create %name% binpath= "\"%binpath%\" %configpath%" start= "auto" DisplayName= "Redis"
其中:
-
%name%——服務實例的名稱,例如:redis-instance;
-
%binpath%——到項目exe文件的路徑,例如:C:\Program Files\Redis\RedisService_1.1.exe;
-
%configpath%——到Redis配置文件的路徑,例如:C:\Program Files\Redis\redis.conf;
舉例:
sc create Redis start= auto DisplayName= Redis binpath= "\"C:\Program Files\Redis\RedisService_1.1.exe\
" \"C:\Program Files\Redis\redis.conf\""
即應該是這樣的:

請確保有足夠的權限啓動該服務。安裝完畢後,請檢查該服務是否建立成功,當前是否正在運行:

或者,你可使用安裝程序(我沒試過):https://github.com/rgl/redis/downloads。
Redis服務器保護:密碼,IP過濾
保護Redis服務器的主要方式是使用Windows防火牆或活躍的網絡鏈接屬性設置IP過濾。此外,還可使用Redis密碼設置額外保護。這須要用下面的方式更新Redis配置文件(redis.conf):
首先,找到這行:
# requirepass foobared
刪除開頭的#符號,用新密碼替換foobared:
requirepass foobared
而後,從新啓動Redis Windows服務!
當具體使用客戶端的時候,使用帶密碼的構造函數:
RedisClient client = new RedisClient(serverHost, port, redisPassword);
Redis服務器複製(主—從配置)
Redis支持主從同步,即,每次主服務器修改,從服務器獲得通知,並自動同步。大多複製用於讀取(但不能寫)擴展和數據冗餘和服務器故障轉移。設 置兩個Redis實例(在相同或不一樣服務器上的兩個服務),而後配置其中之一做爲從站。爲了讓Redis服務器實例是另外一臺服務器的從屬,能夠這樣更改配 置文件:
找到如下代碼:
# slaveof <masterip> <masterport>
替換爲:
slaveof 192.168.1.1 6379
(能夠自定義指定主服務器的真實IP和端口)。若是主服務器配置爲須要密碼(驗證),能夠以下所示改變redis.conf,找到這一行代碼:
# masterauth <master-password>
刪除開頭的#符號,用主服務器的密碼替換<master-password>,即:
masterauth mastpassword
如今這個Redis實例能夠被用來做爲主服務器的只讀同步副本。
用C#代碼使用Redis緩存
用C#代碼使用Redis運行Manage NuGet包插件,找到ServiceStack.Redis包,並進行安裝。

直接從實例化客戶端使用Set
/Get
方法示例:
- string host = "localhost";
- string elementKey = "testKeyRedis";
-
- using (RedisClient redisClient = new RedisClient(host))
- {
- if (redisClient.Get<string>(elementKey) == null)
- {
-
- Thread.Sleep(5000);
-
- redisClient.Set(elementKey, "some cached value");
- }
-
- message = "Item value is: " + redisClient.Get<string>("some cached value");
- }
類型化實體集更有意思和更實用,這是由於它們操做的是確切類型的對象。在下面的代碼示例中,有兩個類分別定義爲Phone和Person——phone的主人。每一個phone實例引用它的主人。下面的代碼演示咱們如何經過標準添加、刪除和發現緩存項:
- public class Phone
- {
- public int Id { get; set; }
- public string Model { get; set; }
- public string Manufacturer { get; set; }
- public Person Owner { get; set; }
- }
-
- public class Person
- {
- public int Id { get; set; }
- public string Name { get; set; }
- public string Surname { get; set; }
- public int Age { get; set; }
- public string Profession { get; set; }
- }
-
- using (RedisClient redisClient = new RedisClient(host))
- {
- IRedisTypedClient<phone> phones = redisClient.As<phone>();
- Phone phoneFive = phones.GetValue("5");
- if (phoneFive == null)
- {
-
- Thread.Sleep(5000);
-
- phoneFive = new Phone
- {
- Id = 5,
- Manufacturer = "Motorolla",
- Model = "xxxxx",
- Owner = new Person
- {
- Id = 1,
- Age = 90,
- Name = "OldOne",
- Profession = "sportsmen",
- Surname = "OldManSurname"
- }
- };
-
- phones.SetEntry(phoneFive.Id.ToString(), phoneFive);
- }
- message = "Phone model is " + phoneFive.Manufacturer;
- message += "Phone Owner Name is: " + phoneFive.Owner.Name;
- }
在上面的例子中,咱們實例化了輸入端IRedisTypedClient,它與緩存對象的特定類型——Phone類型一塊兒工做。
Redis ASP.NET會話狀態
要用Redis提供商配置ASP.NET會話狀態,添加新文件到你的Web項目,命名爲RedisSessionStateProvider.cs,能夠從https://github.com/chadman/redis-service-provider/raw/master/RedisProvider/SessionProvider/RedisSessionProvider.cs複製代碼,而後添加或更改配置文件中的如下部分(sessionState標籤已經內置於system.web標籤),或者你也能夠下載附加來源和複製代碼。
- <sessionstate timeout="1" mode="Custom"
- customprovider="RedisSessionStateProvider" cookieless="false">
- <providers>
- <add name="RedisSessionStateProvider" writeexceptionstoeventlog="false"
- type="RedisProvider.SessionProvider.CustomServiceProvider"
- server="localhost" port="6379" password="pasword">
- </add> </providers>
- </sessionstate>
注意,此密碼是能夠選擇的,看服務器是否須要認證。它必須被真實的值替換或刪除,若是Redis服務器不須要身份驗證,那麼服務器屬性和端口得由具體的數值代替(默認端口爲6379)。而後在項目中,你纔可使用會話狀態:
- public class MvcApplication1 : System.Web.HttpApplication
- {
- protected void Application_Start()
- {
-
- }
-
- protected void Session_Start()
- {
- Session["testRedisSession"] = "Message from the redis ression";
- }
- }
-
- 在Home controller(主控制器):
-
- public class HomeController : Controller
- {
- public ActionResult Index()
- {
-
- ViewBag.Message = Session["testRedisSession"];
- return View();
- }
- }
結果:

ASP.NET輸出緩存提供者,而且Redis能夠用相似的方式進行配置。
Redis Set(集合)和List(列表)
主要要注意的是,Redis列表實現IList<T>,而Redis集合實現ICollection<T>
。下面來講說如何使用它們。
當須要區分相同類型的不一樣分類對象時,使用列表。例如,咱們有「mostSelling(熱銷手機)」和「oldCollection(回收手機)」兩個列表:
- string host = "localhost";
- using (var redisClient = new RedisClient(host))
- {
-
- IRedisTypedClient<phone> redis = redisClient.As<phone>();
-
- IRedisList<phone> mostSelling = redis.Lists["urn:phones:mostselling"];
- IRedisList<phone> oldCollection = redis.Lists["urn:phones:oldcollection"];
-
- Person phonesOwner = new Person
- {
- Id = 7,
- Age = 90,
- Name = "OldOne",
- Profession = "sportsmen",
- Surname = "OldManSurname"
- };
-
-
- mostSelling.Add(new Phone
- {
- Id = 5,
- Manufacturer = "Sony",
- Model = "768564564566",
- Owner = phonesOwner
- });
-
- oldCollection.Add(new Phone
- {
- Id = 8,
- Manufacturer = "Motorolla",
- Model = "324557546754",
- Owner = phonesOwner
- });
-
- var upgradedPhone = new Phone
- {
- Id = 3,
- Manufacturer = "LG",
- Model = "634563456",
- Owner = phonesOwner
- };
-
- mostSelling.Add(upgradedPhone);
-
-
- oldCollection.Remove(upgradedPhone);
-
-
- IEnumerable<phone> LGPhones = mostSelling.Where(ph => ph.Manufacturer == "LG");
-
-
- Phone singleElement = mostSelling.FirstOrDefault(ph => ph.Id == 8);
-
-
- redis.SetSequence(0);
- redisClient.Remove("urn:phones:mostselling");
- redisClient.Remove("urn:phones:oldcollection");
- }
當須要存儲相關的數據集和收集統計信息,例如answer -> queustion給答案或問題投票時,Redis集合就很是好使。假設咱們有不少的問題(queustion)和答案(answer ),須要將它們存儲在緩存中。使用Redis,咱們能夠這麼作:
- IRedisClientsManager RedisManager { get; set; }
- public void DeleteQuestion(long questionId)
- {
- using (var redis = RedisManager.GetClient())
- {
- var redisQuestions = redis.As<question>();
-
- var question = redisQuestions.GetById(questionId);
- if (question == null) return;
-
-
- question.Tags.ForEach(tag => redis.IncrementItemInSortedSet("urn:tags", tag, -1));
-
-
- redisQuestions.DeleteRelatedEntities<answer>(questionId);
-
-
- redis.RemoveItemFromSet("urn:user>q:" + question.UserId, questionId.ToString());
-
-
- question.Tags.ForEach("urn:tags>q:" + tag.ToLower(), questionId.ToString()));
-
- redisQuestions.DeleteById(questionId);
- }
- }
-
- public void StoreQuestion(Question question)
- {
- using (var redis = RedisManager.GetClient())
- {
- var redisQuestions = redis.As<question>();
-
- if (question.Tags == null) question.Tags = new List<string>();
- if (question.Id == default(long))
- {
- question.Id = redisQuestions.GetNextSequence();
- question.CreatedDate = DateTime.UtcNow;
-
-
- question.Tags.ForEach(tag => redis.IncrementItemInSortedSet("urn:tags", tag, 1));
- }
-
- redisQuestions.Store(question);
- redisQuestions.AddToRecentsList(question);
- redis.AddItemToSet("urn:user>q:" + question.UserId, question.Id.ToString());
-
-
- question.Tags.ForEach(tag => redis.AddItemToSet
- ("urn:tags>q:" + tag.ToLower(), question.Id.ToString()));
- }
- }
-
- public void DeleteAnswer(long questionId, long answerId)
- {
- using (var redis = RedisManager.GetClient())
- {
- var answer = redis.As<question>().GetRelatedEntities<answer>
- (questionId).FirstOrDefault(x => x.Id == answerId);
- if (answer == null) return;
-
- redis.As<question>().DeleteRelatedEntity<answer>(questionId, answerId);
-
-
- redis.RemoveItemFromSet("urn:user>a:" + answer.UserId, answerId.ToString());
- }
- }
-
- public void StoreAnswer(Answer answer)
- {
- using (var redis = RedisManager.GetClient())
- {
- if (answer.Id == default(long))
- {
- answer.Id = redis.As<answer>().GetNextSequence();
- answer.CreatedDate = DateTime.UtcNow;
- }
-
-
- redis.As<question>().StoreRelatedEntities(answer.QuestionId, answer);
-
- redis.AddItemToSet("urn:user>a:" + answer.UserId, answer.Id.ToString());
- }
- }
-
- public List<answer> GetAnswersForQuestion(long questionId)
- {
- using (var redis = RedisManager.GetClient())
- {
- return redis.As<question>().GetRelatedEntities<answer>(questionId);
- }
- }
-
- public void VoteQuestionUp(long userId, long questionId)
- {
-
- RedisManager.ExecTrans(trans =>
- {
-
- trans.QueueCommand(redis =>
- redis.AddItemToSet("urn:q>user+:" + questionId, userId.ToString()));
- trans.QueueCommand(redis =>
- redis.RemoveItemFromSet("urn:q>user-:" + questionId, userId.ToString()));
-
-
- trans.QueueCommand(redis =>
- redis.AddItemToSet("urn:user>q+:" + userId, questionId.ToString()));
- trans.QueueCommand(redis =>
- redis.RemoveItemFromSet("urn:user>q-:" + userId, questionId.ToString()));
- });
- }
-
- public void VoteQuestionDown(long userId, long questionId)
- {
-
- RedisManager.ExecTrans(trans =>
- {
-
- trans.QueueCommand(redis =>
- redis.AddItemToSet("urn:q>user-:" + questionId, userId.ToString()));
- trans.QueueCommand(redis =>
- redis.RemoveItemFromSet("urn:q>user+:" + questionId, userId.ToString()));
-
-
- trans.QueueCommand(redis =>
- redis.AddItemToSet"urn:user>q-:" + userId, questionId.ToString()));
- trans.QueueCommand(redis =>
- redis.RemoveItemFromSet("urn:user>q+:" + userId, questionId.ToString()));
- });
- }
-
- public void VoteAnswerUp(long userId, long answerId)
- {
-
- RedisManager.ExecTrans(trans =>
- {
-
- trans.QueueCommand(redis =>
- redis.AddItemToSet("urn:a>user+:" + answerId, userId.ToString()));
- trans.QueueCommand(redis =>
- redis.RemoveItemFromSet("urn:a>user-:" + answerId, userId.ToString()));
-
-
- trans.QueueCommand(redis =>
- redis.AddItemToSet("urn:user>a+:" + userId, answerId.ToString()));
- trans.QueueCommand(redis =>
- redis.RemoveItemFromSet("urn:user>a-:" + userId, answerId.ToString()));
- });
- }
-
- public void VoteAnswerDown(long userId, long answerId)
- {
-
- RedisManager.ExecTrans(trans =>
- {
-
- trans.QueueCommand(redis =>
- redis.AddItemToSet("urn:a>user-:" + answerId, userId.ToString()));
- trans.QueueCommand(redis =>
- redis.RemoveItemFromSet("urn:a>user+:" + answerId, userId.ToString()));
-
-
- trans.QueueCommand(redis =>
- redis.AddItemToSet("urn:user>a-:" + userId, answerId.ToString()));
- trans.QueueCommand(redis =>
- redis.RemoveItemFromSet("urn:user>a+:" + userId, answerId.ToString()));
- });
- }
-
- public QuestionResult GetQuestion(long questionId)
- {
- var question = RedisManager.ExecAs<question>
- (redisQuestions => redisQuestions.GetById(questionId));
- if (question == null) return null;
-
- var result = ToQuestionResults(new[] { question })[0];
- var answers = GetAnswersForQuestion(questionId);
- var uniqueUserIds = answers.ConvertAll(x => x.UserId).ToHashSet();
- var usersMap = GetUsersByIds(uniqueUserIds).ToDictionary(x => x.Id);
-
- result.Answers = answers.ConvertAll(answer =>
- new AnswerResult { Answer = answer, User = usersMap[answer.UserId] });
-
- return result;
- }
-
- public List<user> GetUsersByIds(IEnumerable<long> userIds)
- {
- return RedisManager.ExecAs<user>(redisUsers => redisUsers.GetByIds(userIds)).ToList();
- }
-
- public QuestionStat GetQuestionStats(long questionId)
- {
- using (var redis = RedisManager.GetReadOnlyClient())
- {
- var result = new QuestionStat
- {
- VotesUpCount = redis.GetSetCount("urn:q>user+:" +questionId),
- VotesDownCount = redis.GetSetCount("urn:q>user-:" + questionId)
- };
- result.VotesTotal = result.VotesUpCount - result.VotesDownCount;
- return result;
- }
- }
-
- public List<tag> GetTagsByPopularity(int skip, int take)
- {
- using (var redis = RedisManager.GetReadOnlyClient())
- {
- var tagEntries = redis.GetRangeWithScoresFromSortedSetDesc("urn:tags", skip, take);
- var tags = tagEntries.ConvertAll(kvp => new Tag { Name = kvp.Key, Score = (int)kvp.Value });
- return tags;
- }
- }
-
- public SiteStats GetSiteStats()
- {
- using (var redis = RedisManager.GetClient())
- {
- return new SiteStats
- {
- QuestionsCount = redis.As<question>().TypeIdsSet.Count,
- AnswersCount = redis.As<answer>().TypeIdsSet.Count,
- TopTags = GetTagsByPopularity(0, 10)
- };
- }
- }
附加資源說明
項目中引用的一些包在packages.config文件中配置。
Funq IoC的相關配置,以及註冊類型和當前控制器目錄,在Global.asax文件中配置。
基於IoC的緩存使用以及Global.asax能夠打開如下URL:http://localhost:37447/Question/GetQuestions?tag=test 查看。
你能夠將tag字段設置成test3,test1,test2等。
Redis緩存配置——在web config文件(<system.web><sessionState>節點)以及RedisSessionStateProvider.cs文件中。
在MVC項目中有不少待辦事項,所以,若是你想改進/繼續,請更新,並上傳。
若是有人能提供使用Redis(以及Funq IOC)緩存的MVC應用程序示例,本人將不勝感激。Funq IOC已經配置,使用示例已經在Question controller中。
注:部分取樣於「ServiceStack.Examples-master」解決方案。
結論。優化應用程序緩存以及快速本地緩存
因爲Redis並不在本地存儲(也不在本地複製)數據,那麼經過在本地緩存區存儲一些輕量級或用戶依賴的對象(跳過序列化字符串和客戶端—服務端數據轉換)來優化性能是有意義的。例如,在Web應用中,對於輕量級的對象使用’System.Runtime.Caching.ObjectCache
‘ 會更好——用戶依賴,而且應用程序時常要用。不然,當常常性地須要使用該對象時,就必須在分佈式Redis緩存中存儲大量容積的內容。用戶依賴的對象舉例——我的資料信息,個性化信息 。經常使用對象——本地化數據,不一樣用戶之間的共享信息,等等。
下載源代碼(Redis Funq LoC MVC 4版本)
連接
如何運行Redis服務:
https://github.com/kcherenkov/redis-windows-service
文檔:
http://redis.io/documentation
.NET / C#示例:
https://github.com/ServiceStack/ServiceStack.Examples
關於如何用C#在Windows上使用Redis的好建議:
http://maxivak.com/getting-started-with-redis-and-asp-net-mvc-under-windows/:
http://www.piotrwalat.net/using-redis-with-asp-net-web-api/
關於Redis:
https://github.com/ServiceStack/ServiceStack.Redis
Azure緩存
http://kotugoroshko.blogspot.ae/2013/07/windows-azure-caching-integration.html
許可證
這篇文章,以及任何相關的源代碼和文件,依據The Code Project Open License (CPOL)。
譯文連接:http://www.codeceo.com/article/distributed-caching-redis-server.html
英文原文:Distributed Caching using Redis Server with .NET/C# Client
園內博客簡單安裝Redis方法
一、redis簡介
redis是一個key-value存儲系統。和Memcached相似,它支持存儲的value類型相對更多,包括string(字符串)、list(鏈表)、set(集合)、zset(sorted set --有序集合)和hashs(哈希類型)。這些數據類型都支持push/pop、add/remove及取交集並集和差集及更豐富的操做,並且這些操做都是原子性的。在此基礎上,redis支持各類不一樣方式的排序。與memcached同樣,爲了保證效率,數據都是緩存在內存中。區別的是redis會週期性的把更新的數據寫入磁盤或者把修改操做寫入追加的記錄文件,而且在此基礎上實現了master-slave(主從)同步。
Redis 是一個高性能的key-value數據庫。 redis的出現,很大程度補償了memcached這類key/value存儲的不足,在部分場合能夠對關係數據庫起到很好的補充做用。它提供了Python,Ruby,Erlang,PHP客戶端,使用很方便。
二、windows下安裝redis
下載地址https://github.com/dmajkic/redis/downloads。下載到的Redis支持32bit和64bit。根據本身實際狀況選擇,我選擇32bit。把32bit文件內容拷貝到須要安裝的目錄下,好比:D:\dev\redis-2.4.5。
打開一個cmd窗口,使用cd命令切換到指定目錄(D:\dev\redis-2.4.5)運行 redis-server.exe redis.conf 。運行之後出現以下界面。

這就說明Redis服務端已經安裝成功。
從新打開一個cmd窗口,使用cd命令切換到指定目錄(D:\dev\redis-2.4.5)運行 redis-cli.exe -h 127.0.0.1 -p 6379 -a 123456,其中 127.0.0.1是本地ip,6379是redis服務端的默認端口,123456是redis密碼。運行成功以下圖所示。
這樣,Redis windows環境下搭建已經完成,是否是很簡單。

這樣,Redis windows環境下搭建已經完成,是否是很簡單。
環境已經搭建好,總得測試下吧。好比:存儲一個key爲test,value爲hello word的字符串,而後獲取key值。
正確輸出 hell word,測試成功!