Redis

Seata-AT 如何保证分布式事务一致性

僤鯓⒐⒋嵵緔 提交于 2020-12-29 07:32:53
作者 | 陈健斌(funkye) github id: a364176773 来源| 阿里巴巴云原生公众号 Seata 是一款开源的分布式事务解决方案,star 高达 18100+,社区活跃度极高,致力于在微服务架构下提供高性能和简单易用的分布式事务服务,本文将剖析 Seata-AT 的实现原理,让用户对 AT 模式有更深入的认识。 Seata 事务模式是什么? 1. Seata 对事务的定义 Seata 定义了全局事务的框架。 全局事务定义为若干分支事务的整体协调: TM 向 TC 请求发起(Begin)、提交(Commit)、回滚(Rollback)全局事务。 TM 把代表全局事务的 XID 绑定到分支事务上。 RM 向 TC 注册,把分支事务关联到 XID 代表的全局事务中。 RM 把分支事务的执行结果上报给 TC。(可选) TC 发送分支提交(Branch Commit)或分支回滚(Branch Rollback)命令给 RM。 Seata 的全局事务处理过程,分为两个阶段: 执行阶段 > :执行分支事务,并保证执行结果满足是可回滚的(Rollbackable)和持久化的(Durable)。 完成阶段 > :根据执行阶段结果形成的决议,应用通过 TM 发出的全局提交或回滚的请求给 TC,> TC 命令 RM 驱动 分支事务 进行 Commit 或 Rollback。

using Async inside a transaction in Spring application

别等时光非礼了梦想. 提交于 2020-12-29 04:59:59
问题 I have a Spring application which updates particular entity details in MySQL DB using a @Transactional method, And within the same method, I am trying to call another endpoint using @Async which is one more Spring application which reads the same entity from MySql DB and updates the value in redis storage. Now the problem is, every time I update some value for the entity, sometimes its updated in redis and sometimes it's not. When I tried to debug I found that sometimes the second application

using Async inside a transaction in Spring application

狂风中的少年 提交于 2020-12-29 04:58:16
问题 I have a Spring application which updates particular entity details in MySQL DB using a @Transactional method, And within the same method, I am trying to call another endpoint using @Async which is one more Spring application which reads the same entity from MySql DB and updates the value in redis storage. Now the problem is, every time I update some value for the entity, sometimes its updated in redis and sometimes it's not. When I tried to debug I found that sometimes the second application

使用可视化工具redisclient连接redis

一笑奈何 提交于 2020-12-29 03:10:37
可视化工具推荐:http://database.51cto.com/art/201505/477692.htm 1.连接redis服务端    1.1 设置连接密码 :在redis根目录下,双击redis-cli.exe, 输入命令:redis-cli.exe -h 127.0.0.1 -p 6379 -n 1 1就是密码 1.2 使用redisClient连接redis 连接后如图: 2.使用RedisClient 2.1 2.2:使用控制台 在控制台输入redis命令 来源: oschina 链接: https://my.oschina.net/u/4262399/blog/3969451

windows下redis可视化客户端redisClient与命令redis_cli的安装

寵の児 提交于 2020-12-29 02:33:54
一、 Window 下安装 下载地址: https://github.com/MSOpenTech/redis/releases 。 Redis 支持 32 位和 64 位。这个需要根据你系统平台的实际情况选择,这里我们下载 Redis-x64-xxx.zip压缩包到 C 盘,解压后,将文件夹重新命名为 redis。 运行服务端 这时候另启一个cmd窗口,原来的不要关闭,不然就无法访问服务端了。 切换到redis目录下运行 redis-cli.exe 。 C:\redis>redis-cli.exe 127.0.0.1:6379> ping PONG 以上说明我们已经成功安装了redis。 二、重启 考虑到redis有可能正在将内存中的数据同步到硬盘中,强行终止redis进程有可能导致数据丢失,正确停止redis的方式应该是向redis发送shutdown命令,通过客户端来关闭redis服务端。方法为: C:\redis>redis-cli.exe 127.0.0.1:6379> shutdown Not connected 当redis收到shutdown命令后,会断开所有的客户端连接,然后根据配置执行持久化,最后退出。 [17796] 15 May 14:53:18.771 # User requested shutdown... [17796] 15 May 14:53:18

爬虫mysql,redis重新连接和关闭连接

跟風遠走 提交于 2020-12-29 02:33:26
报错 pymysql.err.InterfaceError: (0, '') 在python 的多线程里 同时使用一个MySQL链接导致的---- 要把mysql数据库连接放入函数中! #使用多线程等,切忌 全局变量 conn="127.0.0.1", user="root",password="123", database="future", charset="utf8") cur = conn.cursor() #在执行sql前插入下行代码------ 实现断开自动重连 conn.ping(reconnect=True) #ping是否连接,如果没有连接会重新连接数据库 sql = ' INSERT INTO 表 VALUES (NULL,数据) ' cur.execute(sql) conn.commit() python 关闭 redis连接对象 import redis r = redis.Redis() #因为redis没有关闭具体某一个对象 以下是关闭连接池中一个 r.connection_pool.disconnect() #如果使用多线程,创建redis对象放入函数中 #redis连接数会暴增,时间过长会卡断报错程序,无法新的redis连接 #解决方法 # 1.redis修改连接最大数量 #redis客户端 #查看连接数量 info clients

第七章Redis Cluster 核心技术

穿精又带淫゛_ 提交于 2020-12-29 00:39:31
第七章· Redis Cluster 核心技术 阅读目录(Content) 一、Redis Cluster 分布式集群 1.什么是Redis Cluster 2.Redis Cluster的特点 3.Redis Cluster客户端连接任意节点 4.redis集群数据共享(设计理念) 5.Redis Cluster运行机制 6.Redis Cluster如何做集群复制 7.Redis Cluster故障转移 8.Redis Cluster中执行命令的两种情况 二、Redis Cluster 安装部署 1.部署Redis Cluster 三、Redis Cluster 集群管理操作(核心) 1.如何添加Redis Cluster节点 2.添加节点 3.扩展槽位,添加主节点 4.扩展槽位,添加从节点 5.删除节点 回到顶部(go to top) 一、Redis Cluster 分布式集群 1.什么是Redis Cluster 1)Redis集群是一个可以在多个Redis节点之间进行数据共享的设施(installation)。 2)Redis集群不支持那些需要同时处理多个键的Redis命令,因为执行这些命令需要在多个Redis节点之间移动数据,并且在高负载的情况下,这些命令将降低Redis集群的性能,并导致不可预测的行为。 3)Redis集群通过分区(partition

Linux下源码安装redis,编译安装

两盒软妹~` 提交于 2020-12-29 00:23:55
#1.下载redis源码 [root@localhost opt]# wget http://download.redis.io/releases/redis-4.0.10.tar.gz #2.解压缩 [root@localhost opt]# tar -zxf redis-4.0.10.tar.gz #3.切换redis源码目录 [root@localhost opt]# cd redis-4.0.10 #4.编译源文件 [root@localhost redis-4.0.10]# make #5.编译好后,src/目录下有编译好的redis指令 # redis可执行文件 ./redis-benchmark #用于进行redis性能测试的工具 ./redis-check-dump #用于修复出问题的dump.rdb文件 ./redis-cli #redis的客户端 ./redis-server #redis的服务端 ./redis-check-aof #用于修复出问题的AOF文件 ./redis-sentinel #用于集群管理 #6.make install 安装到指定目录,默认在/usr/local/bin #7.启动redis服务端 [root@localhost src]# ./redis-server ../redis.conf # 默认情况下,redis

Redis的五种数据结构的内部编码

戏子无情 提交于 2020-12-28 23:39:34
实际上每种数据结构都有自己底层的内部编码实现,而且是多种实现,这样Redis会在合适的场景选择合适的内部编码。 可以看到 每种数据结构都有两种以上的内部编码实现 ,例如string数据结构就包含了raw、int和embstr三种内部编码。 同时, 有些内部编码可以作为多种外部数据结构的内部实现 ,例如ziplist就是hash、list和zset共有的内部编码。 我们可以通过object encoding命令查询内部编码: 127.0.0.1:6379> set set:1 hello OK 127.0.0.1:6379> object encoding set:1 "embstr" 127.0.0.1:6379> hset user:1 name kebi (integer) 1 127.0.0.1:6379> object encoding user:1 "ziplist" Redis会根据当前值的类型和长度决定使用内部编码实现,Redis这样设计有两个好处: 第一, 可以改进内部编码 ,而对外的数据结构和命令没有影响,这样一旦开发开发出优秀的内部编码,无需改动外部数据结构和命令。 第二, 多种内部编码实现可以在不同场景下发挥各自的优势 。例如ziplist比较节省内存,但是在列表元素比较多的情况下,性能会有所下降,  

Redis内部编码

廉价感情. 提交于 2020-12-28 23:10:21
如果想查看一个键的内部编码 方式可以使用 OBJECT ENCODING 命令 typedef struct redisObject { // 类型 unsigned type:4; // 编码 unsigned encoding:4; // 对象最后一次被访问的时间 unsigned lru:REDIS_LRU_BITS; /* lru time (relative to server.lruclock) */ // 引用计数 int refcount; // 指向实际值的指针 void *ptr; } robj; /* Object types */ #define REDIS_STRING 0 #define REDIS_LIST 1 #define REDIS_SET 2 #define REDIS_ZSET 3 #define REDIS_HASH 4 #define REDIS_ENCODING_RAW 0 /* Raw representation */ #define REDIS_ENCODING_INT 1 /* Encoded as integer */ #define REDIS_ENCODING_HT 2 /* Encoded as hash table */ #define REDIS_ENCODING_ZIPMAP 3 /* Encoded as