redis简介和安装

redis简介

Redis是一个开源(BSD许可),内存数据结构存储系统,可以用作数据库,缓存和消息代理。

它的支持数据结构有:字符串(Strings),散列(Hash),列表(List),集合(Set),有序集合(SortedSet或者是ZSet ),带有范围查询的排序集,位图(Bitmaps),Hyperloglog和地理空间(Geospatial)索引半径查询。其中比较常见的就是Stirngs,hash,List,Set,SortedSet,Zset五种数据类型。

Redis内置了复制(Replication),Lua脚本(Lua scripting),LRU驱逐(LRU eviction),事务(Transactions)和不同级别的磁盘持久性(Persistence),并通过Redis Sentinel(redis 哨兵)和Redis Cluster自动分区提供高可用性(High Availability)。
Redis也提供了持久化的选项,这些选项可以让用户将自己的数据保存到磁盘上面进行存储。根据实际情况,可以每隔一定时间将数据集导出到磁盘(快照),或者追加到命令日志中(AOF只追加文件),他会在执行写命令时,将被执行的写命令复制到硬盘里面。您也可以关闭持久化功能,将Redis作为一个高效的网络的缓存数据功能使用。

Redis不使用表,他的数据库不会预定义或者强制去要求用户对Redis存储的不同数据进行关联。

数据库的工作模式按存储方式可分为:硬盘数据库和内存数据库。Redis 将数据储存在内存里面,读写数据的时候都不会受到硬盘 I/O 速度的限制,所以速度极快。

(1)硬盘数据库的工作模式:
image]

(2) 内存数据库的工作模式:
image]

安装

1.在linux上使用wget命令通过redis官网直接下载redis

# wget -P /usr/local/ http://download.redis.io/releases/redis-5.0.3.tar.gz

2.解压redis-5.0.3.tar.gz到当前目录

# tar -zxvf redis-5.0.3.tar.gz

3.进入reddis目录编译

# cd /redis-5.0.3
# make

4.安装redis

# cd src
# make install
# ls /usr/local/bin
redis-benchmark*  redis-check-aof*  redis-check-rdb*  redis-cli*  redis-sentinel@  redis-server*

从/usr/local/bin目录中看到reids的可执行命令

5.修改配置文件redis.conf

在启动redis之前,我们首先应该配置redis的配置文件redis.conf,该文件在redis安装目录下/
在linux中安装程序时,若有默认的配置文件,一定要先配置,不要在默认配置文件上

$ cp -p redis.conf redis.conf.bak
$ vim redis.conf

################################# GENERAL #####################################

# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
daemonize no

该配置意思时默认情况下redis服务端不是一个守护线程,即在关闭终端后,redis服务会默认关闭,此时若不希望redis关闭,应该将其设置为yes

6.启动redis服务端

redis启动需要读取的配置文件是根目录下的redis.conf,我们先备份一份,然后启动reddis-server

$ /usr/local/bin/redis-server
7262:C 10 Mar 2019 05:55:19.391 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
7262:C 10 Mar 2019 05:55:19.391 # Redis version=5.0.3, bits=64, commit=00000000, modified=0, pid=7262, just started
7262:C 10 Mar 2019 05:55:19.391 # Warning: no config file specified, using the default config. In order to specify a config file use src/redis-server /path/to/redis.conf
7262:M 10 Mar 2019 05:55:19.392 * Increased maximum number of open files to 10032 (it was originally set to 1024).
               _._                                                  
          _.-``__ ''-._                                             
     _.-``    `.  `_.  ''-._           Redis 5.0.3 (00000000/0) 64 bit
 .-`` .-```.  ```\/    _.,_ ''-._                                   
(    '      ,       .-`  | `,    )     Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
|    `-._   `._    /     _.-'    |     PID: 7262
 `-._    `-._  `-./  _.-'    _.-'                                   
|`-._`-._    `-.__.-'    _.-'_.-'|                                  
|    `-._`-._        _.-'_.-'    |           http://redis.io        
 `-._    `-._`-.__.-'_.-'    _.-'                                   
|`-._`-._    `-.__.-'    _.-'_.-'|                                  
|    `-._`-._        _.-'_.-'    |                                  
 `-._    `-._`-.__.-'_.-'    _.-'                                   
     `-._    `-.__.-'    _.-'                                       
         `-._        _.-'                                           
             `-.__.-'                                               

7262:M 10 Mar 2019 05:55:19.394 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
7262:M 10 Mar 2019 05:55:19.394 # Server initialized
7262:M 10 Mar 2019 05:55:19.394 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
7262:M 10 Mar 2019 05:55:19.394 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
7262:M 10 Mar 2019 05:55:19.394 * Ready to accept connections

当出现如上内容时,表示redis服务端启动成功
5.启动redis客户端

$ redis-cli -p 6379
127.0.0.1:6379>

#查看所有客户端
127.0.0.1:6379> client list
id=3 addr=127.0.0.1:42527 fd=8 name= age=7 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=26 qbuf-free=32742 obl=0 oll=0 omem=0 events=r cmd=client
#杀掉某个客户端
127.0.0.1:6379> client kill 127.0.0.1:42527
OK

若返回ok则表示删除客户端成功,之后会重新创建一个客户端,注意这里杀掉的端口好不是6379,而是客户端的随机端口.

6.关闭服务端

$ redis-cli shutdown
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值