lettuce
1 | <dependency> |
standalone properties
1 | ## redis |
cluster properties
- code
1
2spring.redis.cluster.nodes=192.168.50.28:6379,192.168.50.28:6381,192.168.50.28:6383
spring.redis.cluster.max-redirects=3测试
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
public class SimpleService {
static Logger logger = LoggerFactory.getLogger(SimpleService.class) ;
StringRedisTemplate stringRedisTemplate ;
public void run(){
logger.info("redis连接工厂:{}",stringRedisTemplate.getConnectionFactory());
//添加key
stringRedisTemplate.opsForValue().set("user","张三");
//获取key
logger.info("从redis中获取key=user的值为:{}",stringRedisTemplate.opsForValue().get("user"));
//删除key
stringRedisTemplate.delete("user");
}
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33import java.util.Locale;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.actuate.autoconfigure.metrics.MeterRegistryCustomizer;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import com.example.summermetrics.service.SimpleService;
import io.micrometer.core.instrument.MeterRegistry;
public class SummerMetricsApplication {
static {
Locale.setDefault(Locale.CHINA);
}
public static void main(String[] args) {
// SpringApplication.run(SummerMetricsApplication.class, args);
ApplicationContext ctx = SpringApplication.run(SummerMetricsApplication.class, args);
SimpleService simpleService = ctx.getBean(SimpleService.class) ;
simpleService.run();
}
MeterRegistryCustomizer<MeterRegistry> configurer(
{ String applicationName)
return (registry) -> registry.config().commonTags("application", applicationName);
}
}参考文章
- Spring boot - data-redis与jedis关系