/*
* Copyright 2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.cluster.redis.lock;
import java.util.concurrent.locks.Lock;
import org.springframework.cloud.cluster.lock.DistributedLock;
import org.springframework.cloud.cluster.lock.LockService;
import org.springframework.cloud.cluster.lock.support.DelegatingDistributedLock;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.integration.redis.util.RedisLockRegistry;
/**
* {@link LockService} implementation based on Redis.
*
* <p>This implementation delegates to {@link RedisLockRegistry} from Spring
* Integration.
*
* @author Janne Valkealahti
*
*/
public class RedisLockService implements LockService {
public static final String DEFAULT_REGISTRY_KEY = "spring-cloud";
private final RedisLockRegistry redisLockRegistry;
/**
* Instantiates a new redis lock service.
*
* @param connectionFactory the redis connection factory
*/
public RedisLockService(RedisConnectionFactory connectionFactory) {
this(connectionFactory, DEFAULT_REGISTRY_KEY);
}
/**
* Instantiates a new redis lock service.
*
* @param connectionFactory the redis connection factory
* @param registryKey The key prefix for locks.
*/
public RedisLockService(RedisConnectionFactory connectionFactory, String registryKey) {
this.redisLockRegistry = new RedisLockRegistry(connectionFactory, registryKey);
}
/**
* Instantiates a new redis lock service.
*
* @param connectionFactory the redis connection factory
* @param expireAfter The expiration in milliseconds.
*/
public RedisLockService(RedisConnectionFactory connectionFactory, long expireAfter) {
this.redisLockRegistry = new RedisLockRegistry(connectionFactory, DEFAULT_REGISTRY_KEY, expireAfter);
}
/**
* Instantiates a new redis lock service.
*
* @param connectionFactory the redis connection factory
* @param registryKey The key prefix for locks.
* @param expireAfter The expiration in milliseconds.
*/
public RedisLockService(RedisConnectionFactory connectionFactory, String registryKey, long expireAfter) {
this.redisLockRegistry = new RedisLockRegistry(connectionFactory, registryKey, expireAfter);
}
@Override
public DistributedLock obtain(String lockKey) {
Lock lock = redisLockRegistry.obtain(lockKey);
return new DelegatingDistributedLock(lockKey, lock);
}
}
- 浏览: 4931680 次
- 性别:
- 来自: 南京
文章分类
- 全部博客 (2844)
- java (1094)
- hadoop (37)
- jvm (39)
- hbase (11)
- sql (25)
- 异常 (83)
- div css (6)
- 数据库 (95)
- 有趣的code (15)
- struts2 (6)
- spring (124)
- js (44)
- 算法 (65)
- linux (36)
- hibernate (7)
- 中间件 (78)
- 设计模式 (2)
- 架构 (275)
- 操作系统 (91)
- maven (35)
- tapestry (1)
- mybatis (9)
- MQ (101)
- zookeeper (18)
- 搜索引擎,爬虫 (208)
- 分布式计算 (45)
- c# (7)
- 抓包 (28)
- 开源框架 (45)
- 虚拟化 (12)
- mongodb (15)
- 计算机网络 (2)
- 缓存 (97)
- memcached (6)
- 分布式存储 (13)
- scala (5)
- 分词器 (24)
- spark (104)
- 工具 (23)
- netty (5)
- Mahout (6)
- neo4j (6)
- dubbo (36)
- canal (3)
- Hive (10)
- Vert.x (3)
- docker (115)
- 分布式追踪 (2)
- spring boot (5)
- 微服务 (56)
- 淘客 (5)
- mesos (67)
- php (3)
- etcd (2)
- jenkins (4)
- nginx (7)
- 区块链 (1)
- Kubernetes (92)
- 驾照 (1)
- 深度学习 (15)
- JGroups (1)
- 安全 (5)
- 测试 (16)
- 股票 (1)
- Android (2)
- 房产 (1)
- 运维 (6)
- 网关 (3)
最新评论
-
明兜3号:
部署落地+业务迁移 玩转k8s进阶与企业级实践技能(又名:Ku ...
Kubernetes系统常见运维技巧 -
q328965539:
牛掰啊 资料收集的很全面
HDFS小文件处理解决方案总结+facebook(HayStack) + 淘宝(TFS) -
guichou:
fluent挂载了/var/lib/kubelet/pods目 ...
kubernetes上部署Fluentd+Elasticsearch+kibana日志收集系统 -
xu982604405:
System.setProperty("java.r ...
jmx rmi 穿越防火墙问题及jmxmp的替代方案 -
大漠小帆:
麻烦问下,“获取每个Item相似性最高的前N个Item”,这个 ...
协同过滤推荐算法在MapReduce与Spark上实现对比
发表评论
-
Kryo 使用指南
2017-12-05 20:14 18811、Kryo 的简介 Kryo 是一个快速序列化/ ... -
spring session序列化问题排查
2017-12-01 19:07 6151严重: Servlet.service() for ser ... -
spring mvc统一异常处理(@ControllerAdvice + @ExceptionHandler)
2017-12-01 17:09 2939spring 封装了非常强大的异常处理机制。本文选取@Co ... -
springboot注解
2017-12-01 09:44 970@RestController和@RequestMappin ... -
Spring 4 xml 注解配置谅解
2017-12-01 09:39 1060《Spring in Action》4th E ... -
利用junit对springMVC的Controller进行测试
2017-11-30 16:26 1398平时对junit测试service/D ... -
Java内存模型之重排序
2017-11-29 09:44 814在执行程序时,为了提供性能,处理器和编译器常常会对指令进行重 ... -
pmd spotbugs 文档
2017-11-28 10:02 0https://pmd.github.io/pmd/pmd ... -
PMD、FindBug、checkstyle、sonar这些代码检查工具的区别?各自的侧重点是什么?
2017-11-28 10:01 2095可以说都是代码静态分析工具,但侧重点不同。pmd:基于源代码 ... -
阿里巴巴Java代码规约插件p3c-pmd使用指南与实现解析
2017-11-23 17:09 1533阿里巴巴Java代码规约插件安装 阿里Java代码规 ... -
静态分析工具PMD使用说明 (文章来源: Java Eye)
2017-11-23 17:07 1102质量是衡量一个软件是否成功的关键要素。而对于商业软件系统,尤 ... -
spring cloud config实现datasource的热部署
2017-11-21 16:44 1576关于spring cloud config的基本使用,前面的 ... -
MyBatis 使用 MyCat 实现多租户的一种简单思路
2017-11-20 18:27 2798本文的多租户是基于多数据库进行实现的,数据是通过不同数据库进 ... -
Spring+MyBatis实现数据库读写分离方案
2017-11-20 17:15 1019百度关键词:spring mybatis 多数据源 读写分离 ... -
数据库连接池druid wallfilter配置
2017-11-20 11:38 1211使用缺省配置的WallFilter <be ... -
java restful 实体封装
2017-11-16 09:47 1538package com.mogoroom.bs.commo ... -
dak
2017-11-15 11:21 0package zzm; import jodd.ht ... -
Java内存模型之从JMM角度分析DCL
2017-11-15 09:35 590DCL,即Double Check Lock,中卫双重检查锁 ... -
Java 打印堆栈的几种方法
2017-11-14 09:36 4655java 中可以通过 eclipse 等工具直接打印堆栈, ... -
Servlet Session学习
2017-11-10 09:25 503HTTP 是一种"无状 ...
相关推荐
SpringCloud整合Redis缓存;版本:SpringCloud :Dalston.SR4;SpringBoot:1.5.14.RELEASE;Redis:3.2.0;Maven :3.5.3.代码下载下来即可用
在使用代码之前,需要你配置reids集群,在百度上你可以找到
SpringBoot、SpringCloud的案例源码,以及Redis安装,并附带上高可用集群
SpringCloud+SpringBoot+OAuth2+Spring Security+Redis实现的微服务统一认证授权
SpringBoot2.0+SpringCloud+redis集群搭建的仿悦诗风吟旗舰网站 项目描述 SpringBoot2.0+SpringCloud搭建的仿悦诗风吟旗舰网站,整合了Mybatis、Redis集群、druid等技术,采用分布式架构,面向服务的思想,该项目...
spring + redis + sentinel 配置文件,同学们可以下载使用,有问题请指教。
Redis是运行在内存中,查取速度很快。本文重点给大家介绍SpringCloud实现Redis在各个微服务的Session共享,感兴趣的朋友一起看看吧
SpringBoot2.0+SpringCloud+redis集群搭建的旗舰网店网站,整合了Mybatis、Redis集群、druid等技术,采用分布式架构,面向服务的思想,该项目是自己在学习SpringBoot和SpringCloud时自己写的一个小项目,整体的功能...
spring和redis集成有很多方式,看到网上很多都是使用redistemplate自己去做redis 的一些操作,但是对于我们开发来说,肯定是使用越方便越好,于是乎就有了spring的对redis或者memcahe这些换成框架的封装,只需要引入...
Redis 是一个开源的 key-value 存储系统,由于出众的性能,大部分互联网企业都用来做服务器端缓存。Redis 支持单实例模式,集群主从模式、哨兵模式等部署
Spring Data Redis。 Spring Data Redis 开发文档。 官网 Spring Data Redis API。
在线教育平台服务端基于Spring Boot构建,采用Spring Cloud微服务框架。 持久层:MySQL、MongoDB、Redis、ElasticSearch 数据访问层:使用Spring Data JPA 、Mybatis、Spring Data Mongodb等 业务层:Spring IOC、...
NULL 博文链接:https://chentian114.iteye.com/blog/2292323
第1章 SpringCloud简介 第2章 SpringCache缓存详细讲解及应用 第3章 Redis高级缓存讲解及应用 第4章 SpringSecurity安全详细讲解及应用 第5章 RabbitMQ高级消息的讲解及应用 第6章 ElasticSearch详细讲解及应用 第7...
Spring Data Redis 纯英文文档,介绍spring操作redis的一些用法
Smart Shop是一款基于 Spring Cloud +MybatisPlus+XXL-JOB+redis+Vue的前后端分离、分布式、微服务架构的Java商城系统,采用稳定框架开发及优化核心,减少依赖,具备出色的执行效率,扩展性、稳定性高,H5/小程序/...
springcloud整合lettuce使用redis
Spring Data Redis是spring Data系列的一部分,它提供了从Spring应用程序轻松配置和访问Redis的功能。
spring整合redis项目 spring redis 下载导入eclipse即可测试
本资源提供springcloud微服务件代码, 主要有三个模块,springcloud集成es,gateway,mongdodb, 通知有基于feign调用的整套代码注解说明 能帮助大家轻易打建springcloud基于nocos配置,注册中心的微服务架构 包含了...