Redis-01.初探
官网 http://redis.io
中文网 http://redis.cn
命令参考 http://redisdoc.cn
Redis(Remote Dictionary Server)是一个开源的key-value内存存储的NoSQL数据库,具有非常强悍的读写性能,现阶段正越来越多地被用于互联网高并发场景。
1 安装
Linux(CentOS 7.2)下yum方式安装
yum install redis
2 启动
2.1 交互模式启动
[root@VM_0_171_centos ~]# redis-server
23173:C 26 Mar 16:13:02.365 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 3.2.3 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 23173
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
23173:M 26 Mar 16:13:02.366 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
23173:M 26 Mar 16:13:02.366 # Server started, Redis version 3.2.3
23173:M 26 Mar 16:13:02.366 # 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.
23173:M 26 Mar 16:13:02.366 # 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.
23173:M 26 Mar 16:13:02.366 * DB loaded from disk: 0.000 seconds
23173:M 26 Mar 16:13:02.366 * The server is now ready to accept connections on port 6379
2.2 后台启动
step 1:需要修改配置文件/etc/redis.conf
# By default Redis does not run as a daemon. Use 'yes' if you need it.
daemonize yes
step 2:使用配置文件启动
[root@VM_0_171_centos ~]# redis-server /etc/redis.conf
[root@VM_0_171_centos ~]#
3 客户端连接
[root@VM_0_171_centos ~]# redis-cli
127.0.0.1:6379> ping
PONG
127.0.0.1:6379>
4 停止服务
[root@VM_0_171_centos ~]# redis-shutdown
[root@VM_0_171_centos ~]#
5 其它程序
redis通过yum方式安装后,所有程序均位于/usr/bin目录
[root@VM_0_171_centos ~]# ls -l /usr/bin | grep redis
-rwxr-xr-x 1 root root 86832 8月 5 2016 redis-benchmark
-rwxr-xr-x 1 root root 15408 8月 5 2016 redis-check-aof
-rwxr-xr-x 1 root root 975248 8月 5 2016 redis-check-rdb
-rwxr-xr-x 1 root root 173344 8月 5 2016 redis-cli
lrwxrwxrwx 1 root root 12 3月 25 23:41 redis-sentinel -> redis-server
-rwxr-xr-x 1 root root 975248 8月 5 2016 redis-server
-rwxr-xr-x 1 root root 918 8月 5 2016 redis-shutdown
[root@VM_0_171_centos ~]#
其中redis-benchmark可以用来测试redis的性能,官网给出的信息是redis的读速度:110000次/s,写速度:81000次/s
[root@VM_0_171_centos ~]# redis-benchmark
====== PING_INLINE ======
100000 requests completed in 0.69 seconds
50 parallel clients
3 bytes payload
keep alive: 1
100.00% <= 0 milliseconds
145137.88 requests per second
====== PING_BULK ======
100000 requests completed in 0.65 seconds
50 parallel clients
3 bytes payload
keep alive: 1
100.00% <= 0 milliseconds
153846.16 requests per second
====== SET ======
100000 requests completed in 0.65 seconds
50 parallel clients
3 bytes payload
keep alive: 1
99.97% <= 1 milliseconds
100.00% <= 1 milliseconds
153609.83 requests per second
====== GET ======
100000 requests completed in 0.64 seconds
50 parallel clients
3 bytes payload
keep alive: 1
100.00% <= 0 milliseconds
156250.00 requests per second
====== INCR ======
100000 requests completed in 0.64 seconds
50 parallel clients
3 bytes payload
keep alive: 1
100.00% <= 0 milliseconds
156006.25 requests per second
====== LPUSH ======
100000 requests completed in 0.65 seconds
50 parallel clients
3 bytes payload
keep alive: 1
100.00% <= 0 milliseconds
153846.16 requests per second
====== RPUSH ======
100000 requests completed in 0.64 seconds
50 parallel clients
3 bytes payload
keep alive: 1
100.00% <= 0 milliseconds
156985.86 requests per second
====== LPOP ======
100000 requests completed in 0.65 seconds
50 parallel clients
3 bytes payload
keep alive: 1
100.00% <= 0 milliseconds
153374.23 requests per second
====== RPOP ======
100000 requests completed in 0.65 seconds
50 parallel clients
3 bytes payload
keep alive: 1
100.00% <= 0 milliseconds
153374.23 requests per second
====== SADD ======
100000 requests completed in 0.65 seconds
50 parallel clients
3 bytes payload
keep alive: 1
100.00% <= 0 milliseconds
152671.77 requests per second
====== SPOP ======
100000 requests completed in 0.65 seconds
50 parallel clients
3 bytes payload
keep alive: 1
100.00% <= 0 milliseconds
154083.20 requests per second
====== LPUSH (needed to benchmark LRANGE) ======
100000 requests completed in 0.65 seconds
50 parallel clients
3 bytes payload
keep alive: 1
100.00% <= 0 milliseconds
153846.16 requests per second
====== LRANGE_100 (first 100 elements) ======
100000 requests completed in 0.64 seconds
50 parallel clients
3 bytes payload
keep alive: 1
99.97% <= 1 milliseconds
100.00% <= 1 milliseconds
155279.50 requests per second
====== LRANGE_300 (first 300 elements) ======
100000 requests completed in 0.64 seconds
50 parallel clients
3 bytes payload
keep alive: 1
99.99% <= 1 milliseconds
100.00% <= 1 milliseconds
155763.23 requests per second
====== LRANGE_500 (first 450 elements) ======
100000 requests completed in 0.65 seconds
50 parallel clients
3 bytes payload
keep alive: 1
100.00% <= 0 milliseconds
154320.98 requests per second
====== LRANGE_600 (first 600 elements) ======
100000 requests completed in 0.65 seconds
50 parallel clients
3 bytes payload
keep alive: 1
100.00% <= 0 milliseconds
153374.23 requests per second
====== MSET (10 keys) ======
100000 requests completed in 0.63 seconds
50 parallel clients
3 bytes payload
keep alive: 1
100.00% <= 0 milliseconds
159744.41 requests per second
[root@VM_0_171_centos ~]#
6 配置文件
通过yum方式安装后,redis的配置文件的位置为:/etc/redis.conf,包括前面提到的后台启动也是需要通过修改配置文件实现,配置项比较多,需要对redis有进一步了解
6.1 设置密码
如果要限制连接redis必须使用密码,需要配置requirepass选项:requriepass
################################## SECURITY ###################################
# Require clients to issue AUTH <PASSWORD> before processing any other
# commands. This might be useful in environments in which you do not trust
# others with access to the host running redis-server.
#
# This should stay commented out for backward compatibility and because most
# people do not need auth (e.g. they run their own servers).
#
# Warning: since Redis is pretty fast an outside user can try up to
# 150k passwords per second against a good box. This means that you should
# use a very strong password otherwise it will be very easy to break.
#
requirepass 123456
设置密码后需要重启服务,再连接redis-cli时会提示需要验证授权,通过auth 命令验证
[root@VM_0_171_centos ~]# vim /etc/redis.conf
[root@VM_0_171_centos ~]# redis-server /etc/redis.conf
[root@VM_0_171_centos ~]# redis-cli
127.0.0.1:6379> ping
(error) NOAUTH Authentication required.
127.0.0.1:6379> auth 123456
OK
127.0.0.1:6379> ping
PONG
127.0.0.1:6379>
7 帮助
客户端连接redis后,可以通过help获取帮助,帮助信息里面给出了3种不同方式获取帮助,具体用法其它章节会进一步描述
127.0.0.1:6379> help
redis-cli 3.2.3
To get help about Redis commands type:
"help @<group>" to get a list of commands in <group>
"help <command>" for help on <command>
"help <tab>" to get a list of possible help topics
"quit" to exit
To set redis-cli perferences:
":set hints" enable online hints
":set nohints" disable online hints
Set your preferences in ~/.redisclirc
Redis-01.初探的更多相关文章
- Redis -- 01 入门
1. Redis是什么 与memcached 和 couchbase类似,redis是非常快速的基于内存的键值数据库,使用标准c编写,是使用最广泛的缓存中间件.利用Redis提供的五种基本数据类型(S ...
- redis geo 初探
redis的geo搜索功能是3.2之后新增的,所以实验开始之前先查看redis的版本,确保版本正确. redis的geo多用于地理类应用,所以这次还是用了高德地图API来用作数据源. 首先截取几个点: ...
- 这几天对Redis的初探,写一个阶段性的东西
原来基于wcf写了一个交互框架,其中自定义了一个session队列,用于保存客户端连接的一些信息. 这几天在想如何将这个wcf框架做负载均衡,于是将session队列拆分出来,用一个共享的内存进行处理 ...
- NoSQL之Redis数据库初探
一.NoSQL的风生水起 1.1 后Web2.0时代的发展要求 随着互联网Web2.0网站的兴起,传统的关系数据库在应付Web2.0网站,特别是超大规模和高并发的SNS类型的Web2.0纯动态网站已经 ...
- Redis 01 概述
参考源 https://www.bilibili.com/video/BV1S54y1R7SB?spm_id_from=333.999.0.0 版本 本文章基于 Redis 6.2.6 简介 NoSQ ...
- Redis 01: 非关系型数据库 + 配置Redis
数据库应用的发展历程 单机数据库时代:一个应用,一个数据库实例 缓存时代:对某些表中的数据访问频繁,则对这些数据设置缓存(此时数据库中总的数据量不是很大) 水平切分时代:将数据库中的表存放到不同数据库 ...
- 01 - 初探JavaScript魅力
网页特效原理 用JavaScript修改样式 编写JS的流程 布局:HTML+CSS 属性:确定要修改哪些属性 事件:确定用户做哪些操作(产品设计) 编写JS:在事件中,用JS来修改页面元素的样式 鼠 ...
- Web前端开发推荐阅读书籍、学习课程下载
转自http://www.xuanfengge.com/fe-books.html 前言 学校里没有前端的课程,那如何学习JavaScript,又如何使自己成为一个合格的前端工程师呢? 除了在项目中学 ...
- 00-A-springmvc分布式项目项目结构
项目使用IDEA进行开发 一个分布式项目基本需要的模块. 用到的技术spring+springmvc+mybatis+dubbo +mysql+redis 01模块名字:p2p-parent 作为父模 ...
- NoSQL初探之人人都爱Redis:(3)使用Redis作为消息队列服务场景应用案例
一.消息队列场景简介 “消息”是在两台计算机间传送的数据单位.消息可以非常简单,例如只包含文本字符串:也可以更复杂,可能包含嵌入对象.消息被发送到队列中,“消息队列”是在消息的传输过程中保存消息的容器 ...
随机推荐
- ambiguous
ambiguous - 必应词典 美[æm'bɪɡjuəs]英[æm'bɪɡjuəs] adj.模棱两可的:含混不清的:多义的:不明确的 网络含糊的:模糊的:暧昧的 搭配ambiguous answe ...
- Nevertheless 和 Nonetheless,你用对了吗?
本文转自:https://www.sohu.com/a/229443257_338773 Nevertheless 以及 nonetheless 都可以表示转折.很多人很多课程也提到这两者基本上可以交 ...
- vue的表单输入绑定
1.单行绑定 <p>{{logintype}}</p> <input type="text" v-model="logintype" ...
- 关于有时候JQuery使用.val()赋值失败问题
jQuery中有3个获取元素value值的函数比较相似:attr(), prop(), val(): 具体作用网上比较多就不展示对比过程了,结果就是:prop()和val()都能获取到文本框的实际va ...
- ReentrantLock 实现
ReentrantLock 实现: 关于锁的操作都是依赖于state 的值,当state =0 时候,表示 线程可以获取锁,state =1 表示锁已经占用,等待释放 获取锁的方法: protec ...
- 20175325 《JAVA程序设计》实验一 《JAVA开发环境的熟悉》实验报告
20175325 <JAVA程序设计>实验一 <JAVA开发环境的熟悉>实验报告 一.实验内容及步骤 (一).实验一: 实验要求: 0 参考实验要求 1 建立"自己学 ...
- MongoDB的Replica Set以及Auth的配置
http://blog.0x01.site/2017/01/13/MongoDB%E7%9A%84Replica-Set%E4%BB%A5%E5%8F%8AAuth%E7%9A%84%E9%85%8D ...
- 关于Https
http://blog.csdn.net/wfdtxz/article/details/8678982 https://www.tuicool.com/articles/feYfE3I https:/ ...
- Linux无法正常连接服务器,无法连接上 127.0.0.1:8989 (127.0.0.1)。 - connect (111: 拒绝连接)
最近修改了下电脑的hosts文件,电脑就突然不能连接下载更新的服务器了,但是浏览器还能正常上网,这让我很是难受啊!!! 错误现象如下: 错误:1 http://archive.ubuntukylin. ...
- 2019.03.09 bzoj4491: 我也不知道题目名字是什么(线段树)
传送门 题意:给定一个序列A[i],每次询问l,r,求[l,r]内最长子串,使得该子串为不上升子串或不下降子串. 思路: 注意要求的是子串而不是子序列!!! 然后直接用线段树维护最大子段和的方式合并一 ...