Redis Brief Description:
1. What is Redis?
The Redis English name is all known as: Remote Dictionary server, which translates as a long-range dictionary server. is a cache database that is distinguished from a disk database such as (Mysql), a dictionary structure with Key-value key-value pairs.
2. What is Redis's role?
Redis, as an in-memory database, is a bit of a high-speed, for those high-frequency access to the data, buffer. The LRU mechanism used by Redis when loading the cache will persist for hotspot data and others will be eliminated.
The implementation of the LRU brief source parsing algorithm for Redis involves:
1 package Com.mysql.jdbc.util; 2 3 import java.util.LinkedHashMap; 4 import java.util.Map.Entry; 5 6 public class LRUCache extends linkedhashmap {7 private static final long serialversionuid = 1L; 8 Prote CTED int maxelements; 9 public LRUCache (int maxSize) {One super (MaxSize, 0.75F, true); this.maxelements = }14 Protected boolean removeeldestentry (Entry eldest) {return this.size () > This }18}
Note: The LRU algorithm uses the LINKEDHASHMAP implementation provided by the Java JDK
View Code
How Redis uses Java is a test case:
Configuring Pom.xml with Maven
View Code
1 <!--Redis cache-->2 <dependency>3 <groupid>redis.clients</groupid>4 <artifactid>jedis</artifactid>5 <version>${redis.clients.version}</version>6 <type>jar</type>7 <scope>compile</scope>8 </dependency>
Test flow in Window environment:
Windows Redis Edition download Environment: Https://github.com/MSOpenTech/redis
Redis has five execution programs:
Redis-server |
Server servers, need to start it |
Redis-client |
Redis Command-line Client |
Redis-benchmark |
Performance testing Tools |
Redis-check-aof/rdb |
Rdb/aof Repair Tool, AoF->appendonly File |
Start the Redis-server server, the following interface appears
Java Code Testing
1 packageCom.hbut.util; 2 3 ImportCom.google.common.collect.Maps; 4 ImportOrg.junit.Before; 5 ImportOrg.junit.Test; 6 ImportRedis.clients.jedis.Jedis; 7 ImportRedis.clients.jedis.JedisPool; 8 ImportRedis.clients.jedis.JedisPoolConfig; 9 Import java.io.*; importJAVA.UTIL.ITERATOR;12 ImportJAVA.UTIL.LIST;13 ImportJava.util.map;14/**16 * Created by Xijun.gong in 14-2-28.17 */18 public classTestredis {19 20 21Jedispool pool;22Jedis jedis;23/**25 * connection26 */27@Before28 public voidInit () {pool = new Jedispool (new Jedispoolconfig (), "localhost"); Jedis =Pool.getresource ();//jedis.auth ("*******"); Password Verification 32}33 34 35/**36 * Store string, set expiration Time 37 */38@Test39 public void Redistest () throwsinterruptedexception {jedis.set ("Google", "Entry1"), System.out.println (Jedis.get ("Google"); Jedis.expire ("Google", 3); Set Expiration Time Thread.Sleep (5000), System.out.println (Jedis.get ("Google")); 45}46/**49 * CRUD for STRING50 */51 @Test52 public void Rediscrud () {/**add**/54 jedis.set ("Key", "Google" ), System.out.println ( Jedis.get ("key" )),/**delete**/57 Jedis.del ("key" ), System.out.println (Jedis.get ("key" )); 59 /*MODIFY*/60 jedis.append ("Key", "qunar.com" ), Jedis.get System.out.println ("key" ); METHOD**/63 jedis.set ("Key", "Tencent" ), System.out.println ("key" ), and Jedis.get value Mapping key**/67 jedis.mset ("Key", "Google", "Tencent", "Qunar" ), System.out.println ("Key", " Google ")",/*for map*/71 map<string, string> user = maps.newhashmap (); User.put ("Huifeidmeng", "Qunar" ), Jedis.hmset ("User" , user), list<string> rsmap = Jedis.hmget ("User", "key" ); 75 span> System.out.println (rsmap); }78)
Redis Introductory Learning Note one