mac下redis安裝、設(shè)置、啟動(dòng)停止方法詳解
需要下載release版本,下載地址:
http://download.redis.io/releases/
我這里下載的是:
http://download.redis.io/releases/redis-3.2.5.tar.gz
解壓到/usr/local/redis目錄中,然后依次執(zhí)行以下命令:
cd /usr/local/redis sudo make test
sudo make install
啟動(dòng)redis-server
redis-server
如上圖,redis-server啟動(dòng)成功,并監(jiān)聽6379端口。
常用命令說明
redis-server redis服務(wù)器
redis-cli redis客戶端
redis-benchmark redis性能測試工具
redis-check-aof AOF文件修復(fù)工具
redis-check-rdb RDB文件修復(fù)工具
啟動(dòng)和停止
服務(wù)端啟動(dòng)
默認(rèn)啟動(dòng)
如上,在命令redis-server即啟動(dòng)redis服務(wù)端。且接受客戶端連接
根據(jù)設(shè)置啟動(dòng)
在 /usr/local/redis目錄下建立bin,etc,db三個(gè)目錄
把/usr/local/redis/src目錄下的mkreleasehdr.sh,redis-benchmark, redis-check-rdb, redis-cli, redis-server拷貝到bin目錄
在etc下,新建配置redis.conf,內(nèi)容如下。
/usr/local/redis下新建日志文件log-redis.log,并修改當(dāng)前用戶使用權(quán)限。sudo chown -R shoren /usr/local/redis/
啟動(dòng)服務(wù)端:redis-server /usr/local/redis/etc/redis.conf
#修改為守護(hù)模式 daemonize yes #設(shè)置進(jìn)程鎖文件 pidfile /usr/local/redis/redis.pid #端口 port 6379 #客戶端超時(shí)時(shí)間 timeout 300 #日志級(jí)別 loglevel debug #日志文件位置 logfile /usr/local/redis/log-redis.log #設(shè)置數(shù)據(jù)庫的數(shù)量,默認(rèn)數(shù)據(jù)庫為16,可以使用SELECT 命令在連接上指定數(shù)據(jù)庫id databases 16 ##指定在多長時(shí)間內(nèi),有多少次更新操作,就將數(shù)據(jù)同步到數(shù)據(jù)文件,可以多個(gè)條件配合 #save #Redis默認(rèn)配置文件中提供了三個(gè)條件: save 900 1 save 300 10 save 60 10000 #指定存儲(chǔ)至本地?cái)?shù)據(jù)庫時(shí)是否壓縮數(shù)據(jù),默認(rèn)為yes,Redis采用LZF壓縮,如果為了節(jié)省CPU時(shí)間, #可以關(guān)閉該#選項(xiàng),但會(huì)導(dǎo)致數(shù)據(jù)庫文件變的巨大 rdbcompression yes #指定本地?cái)?shù)據(jù)庫文件名 dbfilename dump.rdb #指定本地?cái)?shù)據(jù)庫路徑 dir /usr/local/redis/db/ #指定是否在每次更新操作后進(jìn)行日志記錄,Redis在默認(rèn)情況下是異步的把數(shù)據(jù)寫入磁盤,如果不開啟,可能 #會(huì)在斷電時(shí)導(dǎo)致一段時(shí)間內(nèi)的數(shù)據(jù)丟失。因?yàn)?redis本身同步數(shù)據(jù)文件是按上面save條件來同步的,所以有 #的數(shù)據(jù)會(huì)在一段時(shí)間內(nèi)只存在于內(nèi)存中 appendonly no #指定更新日志條件,共有3個(gè)可選值: #no:表示等操作系統(tǒng)進(jìn)行數(shù)據(jù)緩存同步到磁盤(快) #always:表示每次更新操作后手動(dòng)調(diào)用fsync()將數(shù)據(jù)寫到磁盤(慢,安全) #everysec:表示每秒同步一次(折衷,默認(rèn)值) appendfsync everysec
接著,可以查看日志,如下,表示啟動(dòng)成功:
_._ _.-``__ ''-._ _.-`` `. `_. ''-._ Redis 3.2.5 (00000000/0) 64 bit .-`` .-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in standalone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | `-._ `._ / _.-' | PID: 14447 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | http://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-' 14447:M 24 Apr 17:57:33.215 # Server started, Redis version 3.2.5 14447:M 24 Apr 17:57:33.215 * The server is now ready to accept connections on port 6379 14447:M 24 Apr 17:57:33.215 - 0 clients connected (0 slaves), 956832 bytes in use 14447:M 24 Apr 17:57:38.257 - 0 clients connected (0 slaves), 956832 bytes in use
關(guān)閉服務(wù)端
強(qiáng)行關(guān)閉
強(qiáng)行終止redis進(jìn)程可能會(huì)導(dǎo)致數(shù)據(jù)丟失,因?yàn)閞edis可能正在將內(nèi)存數(shù)據(jù)同步到硬盤中。
ps axu|grep redis ## 查找redis-server的PID kill -9 PID
命令關(guān)閉
向redis發(fā)送SHUTDOWN命令,即 redis-cli SHUTDOWN 。Redis收到命令后,服務(wù)端會(huì)斷開所有客戶端的連接,然后根據(jù)配置執(zhí)行持久化,最后退出。
## 啟動(dòng)redis-server,后臺(tái)線程 AT8775:redis shoren$ redis-server /usr/local/redis/etc/redis.conf ## 啟動(dòng)成功 AT8775:redis shoren$ ps axu|grep redis shoren 14948 0.0 0.0 2434840 760 s000 S+ 10:18上午 0:00.00 grep redis shoren 14946 0.0 0.0 2452968 1492 ?? Ss 10:18上午 0:00.01 redis-server *:6379 ## 關(guān)閉服務(wù)器 AT8775:redis shoren$ redis-cli shutdown ##關(guān)閉成功 AT8775:redis shoren$ ps axu|grep redis shoren 14952 0.0 0.0 2435864 772 s000 S+ 10:19上午 0:00.01 grep redis
啟動(dòng)客戶端
默認(rèn)啟動(dòng)
使用命令redis-cli啟動(dòng)客戶端,按照默認(rèn)配置連接Redis(127.0.0.1:6379)。
指定地址和端口號(hào)
使用命令 redis-cli -h 127.0.0.1 -p 6379
關(guān)閉客戶端
交互模式使用quit
AT8775:redis shoren$ redis-cli -h 127.0.0.1 -p 6379 ## 簡單使用set、get命令 127.0.0.1:6379> set key value12 OK 127.0.0.1:6379> get key "value12" ## 退出 127.0.0.1:6379> quit AT8775:redis shoren$
更多mac下redis安裝、設(shè)置、啟動(dòng)停止方法文章請(qǐng)查看下面的相關(guān)鏈接
相關(guān)文章
使用Redis實(shí)現(xiàn)記錄訪問次數(shù)的三種方案
這篇文章主要介紹了使用Redis實(shí)現(xiàn)記錄訪問次數(shù)的三種方案,文中通過代碼示例和圖文講解的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作有一定的幫助,需要的朋友可以參考下2024-09-09redis延時(shí)隊(duì)列zset實(shí)現(xiàn)的示例
延時(shí)隊(duì)列是一種常用的設(shè)計(jì)模式,用于處理那些需要在未來某個(gè)時(shí)間點(diǎn)執(zhí)行的任務(wù),本文主要介紹了redis延時(shí)隊(duì)列zset實(shí)現(xiàn)的示例,具有一定的參考價(jià)值,感興趣的可以了解一下2024-08-08Redis 事務(wù)與過期時(shí)間詳細(xì)介紹
這篇文章主要介紹了Redis 事務(wù)與過期時(shí)間詳細(xì)介紹的相關(guān)資料,需要的朋友可以參考下2017-05-05關(guān)于Redis網(wǎng)絡(luò)模型的源碼詳析
這篇文章主要給大家介紹了關(guān)于Redis網(wǎng)絡(luò)模型的源碼,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者使用Redis具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2020-07-07Redis和Nginx實(shí)現(xiàn)限制接口請(qǐng)求頻率的示例
限流就是限制API訪問頻率,當(dāng)訪問頻率超過某個(gè)閾值時(shí)進(jìn)行拒絕訪問等操作,本文主要介紹了Redis和Nginx實(shí)現(xiàn)限制接口請(qǐng)求頻率的示例,具有一定的參考價(jià)值,感興趣的可以了解一下2024-02-02redis集群搭建_動(dòng)力節(jié)點(diǎn)Java學(xué)院整理
這篇文章主要介紹了redis集群搭建,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-08-08