Giter Site home page Giter Site logo

redislock's Introduction

redislock - 基于redis的分布式可重入锁

Build Status Maven Central License

是什么

redislock 是一个基于Redis的分布式可重入锁

怎么用

maven

<dependency>
  <groupId>com.imadcn.framework</groupId>
  <artifactId>lock</artifactId>
  <version>0.0.1</version>
</dependency>

XML配置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:p="http://www.springframework.org/schema/p" xmlns:lock="http://code.imadcn.com/schema/lock"
	xsi:schemaLocation="
		http://www.springframework.org/schema/beans 
		http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/context 
		http://www.springframework.org/schema/context/spring-context.xsd
		http://code.imadcn.com/schema/lock
		http://code.imadcn.com/schema/lock/lock.xsd">
		
	<!-- redis pool -->
	<bean id="jedisPoolConfig" class="redis.clients.jedis.JedisPoolConfig">
		<property name="testOnBorrow" value="false" />
		<property name="testOnReturn" value="true" />
	</bean>

	<!-- redis sentinel -->
	<bean id="redisSentinelConfig" class="com.imadcn.framework.lock.config.RedisSentinelConfig">
		<property name="masterName" value="mymaster" />
		<property name="sentinelAddrs" value="127.0.0.1:26380,127.0.0.1:26381,127.0.0.1:26382" />
	</bean>

	<!-- redis connectionFactory -->
	<bean id="connectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" destroy-method="destroy">
		<constructor-arg index="0" ref="redisSentinelConfig" />
		<constructor-arg index="1" ref="jedisPoolConfig" />
	</bean>

	<bean id="stringRedisSerializer" class="org.springframework.data.redis.serializer.StringRedisSerializer" />
	<bean id="jdkSerializationRedisSerializer" class="org.springframework.data.redis.serializer.JdkSerializationRedisSerializer" />

	<!-- redisTemplate -->
	<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
		<property name="connectionFactory" ref="connectionFactory" />
		<property name="keySerializer" ref="stringRedisSerializer" />
		<property name="valueSerializer" ref="stringRedisSerializer" />
		<property name="hashKeySerializer" ref="stringRedisSerializer" />
		<property name="hashValueSerializer" ref="stringRedisSerializer" />
		<property name="stringSerializer" ref="stringRedisSerializer" />
	</bean>
	
	<!-- redisMessageListenerContainer -->
	<bean id="redisMessageListenerContainer" class="org.springframework.data.redis.listener.RedisMessageListenerContainer">
		<property name="connectionFactory" ref="connectionFactory" />
		<property name="topicSerializer" ref="stringRedisSerializer" />
	</bean>
	
	<lock:config id="lockManager" group="physical-exam" redisTemplate="redisTemplate" messageContainer="redisMessageListenerContainer"/>
</beans>

API

@Autowired
private RedisLockManager manager;

public void lock() {
	RedisLock redisLock = manager.getLock("asd");
	redisLock.lock();
	redisLock.unlock();
} 

配置参考

<redislock:config /> redislock 配置

属性 类型 必填 缺省值 描述
id String Spring容器中的ID
group String 分组名,可以为不同业务分配分组
redisTemplate String redisTemplate
messageContainer String RedisMessageListenerContainer

redislock's People

Contributors

imadcn avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.