search
Homephp教程php手册Redis抢票先进先出

Redis+Thinkphp=》抢票 1超大流量的抢票(比如地铁,限时抢购这样的) 数据千万不要往数据库存储;数据库容易发生崩溃 抢票(1)先建一个redis存储一等奖 (2)建一个redis存储二等奖 (3)第三个redis存储单一的OpenID或者手机号,唯一编号等; 特别备注:可

Redis+Thinkphp=》抢票
1 超大流量的抢票(比如地铁,限时抢购这样的)
   数据千万不要往数据库存储 ;数据库容易发生崩溃
   抢票 (1)先建一个redis 存储一等奖
           (2)建一个redis 存储 二 等奖
           (3)第三个 redis 存储 单一的 OpenID或者手机号,唯一编号等;
          特别备注: 可以用 Set集合存储,插入重复的OpenID 返回 0 ;正确返回 插入个数1,2,3,4。。。。。
          (4)第四个 redis 存储 openid,ticketsID,返回用户 所获得的 票ID
   最后一次性到处 第四个redis记录 存储到数据库作为 记录

	/*
	 * 是否已经抢票
	*/
	public function is_fight_tickets($fightticktes,$openid){
		$where['openid'] = $openid;
		$where["telephone"] = array('exp', 'is not NULL');
		$ticketsresults = $fightticktes ->where($where) -> find();
		///判断是否已经购票 
		if(!empty($ticketsresults)){
			return $ticketsresults;
		}else{
			$allowtickets = $this->allowtickets("");
			///返回数字 或者 false
			if($allowtickets){
				////插入
			}else{
			}	
		}
	}
    //允许
    public function allowtickets($openid){
    	$Cache = Cache::getInstance('Redis');
    	$result  =$Cache->lpop("fight_tickets:ticketlist");
    	return $result;
    }
    public function createtickets(){
    	$Cache = Cache::getInstance('Redis');
    	///$hashset = "fight_tickets:";
    	for($i=10;$i<20000;$i++){
    		$Cache->rpush("fight_tickets:ticketlist",$i);
    		echo $i;
    	}

        SADD key member [member ...]
        将一个或多个 member 元素加入到集合 key 当中,已经存在于集合的 member 元素将被忽略。
        假如 key 不存在,则创建一个只包含 member 元素作成员的集合。
        当 key 不是集合类型时,返回一个错误。

        返回值:
          被添加到集合中的新元素的数量,不包括被忽略的元素。
        # 添加单个元素
        redis> SADD bbs "discuz.net"
        (integer) 1
        # 添加重复元素
        redis> SADD bbs "discuz.net"
        (integer) 0
        # 添加多个元素
        redis> SADD bbs "tianya.cn" "groups.google.com"
        (integer) 2
    	/*
    	从list 头部压入一个元素   先进后出
    	lpush mylist "word"
    	lpush mylist "ehll"
    	lrange mylist 0 -1    显示  ehll    word
    	*/
    	/*
        rpop  从list 尾部删除一个元素,并返回删除的元素
    	///rpop  mylist
    	//$times = $Cache->get($hashset);
    	//$key = "集合数据iD";
    	//$Cache->zrem($hashset,$key);*/


    }
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.