tp5.0 combined with Redis cache caching storm

Source: Internet
Author: User
Tags delete key ticket

Method Introduction

1.sadd ()

Description: Adds a value to a key. If this value is already in this key, it returns false. Parameter: Key value return value: Successful return true, failed false 2.delete ()Description: Delete the specified key parameter: A key, or an indeterminate number of arguments, for each key array: Key1 key2 Key3 ... keyn return value: Number of items deleted
    Private Function Getjsapiticket () {//==================author D xx start=================//1. Cache Wx Jsapiticket if (! $jsapiTicket = Cache::get (' Wxjsapiticket ')) {if (Cache::init ()->handler ()->sadd (                ' Wxjsapistorm ', ' 11 ') {//1.1 gets accesstoken $accessToken = $this->getaccesstoken (); 1.2 Request $url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi&access_token=                {$accessToken} ";                $res = file_get_contents ($url);                Trace ($res);                $res = Json_decode ($res);                $jsapiTicket = $res->ticket;                if (Isset ($jsapiTicket)) {//Cache Cache::set (' Wxjsapiticket ', $jsapiTicket, 7000);            }//Delete key Cache::init ()->handler ()->delete (' Wxjsapistorm ');                } else {sleep (1);  $this->getjsapiticket ();          }} return $jsapiTicket; ==================author D xx end=================}

tp5.0 combined with Redis cache caching Storm

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.