<?xml version="1.0" encoding="UTF-8"?> 
< projectxmlns = " http://maven.apache.org/POM/4.0.0" xmlns: xsi= " http://www.w3.org/2001/XMLSchema-instance" xsi: schemaLocation= " http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" > < modelVersion> </ modelVersion> < parent> < groupId> </ groupId> < artifactId> </ artifactId> < version> </ version> < relativePath/> </ parent> < groupId> </ groupId> < artifactId> </ artifactId> < version> </ version> < name> </ name> < description> </ description> < properties> < java.version> </ java.version> </ properties> < dependencies> < dependency> < groupId> </ groupId> < artifactId> </ artifactId> </ dependency> < dependency> < groupId> </ groupId> < artifactId> </ artifactId> < scope> </ scope> </ dependency> < dependency> < groupId> </ groupId> < artifactId> </ artifactId> < version> </ version> </ dependency> </ dependencies> < build> < plugins> < plugin> < groupId> </ groupId> < artifactId> </ artifactId> </ plugin> </ plugins> </ build> </ project> spring.redis.host=127.0.0.1
spring.redis.database=0
spring.redis.port=6379
spring.redis.timeout=5000
package  com. example. springbootjedis. config ; 
import  org. springframework. boot. context. properties.  ConfigurationProperties ; 
import  org. springframework. context. annotation.  Bean ; 
import  org. springframework. stereotype.  Component ; 
import  redis. clients. jedis.  JedisPool ; 
import  redis. clients. jedis.  JedisPoolConfig ; 
@Component 
@ConfigurationProperties ( prefix =  "spring.redis" ) 
public  class  RedisConfig  { 
    private  String  host; 
    private  int  port; 
    private  int  timeout; 
    public  String  getHost ( )  { 
        return  host; 
    } 
    public  void  setHost ( String  host)  { 
        this . host =  host; 
    } 
    public  int  getPort ( )  { 
        return  port; 
    } 
    public  void  setPort ( int  port)  { 
        this . port =  port; 
    } 
    public  int  getTimeout ( )  { 
        return  timeout; 
    } 
    public  void  setTimeout ( int  timeout)  { 
        this . timeout =  timeout; 
    } 
    @Bean 
    public  JedisPool  redisPoolFactory ( )  { 
        JedisPoolConfig  jedisPoolConfig =  new  JedisPoolConfig ( ) ; 
        jedisPoolConfig. setMaxIdle ( 0 ) ; 
        jedisPoolConfig. setMaxWaitMillis ( 5000 ) ; 
        JedisPool  jedisPool =  new  JedisPool ( jedisPoolConfig,  host,  port,  timeout,  null ) ; 
        return  jedisPool; 
    } 
} 
package  com. example. springbootjedis ; 
import  org. springframework. boot.  SpringApplication ; 
import  org. springframework. boot. autoconfigure.  SpringBootApplication ; 
@SpringBootApplication 
public  class  SpringBootJedisApplication  { 
	public  static  void  main ( String [ ]  args)  { 
		SpringApplication . run ( SpringBootJedisApplication . class ,  args) ; 
	} 
} 
package  com. example. springbootjedis ; 
import  org. junit. jupiter. api.  Test ; 
import  org. springframework. beans. factory. annotation.  Autowired ; 
import  org. springframework. boot. test. context.  SpringBootTest ; 
import  redis. clients. jedis.  Jedis ; 
import  redis. clients. jedis.  JedisPool ; 
@SpringBootTest 
class  SpringBootJedisApplicationTests  { 
	@Autowired 
	private  JedisPool  jedisPool; 
	@Test 
	void  contextLoads ( )  { 
		Jedis  jedis =  jedisPool. getResource ( ) ; 
		System . out. println ( jedis) ; 
		String  keyName =  "FirstInfo" ; 
		String  fieldName =  "redisDemo" ; 
		String  str =  "hello" ; 
		jedis. hset ( keyName, fieldName,  str) ; 
		jedis. close ( ) ; 
	} 
}