配置
配置文件位置 /usr/local/etc/redis.conf
# 默认启动
redis-server
# 通过配置文件启动
redis-server /path_to/redis.conf
# 非保护模式下启动
redis-server --protected-mode no
# 测试是否启动成功
redis-cli ping
# 开机启动
ln -sfv /usr/local/opt/redis/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
# 取消开机启动
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
# 卸载
brew uninstall redis
rm ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
命令
set [key] [value]
get [key]
del [key]
exists [key]
type [key]
mset [key2] [value2] [key2] [value2] ...
mget [key1] [key2] ...
# List
rpush mylist [value1] [value2] ...
rpush mylist v1 v2 v3 v4 v5
lpush mylist v0
rpop mylist
lpop mylist
llen mylist
lrange mylist [start_index] [stop_index]
ltrim mylist [start_index] [stop_index]
# Hash
hset [key] [field] [value]
hget [key] [field]
hmset [key] [field1] [value2] [field2] [value2] ...
hmget [key] [field1] [field2] ...
hmset user:1000 username zhudongfang birthday 19900312
hmget user:1000 username birtdday
hset user:1000 username xiaoming
hget user:1000 username
hget user:1000 birthday
hgetall user:1000
# Set
sadd myset 1 2 3
smembers myset
sismember myset 1
备份导出
gem install redis-dump
redis-dump > db.json
Install and config Redis on Mac OS X via Homebrew
Install and config Redis server on Ubuntu Linux 16.04
网友评论