Redis is used as the cache in the Spring boot project.Create a spring boot maven project to add dependencies in Pom.xml Dependency> groupId>Org.springframework.bootgroupId> Artifactid>Spring-boot-starter-webArtifactid> version>1.5.3.RELEASEversion> Dependency> Dependency> groupId>Org.springframework.bootgroupId> Artifactid>Spring-bo
500ms, when the small white realized that the program needs to be optimized.This time the small white teacher came, the teacher said, these articles list data, in a short period will not change too big, why not to cache it up? This can be removed from memory every time, without having to access the database every time.The project architecture is made up of the simplestAdded the cache layer:In this way, the
The caching method described here is relatively simple, the following is the approximate idea :Example:A list cache example, because the list data real-time requirements are not high, can be cached for 1 minutes.Approximate idea:According to the URL of the request to determine:1. The requested URL hash is recorded in Redis and the data in Redis is returned direct
a previous essay-- Redis installation and master-slave configuration have been described in detail for redis installation in configuration. This article is about how to quickly create a new Redis cache database on a machine that already has Redis installed.I. Introduction to
roledao.getrole (ID);
}
The application.properties configuration file is as follows
#redis------start-------
spring.redis.hostname=127.0.0.1
spring.redis.port=63791
spring.redis.timeout=1000
spring.redis.maxidle=10
spring.redis.maxwaitmillis=15000
Spring.redis.testonborrow=true
Spring.redis.testwhileidle=false
The Ecache-shiro.xml configuration file is as follows (Shiro is used for this project, so Ehcache uses the Shiro
SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss")
. Format (New Date ()));
Thread.CurrentThread (). Sleep (5000);
}
The results are visible and expire after one minute. See Cc-redis-tow package:cached and test classesIi. comparison with memcached1. Basic parametersmemcached default port 11211 cache default Expiration Time 30 days (one term is permanent, but can not be saved after 30 days) the value stored in
1. Be sure to set the maximum cache size and set the cache policyIf you do not set the maximum cache, the Redis crashes when the new data is added, if the maximum memory is exceeded!Setting mode: MaxMemory 1GBAfter logging in using REDIS-CLI, use the Info command to view the
This article mainly introduced the PHP implementation of the Redis cache class, combined with a specific example of the PHP package for the definition and use of the Redis cache class related operation skills, the need for friends can refer to the following
Specific as follows:
Php+
Description:A Web service, the original business logic is to cache the results of the MySQL query in Redis for one hours, speeding up the response of the request. One problem now is that the response of the corresponding encoding is returned based on the specified encoding of the request.The first is to modify the response of the body encoding, because MySQL is going out is Unicode, so directly use "content
the data in the cache.
1. directly generate static files and use nginx to efficiently cache static files.
At that time, the hardware resources of the server were limited, so this method was adopted, and the source has been used till now.
Servers are shared through NFS
Too many small files, inconvenient to manage
NFS inconvenient O M and Expansion
The file content is very small (about 100 byte
This is the source of the key class Rediscache in Mybatis/redis-cache/*** Copyright The original author or authors. * Licensed under the Apache License, Version 2.0 (the "Licen Se "); * You are not a use this file except in compliance with the License. * Obtain a copy of the License at * *http://www.apache.org/licenses/LICENSE-2.0* * Unless required by applicable or agreed to writing, software * Distributed
.* Redis:* Using Ehcache:* Introduction of JAR Packages:* Introduction of configuration files: //the business layer queries all classification methods: PublicListthrowsSQLException {/** CategoryDao CategoryDao = new Categorydaoimpl (); return * Categorydao.findall (); */ /*** Query data from the cache: * * with data, directly return the cached data. * * If not, query the database and the
Some time ago, the company needed to use redis to implement the cache function. Therefore, I wrote this article to share the installation and usage skills of redis.
First, download the redisserver and execute redis-server.exe. This process must be enabled all the time. We can also download a
The caching method described here is relatively simple, the following is the approximate idea:
Example:
A list cache example, because the list data real-time requirements are not high, can be cached for 1 minutes.
Approximate idea:According to the URL of the request to determine:1. The requested URL hash is recorded in Redis and the data in Redis is returned di
Suppose the DAL uses PHP for example.
Originally using PHP alone to operate MySQL, now need to press the server, consider adding a redis, but at the same time facing the two data source access strategy generated doubts, hope to help comb.
It's better to explain it in pseudo-code, thank you.
Reply content:
Suppose the DAL uses PHP for example.
Originally using PHP alone to operate MySQL, now need to press the server, consider adding a
Environment: MySQL (database) + Redis (cache)
Scenario: List of forum posts
with pagination
Need to sort by time/heat/etc
You need to show the title and content in the list
Concurrency: Spikes may be up to tens of thousands of, but the duration may be one day, and read and write may be more frequent
Reply content:
Environment: MySQL (database) + Redis
Redis Cache Usage1. Introduction of dependencies (may have been introduced): Spring-boot-starter-cache2. Configure the Spring:redis:host/port/password in the Application.yml configuration file to connect to the Redis library3. Add annotations to the main launcher: @EnableChaching4. Add annotations to the method that requires caching:@Cacheable (cachename= "". key
, Withscores=false, score_cast_func=float) Gets the element of the ordered collection of name corresponding to the index range # 参数:# name,redis的name# start,有序集合索引起始位置(非分数)# end,有序集合索引结束位置(非分数)# desc,排序规则,默认按照分数从小到大排序# withscores,是否获取元素的分数,默认只获取元素的值# score_cast_func,对分数进行数据转换的函数6) Zrank (name, value) gets the rank of a value in the ordered set of name (starting from 0) 7) zrem (name, values) removes the value of the ordered collection of name corre
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.