下面由Redis教程欄目給大家介紹單機(jī)Redis環(huán)境搭建方法,希望對需要的朋友有所幫助!
序言
在實(shí)際開發(fā)項(xiàng)目過程中, 如果說要用到緩存, 那么第一個想到的一定是Redis, 但是為什么選Redis大多數(shù)人都不會去了解, 也不會去思考, 只知道它能當(dāng)緩存使用, 比數(shù)據(jù)庫快一點(diǎn), 恰巧我也是這樣的一個人;所以, 當(dāng)我想寫一篇關(guān)于Redis介紹的時候, 我竟然無從說起; 這也是對于Redis以及主流內(nèi)存數(shù)據(jù)庫不熟的原因; 不過, 在以后的日子里, 一定增加自己對于框架的思考與深入, 讓自己在后面的技術(shù)道路上有所沉淀, 希望以后有人讓我簡要介紹Redis的時候, 我不會無從說起;這或許就是我想寫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/
啟動Redis服務(wù)
./redis-server ../conf/redis.conf & //啟動的時候后臺運(yùn)行
啟動輸出日志:
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 //一個是Redis服務(wù) 501 45897 44430 0 10:11下午 ttys000 0:00.00 grep redis //ps查詢進(jìn)程自己
到這里, 一個單機(jī)版的Redis服務(wù)就搭建完成了!
二、使用Redis存儲數(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>
到此, 我們可以使用Redis系統(tǒng)來存儲數(shù)據(jù)字符串?dāng)?shù)據(jù)了.