您好,登錄后才能下訂單哦!
小編給大家分享一下搭建Redis環(huán)境的方法,希望大家閱讀完這篇文章后大所收獲,下面讓我們一起去探討吧!
序言
在實(shí)際開發(fā)項(xiàng)目過(guò)程中, 如果說(shuō)要用到緩存, 那么第一個(gè)想到的一定是Redis, 但是為什么選Redis大多數(shù)人都不會(huì)去了解, 也不會(huì)去思考, 只知道它能當(dāng)緩存使用, 比數(shù)據(jù)庫(kù)快一點(diǎn), 恰巧我也是這樣的一個(gè)人;所以, 當(dāng)我想寫一篇關(guān)于Redis介紹的時(shí)候, 我竟然無(wú)從說(shuō)起; 這也是對(duì)于Redis以及主流內(nèi)存數(shù)據(jù)庫(kù)不熟的原因; 不過(guò), 在以后的日子里, 一定增加自己對(duì)于框架的思考與深入, 讓自己在后面的技術(shù)道路上有所沉淀, 希望以后有人讓我簡(jiǎn)要介紹Redis的時(shí)候, 我不會(huì)無(wú)從說(shuō)起;這或許就是我想寫Redis系列博客的目的所在吧!
一、Redis環(huán)境搭建
下載redis穩(wěn)定版
curl -o redis.tar.gz http://download.redis.io/releases/redis-stable.tar.gz
解壓redis包
tar -zxvf redis-stable.tar.gz -C ./ // 該命令表示解壓tar.gz包到當(dāng)前目錄
編譯安裝redis
進(jìn)入到解壓的Redis的目錄下, 使用如下命令編譯安裝Redis
sudo make && make install PREFIX=/usr/local/redis
編輯配置Redis配置文件
sudo cp redis.conf /usr/local/redis/conf/
啟動(dòng)Redis服務(wù)
./redis-server ../conf/redis.conf & //啟動(dòng)的時(shí)候后臺(tái)運(yùn)行
啟動(dòng)輸出日志:
45894:C 02 Nov 2018 22:11:19.922 # Redis version=5.0.0, bits=64, commit=00000000, modified=0, pid=45894, just started 45894:C 02 Nov 2018 22:11:19.922 # Configuration loaded 45894:M 02 Nov 2018 22:11:19.924 * Increased maximum number of open files to 10032 (it was originally set to 256). _._ _.-``__ ''-._ _.-`` `. `_. ''-._ Redis 5.0.0 (00000000/0) 64 bit .-`` .-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in standalone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | `-._ `._ / _.-' | PID: 45894 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | http://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-' 45894:M 02 Nov 2018 22:11:19.933 # Server initialized 45894:M 02 Nov 2018 22:11:19.933 * Ready to accept connections
驗(yàn)證Redis服務(wù)
使用網(wǎng)絡(luò)工具telnet驗(yàn)證
terrydeMacBook-Air:bin terrylmay$ telnet 127.0.0.1 6379 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'.
使用系統(tǒng)進(jìn)程ps 驗(yàn)證
terrydeMacBook-Air:bin terrylmay$ ps -ef | grep redis 501 45894 44430 0 10:11下午 ttys000 0:00.04 ./redis-server 127.0.0.1:6379 //一個(gè)是Redis服務(wù) 501 45897 44430 0 10:11下午 ttys000 0:00.00 grep redis //ps查詢進(jìn)程自己
到這里, 一個(gè)單機(jī)版的Redis服務(wù)就搭建完成了!
二、使用Redis存儲(chǔ)數(shù)據(jù)
Redis CLI連接Redis服務(wù)
terrydeMacBook-Air:bin terrylmay$ ./redis-cli 127.0.0.1:6379> 127.0.0.1:6379> set name terrylmay OK 127.0.0.1:6379> get name "terrylmay" 127.0.0.1:6379>
看完了這篇文章,相信你對(duì)搭建Redis環(huán)境的方法有了一定的了解,想了解更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。