nicenote/source/_posts/redis环境搭建.md
2018-05-26 17:58:20 +08:00

111 lines
2.4 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: redis环境搭建
date: 2018-03-07 10:35:17
tags: [redis]
categories: 数据库
---
# redis 环境搭建
## 下载
[官方网站](https://redis.io/)
## 安装
```js
解压
tar zxvf redis-4.0.8.tar.gz
移动文件夹
mv redis-4.0.8 /usr/local/
打开该文件夹
cd /usr/local/redis-4.0.8/
编译测试
sudo make test
编译安装
sudo make install
```
## 启动
```js
redis-server
```
## 配置
```t
新建目录
sudo mkdir redis-4.0.8/bin
sudo mkdir redis-4.0.8/etc
sudo mkdir redis-4.0.8/db
拷贝文件
cp src/mkreleasehdr.sh bin
cp src/redis-benchmark bin
cp src/redis-check-rdb bin
cp src/redis-cli bin
cp src/redis-server bin
```
## 修改redis.conf
```t
#修改为守护模式
daemonize yes
#设置进程锁文件
pidfile /usr/local/redis-3.2.8/redis.pid
#端口
port 6379
#客户端超时时间
timeout 300
#日志级别
loglevel debug
#日志文件位置
logfile /usr/local/redis-3.2.8/log-redis.log
#设置数据库的数量默认数据库为0可以使用SELECT <dbid>命令在连接上指定数据库id
databases 16
##指定在多长时间内,有多少次更新操作,就将数据同步到数据文件,可以多个条件配合
#save <seconds> <changes>
#Redis默认配置文件中提供了三个条件
save 900 1
save 300 10
save 60 10000
#指定存储至本地数据库时是否压缩数据默认为yesRedis采用LZF压缩如果为了节省CPU时间
#可以关闭该#选项,但会导致数据库文件变的巨大
rdbcompression yes
#指定本地数据库文件名
dbfilename dump.rdb
#指定本地数据库路径
dir /usr/local/redis-3.2.8/db/
#指定是否在每次更新操作后进行日志记录Redis在默认情况下是异步的把数据写入磁盘如果不开启可能
#会在断电时导致一段时间内的数据丢失。因为 redis本身同步数据文件是按上面save条件来同步的所以有
#的数据会在一段时间内只存在于内存中
appendonly no
#指定更新日志条件共有3个可选值
#no表示等操作系统进行数据缓存同步到磁盘
#always表示每次更新操作后手动调用fsync()将数据写到磁盘(慢,安全)
#everysec表示每秒同步一次折衷默认值
appendfsync everysec
```
## 启动服务
```t
启动
./bin/redis-server etc/redis.conf
查看日志
tail -f log-redis.log
OK
./bin/redis-cli
```
## 基本命令
```redis
查看所有数据
keys *
插入键值对
set a b
查看数据
get a
```