[redis] redis
redis是什么?
redis官方介绍:introduction to redis
安装:
install 拉到最下面的install小节
wget http://download.redis.io/releases/redis-4.0.11.tar.gz
tar zxvf redis-4.0..tar.gz
cd redis-4.0.
make
运行:
[root@T9 redis-4.0.]# ./src/redis-server
:C Oct ::21.602 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
:C Oct ::21.602 # Redis version=4.0., bits=, commit=, modified=, pid=, just started
:C Oct ::21.602 # Warning: no config file specified, using the default config. In order to specify a config file use ./src/redis-server /path/to/redis.conf
:M Oct ::21.603 * Increased maximum number of open files to (it was originally set to ).
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 4.0. (/) bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port:
| `-._ `._ / _.-' | PID: 14015
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-' :M Oct ::21.603 # WARNING: The TCP backlog setting of cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of .
:M Oct ::21.603 # Server initialized
:M Oct ::21.603 # WARNING overcommit_memory is set to ! 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.
:M Oct ::21.603 # 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.
:M Oct ::21.604 * Ready to accept connections
测试:
[root@T9 redis-4.0.]# ./src/redis-cli
127.0.0.1:> set foo bar
OK
127.0.0.1:> get foo
"bar"
127.0.0.1:> get bar
(nil)
127.0.0.1:>
tutorial
The book is many years old, but still relevant. Redis has evolved a lot, but most of that has been in the form of internal improvements,
new advanced features (like lua scripting) and awesome new data types. The best way to learn Redis is still to start by understanding
the fundamentals presented in this book.
读书笔记:
[redis] <<The little Redis book>>的读书笔记
其他内容摘要
在cli上查看server状态
127.0.0.1:> info
# Server
redis_version:4.0.
redis_git_sha1:
redis_git_dirty:
。。。
摘录:
# 传统关系型数据库,用表,表示一切。
If we were to apply this data structure concept to the relational world, we could say that databases expose a single
data structure - tables.
# redis,用五种基本数据结构。
To me, that defines Redis’ approach. If you are dealing with scalars, lists,
hashes, or sets, why not store them as scalars, lists, hashes and sets?
概念
数据库
用数字代表,默认是0。用select命令切换。如下:
127.0.0.1:> select
OK
127.0.0.1:[]> select
OK
127.0.0.1:>
关于K-V
While Redis is more than just a key-value store, at its core, every one of Redis’ five data structures has at least a
key and a value.
全部redis命令的详细列表
https://redis.io/commands
redis cluster的文档
HA:https://redis.io/topics/sentinel
https://redis.io/topics/cluster-tutorial
https://redis.io/topics/cluster-spec
创建redis cluster
1. 创建配置文件
[root@T9 cluster]# pwd
/root/worklist/-redis/cluster
[root@T9 cluster]# cat redis.conf
port
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout
appendonly yes
[root@T9 cluster]#
2. 为6个实例创建配置文件
[root@T9 cluster]# tree
.
├──
│ └── redis.conf
├──
│ └── redis.conf
├──
│ └── redis.conf
├──
│ └── redis.conf
├──
│ └── redis.conf
├──
│ └── redis.conf
3. 分别启动6个实例
[root@T9 7000]# ../../redis-4.0.11/src/redis-server ./redis.conf
4. 创建
[root@T9 redis-4.0.11]# ./src/redis-cli --cluster create 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 --cluster-replicas 1
Unrecognized option or bad number of args for: '--cluster'
[root@T9 redis-4.0.11]#
创建没成功。 redis-cli不支持这个命令了,可能。
看了create-cluster脚本,里边是这样的:
[root@T9 redis-4.0.11]# ./src/redis-trib.rb create --replicas 1 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005
在此之前,还需要安装:
yum install ruby
yum install rubygem-redis
上边的命令在5.0里也旧了。最新的写法是这样的(所以上边那两个ruby,其实也可以不装):
redis-cli --cluster create \
> 192.168.2.205: 192.168.2.205: 192.168.2.205: 192.168.2.205: 192.168.2.205: 192.168.2.205: \
> --cluster-replicas
成功之后,master大概会打印这些东西:
:M Oct ::32.268 # configEpoch set to via CLUSTER SET-CONFIG-EPOCH
:M Oct ::32.284 # IP address for this node updated to 127.0.0.1
:M Oct ::37.224 # Cluster state changed: ok
:M Oct ::37.551 * Slave 127.0.0.1: asks for synchronization
:M Oct ::37.551 * Partial resynchronization not accepted: Replication ID mismatch (Slave asked for '333d735fee630925f6cb26009980da7c036c1be1', my replication IDs are '0afc41e9ed8a0e316dbca9051ffa1c4bdcbab8dd' and '')
:M Oct ::37.551 * Starting BGSAVE for SYNC with target: disk
:M Oct ::37.553 * Background saving started by pid
:C Oct ::37.899 * DB saved on disk
:C Oct ::37.902 * RDB: MB of memory used by copy-on-write
:M Oct ::37.980 * Background saving terminated with success
:M Oct ::37.981 * Synchronization with slave 127.0.0.1: succeeded
slave会打印这些:
:M Oct ::32.269 # configEpoch set to via CLUSTER SET-CONFIG-EPOCH
:M Oct ::32.292 # IP address for this node updated to 127.0.0.1
:S Oct ::36.989 * Before turning into a slave, using my master parameters to synthesize a cached master: I may be able to synchronize with the new master with just a partial transfer.
:S Oct ::36.989 # Cluster state changed: ok
:S Oct ::37.548 * Connecting to MASTER 127.0.0.1:
:S Oct ::37.548 * MASTER <-> SLAVE sync started
:S Oct ::37.548 * Non blocking connect for SYNC fired the event.
:S Oct ::37.549 * Master replied to PING, replication can continue...
:S Oct ::37.550 * Trying a partial resynchronization (request 333d735fee630925f6cb26009980da7c036c1be1:).
:S Oct ::37.900 * Full resync from master: 28607c280e263eaefb803cc88f213822187e903f:
:S Oct ::37.900 * Discarding previously cached master state.
:S Oct ::37.981 * MASTER <-> SLAVE sync: receiving bytes from master
:S Oct ::37.982 * MASTER <-> SLAVE sync: Flushing old data
:S Oct ::38.008 * MASTER <-> SLAVE sync: Loading DB in memory
:S Oct ::38.008 * MASTER <-> SLAVE sync: Finished with success
:S Oct ::38.012 * Background append only file rewriting started by pid
:S Oct ::38.302 * AOF rewrite child asks to stop sending diffs.
:C Oct ::38.302 * Parent agreed to stop sending diffs. Finalizing AOF...
:C Oct ::38.302 * Concatenating 0.00 MB of AOF diff received from parent.
:C Oct ::38.303 * SYNC append only file rewrite performed
:C Oct ::38.304 * AOF rewrite: MB of memory used by copy-on-write
:S Oct ::38.330 * Background AOF rewrite terminated with success
:S Oct ::38.330 * Residual parent diff successfully flushed to the rewritten AOF (0.00 MB)
:S Oct ::38.331 * Background AOF rewrite finished successfully
脚本最后会打印这个:
[OK] All slots covered
杀掉一个master
它的slave会升成master
:S Oct ::11.497 # Error condition on socket for SYNC: Connection refused
:S Oct ::11.604 # Failover election won: I'm the new master.
:S Oct ::11.605 # configEpoch set to after successful failover
:M Oct ::11.605 # Setting secondary replication ID to a7bc292355042d4c2344f8a84503a418775018f0, valid up to offset: . New replication ID is 1ac1b3a40de43eb7012840543e9e50200a948334
:M Oct ::11.605 * Discarding previously cached master state.
:M Oct ::11.605 # Cluster state changed: ok
再启动这个master,它会变成slave
再杀掉新的master,slave又会变回成master。
5. shutdown
[root@T9 redis-4.0.]# ./src/redis-cli -p shutdown nosave
[root@T9 redis-4.0.]# ./src/redis-cli -p shutdown nosave
[root@T9 redis-4.0.]# ./src/redis-cli -p shutdown nosave
[root@T9 redis-4.0.]# ./src/redis-cli -p shutdown nosave
[root@T9 redis-4.0.]# ./src/redis-cli -p shutdown nosave
[root@T9 redis-4.0.]# ./src/redis-cli -p shutdown nosave
使用脚本创建 redis cluster
脚本:
utils/create-cluster/create-cluster
启动:
[root@T9 create-cluster]# ./create-cluster start
[root@T9 create-cluster]# ./create-cluster create
[root@T9 create-cluster]# ./create-cluster stop
使用:与非cluster的区别是使用-c参数。
[root@T9 create-cluster]# ../../src/redis-cli -c -p
gossip协议
https://www.jianshu.com/p/133560ef28df
其他
为什么redis cluster最小需要6个node?
redis cluster tutorial中写道:
Note that the minimal cluster that works as expected requires to contain at least three master nodes. For your first tests it is strongly suggested to start a six nodes cluster with three masters and three slaves.
用四个节点(2 master,2 slave)测试失败,错误信息如下:
[root@T9 -redis]# ./redis-4.0./src/redis-trib.rb create --replicas 127.0.0.1: 127.0.0.1: 127.0.0.1: 127.0.0.1:
>>> Creating cluster
*** ERROR: Invalid configuration for cluster creation.
*** Redis Cluster requires at least master nodes.
*** This is not possible with nodes and replicas per node.
*** At least nodes are required.
[root@T9 -redis]#
可能是为了防止脑裂吧? https://grokbase.com/t/gg/redis-db/15cbatbypm/why-a-minimal-cluster-should-require-at-least-three-master-nodes
用sentinel也是同理最少需要三个。
在sentinel文档里看见的一句话,应该是可以简单的解释了这个问题:
Note that we will never show setups where just two Sentinels are used, since Sentinels always need to talk with the majority in order to start a failover.
另外,redis部署了集群的话,就不需要部署哨兵了。
Cluster is only for when you need sharding.
If you only want replication + failover use Sentinel (though you still
need hosts for the Sentinels)
[redis] redis的更多相关文章
- [redis] Redis 配置文件置参数详解
################################ 基础配置 ################################# #daemonize no 默认情况下, redis 不 ...
- ServiceStack.Redis——Redis于.net向上client解
ServiceStack.Redis--Redis于.net向上client解 源代码和使用: https://github.com/ServiceStack/ServiceStack.Redis 样 ...
- Redis --> Redis的接口介绍及使用
Redis的接口介绍及使用 Redis是一个远程内存数据库,它不仅性能强劲,而且还具有复制特性以及为解决问题而生的独一无二的数据模型.Redis提供了5种不同类型的数据结构,各式各样的问题都可以很自然 ...
- redis.Redis与redis.StrictRedis区别
redis-py提供两个类Redis和StrictRedis用于实现Redis的命令,StrictRedis用于实现大部分官方的命令,并使用官方的语法和命令(比如,SET命令对应与StrictRedi ...
- Windows下Redis缓存服务器的使用 .NET StackExchange.Redis Redis Desktop Manager 转发非原创
Windows下Redis缓存服务器的使用 .NET StackExchange.Redis Redis Desktop Manager Redis缓存服务器是一款key/value数据库,读11 ...
- linux上面是否有安装redis,redis启动
1.进入/usr/local/src目录,下载redis # cd /usr/local/src# wget http://download.redis.io/releases/redis-4.0.6 ...
- [Redis] redis在centos下安装测试
下载软件,使用命令wget xxx,参数:url 例如: wget http://download.redis.io/releases/redis-3.0.0.tar.gz 解压缩,使用命令tar,参 ...
- [Redis] - redis实战
Microsoft Windows [版本 10.0.17134.472] (c) Microsoft Corporation.保留所有权利. C:\Users\SeeClanUkyo>f: F ...
- 查看linux上面是否有安装redis,redis启动
1.检测是否有安装redis-cli和redis-server; [root@localhost bin]# whereis redis-cli redis-cli: /usr/bin/redis-c ...
- [redis] redis配置文件redis.conf的详细说明
# Redis 配置文件 # 当配置中需要配置内存大小时,可以使用 1k, 5GB, 4M 等类似的格式,其转换方式如下(不区分大小写) # # 1k => bytes # 1kb => ...
随机推荐
- (原)faster rcnn的tensorflow代码的理解
转载请注明出处: https://www.cnblogs.com/darkknightzh/p/10043864.html 参考网址: 论文:https://arxiv.org/abs/1506.01 ...
- MySQL技术内幕读书笔记(七)——锁
锁 锁是数据库系统区分与文件系统的一个关键特性.为了保证数据一致性,必须有锁的介入.数据库系统使用锁是为了支持对共享资源进行并发访问,提供数据的完整性和一致性. lock与latch 使用命令 ...
- Nop--NopCommerce源码架构详解专题目录
最近在研究外国优秀的ASP.NET mvc电子商务网站系统NopCommerce源码架构.这个系统无论是代码组织结构.思想及分层都值得我们学习.对于没有一定开发经验的人要完全搞懂这个源码还是有一定的难 ...
- 【C++】C++中的流
目录结构: contents structure [-] 1.IO类 IO对象无拷贝状态 条件状态 文件流 文件模式 string流 1.IO类 除了istream和ostream之外,标准库还定义了 ...
- 【PHP】解析PHP中的函数
目录结构: contents structure [-] 可变参数的函数 变量函数 回调函数 自定义函数库 闭包(Closure)函数的使用 在这篇文章中,笔者将会讲解如何使用PHP中的函数,PHP是 ...
- Asp.Net MVC上传图片
mvc上传图片 [HttpPost] public JsonResult Upload() { ) { ) { HttpPostedFileBase file = Request.Files[]; ) ...
- [Linux]linux下取消用户名和密码直接登录
假定目前只有root用户,则有如下两种方式可直接登录系统: 方式一: 1. passwd -d root 2. 修改/lib/systemd/system/serial-getty\@.service ...
- 字符集之在UTF-8中,一个汉字为什么需要三个字节?
(一)在UTF-8中,一个汉字为什么需要三个字节? UNICODE是万能编码,包含了所有符号的编码,它规定了所有符号在计算机底层的二进制的表示顺序.有关Unicode为什么会出现就不叙述了,Unico ...
- SAP Parallel Accounting(平行分类账)业务配置及操作手册
目录 SAP Parallel Accounting(平行分类账业务)配置及操作手册 SAP Parallel Accounting(平行分类账业务)配置及操作手册 Overview 业务说明 为了适 ...
- C++中常用的std标准容器
从c++11标准以来,c++中std定义的几种容器的效率非常高,优化的非常好,完全没有必要自己去定义类似的数据结构.了解使用它们,可以满足90%的日常编程需要.该篇文章基于c++11标准,从用户角度来 ...