Redis介绍及入门安装及使用
Redis介绍及入门安装及使用
什么是Redis
Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker. It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs, geospatial indexes with radius queries and streams. Redis has built-in replication, Lua scripting, LRU eviction, transactions and different levels of on-disk persistence, and provides high availability via Redis Sentinel and automatic partitioning with Redis Cluster。
根据Redis的官网介绍,我们可以得知Redis有以下功能及特性:
- Redis是一个开源的、基于BSD协议的内存数据结构存储,可以用来当做数据库、缓存、消息代理。
- 支持的数据格式包括:strings、hashes、lists、sets、sorted sets with range queries、bitmaps, hyperloglogs、geospatial indexes with radius queries 、streams。
- Redis本身提供复制、Lua脚本、LRU清除、事务、及不同级别的持久机制,通过Sentinel和Cluster来保证高可用性。
为什么要选择Redis
- 性能优异,Redis官方验证了在不同CPU下的Redis性能,感兴趣的同学请移步,https://redis.io/topics/benchmarks ,每秒10w+的读写操作是完全是小菜一碟,当然在实际中因为服服务器的CPU/环境会有些许出入,但足以应对觉得大多数的复杂应用场景。
- 支持复杂的数据结构,除了常用的KEY -Value之外,还支持其他多种复杂的数据结构,比如Set 、Lists、bitmaps、hyperloglogs 、 geospatial 、stream。
- 提供了持久化的功能,方便快速恢复数据。
- 支持读写分离、主从复制、哨兵模式、集群模式,保证高可用。
- 对存储的Value大小没有内容限制。方便存储较大的数据。
安装Redis
官网最新稳定的版本为:[Redis 5.0.6 is the latest stable version]:http://download.redis.io/releases/redis-5.0.6.tar.gz 。
Redis的安装
$ wget http://download.redis.io/releases/redis-5.0.6.tar.gz
$ tar xzf redis-5.0.6.tar.gz
$ cd redis-5.0.6
$ make
如果在执行make指令时出现如下错误:
/bin/sh: cc: command not found
make[1]: *** [adlist.o] Error 127
make[1]: Leaving directory `/opt/software/redis/redis-5.0.6/src'
make: *** [all] Error 2
说明没有安装gcc,因为Redis是C实现的,所以需要安装gcc来进行编译。
安装gcc指令:
yum install gcc
安装完成后执行以下操作:
# 删除上次安装的Redis目录及子目录
$ rm -rf redis-5.0.6
# 重新解压和编译
$ tar xzf redis-5.0.6.tar.gz
$ cd redis-5.0.6
$ make
启动服务端
# 启动服务端
[enjoyitlife@localhost redis-5.0.6]$ src/redis-server
# 启动成功会显示如下信息
[enjoyitlife@localhost redis-5.0.6]$ src/redis-server
11872:C 20 Nov 2019 07:13:57.586 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
11872:C 20 Nov 2019 07:13:57.586 # Redis version=5.0.6, bits=64, commit=00000000, modified=0, pid=11872, just started
11872:C 20 Nov 2019 07:13:57.586 # Warning: no config file specified, using the default config. In order to specify a config file use src/redis-server /path/to/redis.conf
11872:M 20 Nov 2019 07:13:57.589 # You requested maxclients of 10000 requiring at least 10032 max file descriptors.
11872:M 20 Nov 2019 07:13:57.590 # Server can't set maximum open files to 10032 because of OS error: Operation not permitted.
11872:M 20 Nov 2019 07:13:57.590 # Current maximum open files is 4096. maxclients has been reduced to 4064 to compensate for low ulimit. If you need higher maxclients increase 'ulimit -n'.
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 5.0.6 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 11872
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
11872:M 20 Nov 2019 07:13:57.594 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
11872:M 20 Nov 2019 07:13:57.595 # Server initialized
11872:M 20 Nov 2019 07:13:57.595 # 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.
11872:M 20 Nov 2019 07:13:57.595 # 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.
11872:M 20 Nov 2019 07:13:57.595 * Ready to accept connections
客户端连接
# 新开一个Shell 窗口
[enjoyitlife@localhost ~]$ cd /opt/software/redis/redis-5.0.6
[enjoyitlife@localhost redis-5.0.6]$ src/redis-cli
# 表示连接成功
127.0.0.1:6379>
命令测试
127.0.0.1:6379> set name enjoyitlife
OK
127.0.0.1:6379> get name
"enjoyitlife"
127.0.0.1:6379>
设置Redis后台运行
# 修改redis.conf 中 daemonize no 改成 yes
daemonize yes
# 可以先将文件改下名,然后在启动的时候 以指定的文件启动
[enjoyitlife@localhost redis-5.0.6]$ cp redis.conf redis6379.conf
[enjoyitlife@localhost redis-5.0.6]$ src/redis-server redis6379.conf
# 此时就不会出现Redis的Logo图片了,而是如下说明, 表明后台启动Redis成功
[zpenjoy@localhost redis-5.0.4]$ src/redis-server redis6379.conf
11920:C 20 Nov 2019 07:21:21.021 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
11920:C 20 Nov 2019 07:21:21.022 # Redis version=5.0.6, bits=64, commit=00000000, modified=0, pid=11920, just started
11920:C 20 Nov 2019 07:21:21.022 # Configuration loaded
停止Redis服务
# 可以通过关闭进程的方式 强制关闭 不建议使用该方式
[enjoyitlife@localhost ~]$ ps -ef|grep redis
[enjoyitlife@localhost redis-5.0.6]$ ps -ef|grep redis
enjoyit+ 11921 1 0 07:21 ? 00:00:00 src/redis-server 127.0.0.1:6379
enjoyit+ 11929 11898 0 07:23 pts/1 00:00:00 src/redis-cli
enjoyit+ 11956 11933 0 07:25 pts/0 00:00:00 grep --color=auto redis
[enjoyitlife@localhost redis-5.0.6]$ kill -9 11921
# 推荐方式
./src/redis-cli shutdown
好了,Redis基本介绍及安装就介绍到这里了,谢谢阅读。
Redis介绍及入门安装及使用的更多相关文章
- Redis介绍和环境安装
-------------------Redis环境安装------------------- 1.安装 1.卸载软件 sudo apt-get remove redis-se ...
- redis介绍、单机安装以及java调用
什么是redis Redis是用C语言开发的一个开源的高性能键值对(key-value)数据库.和传统的关系型数据库不一样,不一定遵循传统数据库的一些基本要求(非关系型的.分布式的.开源的.水平可扩展 ...
- redis介绍、安装、redis持久化、redis数据类型
1.redis介绍 2.安装管网:https://redis.io/下载:wget -c http://download.redis.io/releases/redis-4.0.11.tar.gz解 ...
- Redis介绍——Linux环境Redis安装全过程和遇到的问题及解决方案
一:redis的入门介绍: 首先贴出官网; 英文:https://redis.io/ 中文:http://www.redis.cn/ 1.是什么 --REmote DIctionary Server( ...
- Redis介绍以及安装(Linux)
Redis介绍以及安装(Linux) redis是当前比较热门的NOSQL系统之一,它是一个key-value存储系统.和Memcached类似,但很大程度补偿了memcached的不足,它支持存储的 ...
- redis介绍以及安装
一.redis介绍 redis是一个key-value存储系统.和Memcached类似,它支持存储的values类型相对更多,包括字符串.列表.哈希散列表.集合,有序集合. 这些数据类型都支持pus ...
- Redis介绍以及安装(Linux)
Redis介绍以及安装(Linux) redis是当前比较热门的NOSQL系统之一,它是一个key-value存储系统.和Memcached类似,但很大程度补偿了memcached的不足,它支持存储的 ...
- [Redis_1] Redis 介绍 && 安装
0. 说明 Redis 介绍 && 安装 1. Redis 介绍 2. Redis 安装(Windows 10) [2.1 解压 redis-2.2.2-win32-win64.rar ...
- 1.Redis介绍以及安装
Redis介绍 Redis是一个开源的(BSD开源协议),内存数据结构存储,被用于作为数据库,缓存和消息代理. Redis支持如下数据结构: string(字符串) hashes(哈希) lists ...
随机推荐
- 常用sql---表记录数和占用空间统计
1.每张表的记录数和占用空间 select owner as 用户名, table_name as 表名, num_rows as 记录数, ROUND(t.NUM_ROWS * t.AVG_ROW_ ...
- Netty学习第三章 Linux网络编程使用的I/O模型
一.同步阻塞IO:blocking IO(BIO) 1.过程分析: 当进程进行系统调用时,内核就会去准备数据,当数据准备好后就复制数据到内核缓冲器,复制完成后将数据拷贝到用户进程内存,整个过程都是阻塞 ...
- IP地址与子网掩码逐位相与
逐位相与说的其实就是子网掩码与网络地址相同位置的数字相加,当和为2的时候该位置写作1,否则的话写作0
- 基于jQuery封装的分页组件(可自定义设置)
jQuery封装的分页组件 前几天做了一个vue的组件分页,而现在需求是jquery的分页,我就根据我自己的需求写了一个.在网上找了很久的基于jquery的分页封装,可是都不是我想要的结果,那么今天我 ...
- QQ群文件未通过安全检查,禁止下载该文件
直接用手机收藏群文件,然后用电脑登上qq去收藏里面下载就ok了
- vue单页面项目中解决安卓4.4版本不兼容的问题
1.cnpm安装 cnpm i babel-polyfill --save cnpm i es6-promise --save 2.main.js引入 import ‘babel-polyfill‘ ...
- java:集合输出之Iterator和ListIterator
在调用Iterator集合输出时,如果想要删除某个元素,请直接使用Iterator来判断元素是否存在然后再删除(next()当前指针内容,remove()删除当前内容 );如果在将集合丢给Iterat ...
- 决策树剪枝算法-悲观剪枝算法(PEP)
前言 在机器学习经典算法中,决策树算法的重要性想必大家都是知道的.不管是ID3算法还是比如C4.5算法等等,都面临一个问题,就是通过直接生成的完全决策树对于训练样本来说是“过度拟合”的,说白了是太精确 ...
- 你肯定不知道的oracle数据库和sql server的这些区别
它们两者之间的区别主要体现在六大方面: 一是开放性. 1.SQL Server 只可在windows上运行,缺乏开放性,操作系统的稳定对数据库是非常重要的. Windows9X系列产品比较偏重于桌面应 ...
- 封装通用的 ajax, 基于 jQuery。
在前端异步获取数据时候每次都是使用 ajax:为了通用性更好,然而封装通用的 ajax 是一个一劳永逸的办法. 本次基于 jQuery 封装实现: 第一步: 引入 jQuery: <script ...