Redis
比较简单:首先安装Homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
然后:
brew install redis
brew install redis
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> Updated Formulae
sonar-scanner
Error: Could not link:
/usr/local/share/doc/homebrew
Please delete these paths and run `brew update`.
==> Downloading https://homebrew.bintray.com/bottles/redis-5.0.3.mojave.bottle.t
######################################################################## 100.0%
==> Pouring redis-5.0.3.mojave.bottle.tar.gz
==> Caveats
To have launchd start redis now and restart at login:
brew services start redis
Or, if you don't want/need a background service you can just run:
redis-server /usr/local/etc/redis.conf
==> Summary
🍺 /usr/local/Cellar/redis/5.0.3: 13 files, 3.1MB
这样就安装完成了。不要先急着用redis-cli,先把服务端用redis-server
启动:
redis-server
87277:C 10 Jan 2019 07:16:04.956 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
87277:C 10 Jan 2019 07:16:04.956 # Redis version=5.0.3, bits=64, commit=00000000, modified=0, pid=87277, just started
87277:C 10 Jan 2019 07:16:04.956 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
87277:M 10 Jan 2019 07:16:04.958 * Increased maximum number of open files to 10032 (it was originally set to 256).
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 5.0.3 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 87277
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
87277:M 10 Jan 2019 07:16:04.962 # Server initialized
87277:M 10 Jan 2019 07:16:04.962 * Ready to accept connections
然后再另开一个终端窗口,使用redis-cli
,看到127.0.0.1:6379>
的提示符,说明成功。
那么简单的来操作一下吧:
127.0.0.1:6379> PING
PONG
127.0.0.1:6379> set name miaomiao
OK
127.0.0.1:6379> get name
"miaomiao"
127.0.0.1:6379>
首先,执行 PING 命令,该命令用于检测 redis 服务是否启动。得到了PONG的回复,说明已经启动。
接着使用了 SET 和 GET 命令,键为 name,值为miaomiao。
怎么样,是不是非常简单呢?继续来看一些应用吧。
keys *
可以获取当前库下的所有key。不过这个操作比较耗费资源,所以非常非常非常不建议直接在生产环境上使用这个命令!而且Redis的开发规范,也是建议禁用keys命令的。
对于在redis中很常见的一种list结构对象,如果使用get来获取值,是要报错的,此时需要按照元素下标索引取值,例如:
lindex mylist 0
lindex中的l,是left,代表左边队列。
mylist是该list类型对象在redis数据库中的寻址标识映射值。
0就是下标咯!
MongoDB
同样使用brew来安装:brew install mongodb
坐等,很快就装好了,最后它会提示你如何启动,以及配置文件的地址如下:
==> mongodb
To have launchd start mongodb now and restart at login:
brew services start mongodb
Or, if you don't want/need a background service you can just run:
mongod --config /usr/local/etc/mongod.conf
那就试试:
$ brew services start mongodb
==> Tapping homebrew/services
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-services'...
remote: Enumerating objects: 17, done.
remote: Counting objects: 100% (17/17), done.
remote: Compressing objects: 100% (14/14), done.
remote: Total 17 (delta 0), reused 12 (delta 0), pack-reused 0
Unpacking objects: 100% (17/17), done.
Tapped 1 command (50 files, 62.1KB).
==> Successfully started `mongodb` (label: homebrew.mxcl.mongodb)
看提示,已经启动了。
然后继续启动客户端:
$ mongo
MongoDB shell version v4.0.4
connecting to: mongodb://127.0.0.1:27017
Implicit session: session { "id" : UUID("6385bdde-a4da-4ebf-9b40-4025ae4434c3") }
MongoDB server version: 4.0.4
Welcome to the MongoDB shell.
……
比较长就不贴全了,最后看到>
提示符就说明已经启动成功了,可以操作了。
网友评论