Talking about the application of Redis in the project _redis

Source: Internet
Author: User
Tags delete key redis

Redis applications in projects ps:php automatically turn off Redis connections do not require manual shutdown for temporary data can be redis directly from the database

/* Message Queuing instance/Public function Insertinfo () {//connection local Redis service $redis = new \redis ();
    $redis->connect (' 127.0.0.1 ', 6379);
    Store data into the list $infos = Array (' Info1 ' =>, ' Info2 ' => 88);

    $redis->lpush ($key, Json_encode ($infos));
    Gets the stored data and outputs the $arList = $redis->lrange ("Tutorial-list", 0, 30);
    Print_r ($arList);
	Exit ();
		/* Read instance//Public function GetInfo () {//Connect local Redis Service $redis = new \redis ();

		$redis->connect (' 127.0.0.1 ', 6379);

		Gets the stored data and outputs $result = Json_decode ($redis->get ("Tutoriallist"), ' true ';
			if (empty ($result)) {$sql = "select * from Mobantestinfo";
			$VModel = new Huanshanvotemodel ();
			$result = $VModel->query ($sql);
		Re-put the cache into the database Redis cannot directly save the array needs to be converted to JSON $redis->set (Json_encode ($result));
			}else{//Connect the local Redis service $redis = new \redis ();
			$redis->connect (' 127.0.0.1 ', 6379);
		Gets the stored data and outputs $result = Json_decode ($redis->get ("Tutoriallist"), ' true ';
		} print_r ($result); Exit (); }
/* Update instance *

	/Public Function Updateinfo () {


		//Run SQL statement
		$sql = "Update mobantestinfo set info1=1 where id=40";
		$VModel = new Huanshanvotemodel ();
		$isOk = $VModel->execute ($sql);

		Connect the local Redis service
		$redis = new \redis ();
		$redis->connect (' 127.0.0.1 ', 6379);
		/* Delete key*/
		$redis->del (' tutoriallist ');
	}
/* Delete instance *

	/Public Function Deleteinfo () {


		//Run SQL statement
		$sql = "Delete from mobantestinfo where id=40";
		$VModel = new Huanshanvotemodel ();
		$isOk = $VModel->execute ($sql);

		Connect the local Redis service
		$redis = new \redis ();
		$redis->connect (' 127.0.0.1 ', 6379);
		$redis->del (' tutoriallist ');
	}

The above is small series for everyone to bring the Redis in the project application of all content, I hope that we support cloud-Habitat Community ~

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.