安裝memcached
使用brew 安裝:
brew install memcached ==> Installing memcached ==> Downloading https://homebrew.bintray.com/bottles/memcached-1.5.7.high_sierra ######################################################################## 100.0% ==> Pouring memcached-1.5.7.high_sierra.bottle.tar.gz ==> Caveats To have launchd start memcached now and restart at login: brew services start memcached Or, if you don't want/need a background service you can just run: /usr/local/opt/memcached/bin/memcached ==> Summary /usr/local/Cellar/memcached/1.5.7: 11 files, 199.2KB
使用brew 安裝好memcached 可以使用如下方式啟動(dòng)start、停止stop、重啟restart
# 第一種方式: brew services start memcached # 第二種方式: memcached -p 11211 -u nobody -c 1024 -m 64m -d -vv
參數(shù)解釋:
-p 使用的TCP端口,默認(rèn)為11211 -u 用戶名(只使用root 運(yùn)行的時(shí)候) -c 最大連接數(shù) -m 最大內(nèi)存大小默認(rèn)為64m -vv 用very verbose模式啟動(dòng),調(diào)試信息和錯(cuò)誤輸出到控制臺(tái) -d 作為daemon在后臺(tái)啟動(dòng)
使用memcached
啟動(dòng)memcached,直接使用telnet連接到memcached端口:
~ $ brew services start memcached ==> Successfully started `memcached` (label: homebrew.mxcl.memcached) ~ shouei$ telnet localhost 11211 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'.
數(shù)據(jù)讀取:
# 數(shù)據(jù)寫(xiě)入 set foo 0 0 3 bar # 顯示如下,表示數(shù)據(jù)寫(xiě)入成功 STORED
set key flag expires byte:
flag 表示是否壓縮數(shù)據(jù),0不壓縮,1壓縮
expires 指定數(shù)據(jù)保存的時(shí)間,一種方法是秒數(shù)(不能超過(guò)30天),另外一種可以使用unix 時(shí)間戳指定,0 為有效期無(wú)限
byte 保存值的字節(jié)數(shù)
# 數(shù)據(jù)讀取 get foo # 顯示如下,表示數(shù)據(jù)讀取成功 VALUE foo 0 3 bar END
結(jié)束telnet,輸入telnet退出命令:quit