Shiro Cache to Redis management
tags (space delimited): Shiro Redis
Objective:
The following methods are only used by single-use Redis
I. Importing jars for Shiro and Redis
Jedis-2.7.3.jar
shiro-core-1.2.3.jar
shiro-ehcache-1.2.3.jar
Shiro-spring-1.2.3.jar
: This article mainly introduces a simple php Cache method using redis. if you are interested in the PHP Tutorial, please refer to it. The cache method described here is relatively simple. The following is a rough idea:
Example:
A list cache example can be cached for 1 minute because the real-time requirement of list
Problem Description
Recently we used spring cache + Redis to do caching. Under high concurrency the @cacheable annotation returns a null content. Look at the source code, in the use of annotations to get the cache, the Rediscache get method will first determine whether the key exists, and then to get the value. There's a copper leak, and when thread 1 judges tha
connections currently open
Total_connections number of connections that have been opened since the server was started
Number of connection constructs that the Connection_structures server assigns
Cmd_get get Command (gets) the total number of requests
Cmd_set set Command (save) number of total requests
Total hit times of get_hits
Get_misses Total missed Hits
Number of items deleted for evictions to get free memory (the space assigned to memcache needs to be removed from the old items to get spa
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
Poolingpublic void sharded () {Create a sharded Pool configuration objectJedispoolconfig config = new Jedispoolconfig ();Maximum number of connectionsConfig.setmaxtotal (50);Connect multiple Redis nodes, IP, and port informationlistOne of the node information is OKJedisshardinfo Info1 =New Jedisshardinfo ("192.168.27.113", 6379);Shards.add (INFO1);Create a shard PoolShardedjedispool pool =New Shardedjedispool (config, shards);Get a Jedis link from th
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
Suppose dal uses php as an example. I used to use php to operate mysql separately. Now I need to squeeze the server and consider adding a redis instance. However, I am confused about the access policies of the two data sources. I hope to help me sort it out. It is better to explain it with pseudo code. Thank you. Suppose dal uses php as an example.
I used to use php to operate mysql separately. Now I need to squeeze the server and consider adding a
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
Adding a Redis cache using Springboot needs to be introduced in the Pom fileOur support for adding the cache requires two dependencies, one for the Springboot internal cache configuration, and the other for our Redis cache.Configuring the
A: Introduction to RedisRedis is fully open source free, adheres to the BSD protocol and is a high-performance Key-value database.Redis and other Key-value cache products have the following three features:
Redis supports data persistence, which saves data in memory on disk and can be loaded again for use when restarting.
Redis not only supports simpl
.* 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
About Redis
Redis is based on memory, or can be based on disk persistence NoSQL database, using C language development.
Data storage structure: Key-value
Installation Environment Preparation
Redis is developed using the C language and needs to be compiled using the GCC compiler.
1) Installing GCC
A) Install from disk mirroring: (reboot the Linux server requires a
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
1. Who decided to take the Redis cache? Of course it's mybatis.MyBatis in the default implementation of data deletion and modification function, here to use the cache AhAnd it's mybatis. This ORM framework uses a caching mechanism, and MyBatis has a two-tier cache by default! So, you only need to configure
As soon as you join Spring-boot-starter-data-redis, Springboot automatically recognizes and uses Redis as the cache container, using the following methodsGradle Join Dependency Compile ("Org.springframework.boot:spring-boot-starter-data-redis:${springbootversion}")Enable caching in
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
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.