Home  >  Article  >  php教程  >  redis optimistic lock practice flash sale

redis optimistic lock practice flash sale

高洛峰
高洛峰Original
2016-11-22 17:51:112537browse

Demand: There is a bid (it can be understood as grabbing red envelopes, the accountBalance is pre-assigned 1,000 yuan), and everyone can snap up it. After each user succeeds in snapping up, the total number of the last bid will be updated. In the case of concurrency, redis's optimistic lock is used to ensure updates. To check the correctness of the total bid value, first put a bid amount into redis:

set accountBalance "1000"

The implementation method is as follows:

pom. bid.jsp


	4.0.0

	mybatisPage
	page
	1.0-SNAPSHOT
	war

	PageHelperSample
	http://git.oschina.net/free/Mybatis-Sample

	
		UTF-8
	

	
		
		
			jstl
			jstl
			1.1.2
		
		
			taglibs
			standard
			1.1.2
		
		
		
			commons-pool
			commons-pool
			1.6
		

		
		
			org.slf4j
			slf4j-log4j12
			1.7.5
		
		
			org.slf4j
			slf4j-api
			1.7.5
		
		

		
		
			com.alibaba
			fastjson
			1.2.5
		
		
			com.alibaba
			fastjson
			1.2.4
		
		
		
			javax.servlet
			servlet-api
			2.5
			provided
		
		
			javax.servlet.jsp
			jsp-api
			2.1
			provided
		
		
			taglibs
			standard
			1.1.2
		
		
			javax.servlet
			jstl
			1.2
		

		
			com.github.pagehelper
			pagehelper
			3.7.4
		
		
			com.github.jsqlparser
			jsqlparser
			0.9.1
		

		
			junit
			junit
			4.11
			test
		
		
			log4j
			log4j
			1.2.17
		
		
			org.mybatis
			mybatis
			3.2.5
		
		
		
			org.apache.commons
			commons-lang3
			3.1
		
		
		
			mysql
			mysql-connector-java
			5.1.35
		
		
		
			redis.clients
			jedis
			2.1.0
			jar
		
	
	
		
			
				org.apache.maven.plugins
				maven-compiler-plugin
				
					1.6
					1.6
					utf-8
				
			
			
				org.mortbay.jetty
				jetty-maven-plugin
				8.0.0.M3
			
		
	

list.jsp


	
		index.jsp
	
	
	
		bid
		com.heli.mybatis.page.servlet.ReidsMatchServlet
	
	
		bid
		/bid
	
	
		list
		com.heli.mybatis.page.servlet.ReidsMatchListServlet
	
	
		list
		/list
	

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn