丁云鹏 1 年之前
父节点
当前提交
ee78e84e4a

+ 5 - 1
recommend-feature-service/src/main/java/com/tzld/piaoquan/recommend/feature/Application.java

@@ -2,6 +2,7 @@ package com.tzld.piaoquan.recommend.feature;
 
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.autoconfigure.data.redis.RedisReactiveAutoConfiguration;
 import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
 import org.springframework.context.annotation.ComponentScan;
 import org.springframework.context.annotation.EnableAspectJAutoProxy;
@@ -9,10 +10,13 @@ import org.springframework.context.annotation.EnableAspectJAutoProxy;
 /**
  * https://github.com/grpc-swagger/grpc-swagger/blob/master/README_CN.md
  */
-@SpringBootApplication
+@SpringBootApplication(exclude = {
+        RedisReactiveAutoConfiguration.class
+})
 @ComponentScan({
         "com.tzld.piaoquan.recommend.feature.service",
         "com.tzld.piaoquan.recommend.feature.grpcservice",
+        "com.tzld.piaoquan.recommend.feature.web",
         "com.tzld.piaoquan.recommend.feature.config"
 })
 @EnableEurekaClient

+ 19 - 0
recommend-feature-service/src/main/java/com/tzld/piaoquan/recommend/feature/config/ByteArrayRedisSerializer.java

@@ -0,0 +1,19 @@
+package com.tzld.piaoquan.recommend.feature.config;
+
+import org.springframework.data.redis.serializer.RedisSerializer;
+import org.springframework.data.redis.serializer.SerializationException;
+
+/**
+ * @author dyp
+ */
+public class ByteArrayRedisSerializer implements RedisSerializer<byte[]> {
+    @Override
+    public byte[] serialize(byte[] bytes) throws SerializationException {
+        return bytes;
+    }
+
+    @Override
+    public byte[] deserialize(byte[] bytes) throws SerializationException {
+        return bytes;
+    }
+}

+ 12 - 0
recommend-feature-service/src/main/java/com/tzld/piaoquan/recommend/feature/config/RedisTemplateConfig.java

@@ -60,4 +60,16 @@ public class RedisTemplateConfig {
         return redisTemplate;
     }
 
+    @Bean(name = "byteRedisTemplate")
+    public RedisTemplate<String, byte[]> byteRedisTemplate(@Qualifier("redisFactory") RedisConnectionFactory factory) {
+        RedisTemplate<String, byte[]> redisTemplate = new RedisTemplate<>();
+        redisTemplate.setConnectionFactory(factory);
+        // key的序列化类型 保证可读性
+        redisTemplate.setKeySerializer(new StringRedisSerializer());
+        redisTemplate.setValueSerializer(new ByteArrayRedisSerializer());
+        redisTemplate.setHashKeySerializer(new StringRedisSerializer());
+        redisTemplate.setHashValueSerializer(new ByteArrayRedisSerializer());
+        return redisTemplate;
+    }
+
 }

+ 14 - 1
recommend-feature-service/src/main/java/com/tzld/piaoquan/recommend/feature/config/TairTemplateConfig.java

@@ -43,7 +43,7 @@ public class TairTemplateConfig {
         return buildTairTemplateByString(factory);
     }
 
-    public RedisTemplate<String, String> buildTairTemplateByString(RedisConnectionFactory factory) {
+    private RedisTemplate<String, String> buildTairTemplateByString(RedisConnectionFactory factory) {
         RedisTemplate<String, String> redisTemplate = new RedisTemplate<>();
         redisTemplate.setConnectionFactory(factory);
         // key的序列化类型 保证可读性
@@ -54,4 +54,17 @@ public class TairTemplateConfig {
         return redisTemplate;
     }
 
+
+    @Bean(name = "byteTairTemplate")
+    public RedisTemplate<String, byte[]> byteRedisTemplate(@Qualifier("tairFactory") RedisConnectionFactory factory) {
+        RedisTemplate<String, byte[]> redisTemplate = new RedisTemplate<>();
+        redisTemplate.setConnectionFactory(factory);
+        // key的序列化类型 保证可读性
+        redisTemplate.setKeySerializer(new StringRedisSerializer());
+        redisTemplate.setValueSerializer(new ByteArrayRedisSerializer());
+        redisTemplate.setHashKeySerializer(new StringRedisSerializer());
+        redisTemplate.setHashValueSerializer(new ByteArrayRedisSerializer());
+        return redisTemplate;
+    }
+
 }

+ 0 - 2
recommend-feature-service/src/main/java/com/tzld/piaoquan/recommend/feature/service/AbstractFeatureService.java

@@ -46,8 +46,6 @@ public abstract class AbstractFeatureService<K, V> {
         this.emptyDataExpire = 60;
         this.defaultExpire = 7200;
         this.keyFunc = k -> String.valueOf(k);
-        this.typeToken = new TypeToken<V>() {
-        };
 
         initLocalCache(defaultMaximumSize, defaultRefreshAfterWrite, defaultExpireAfterWrite, defaultExpireAfterAccess);
     }

+ 18 - 0
recommend-feature-service/src/main/java/com/tzld/piaoquan/recommend/feature/web/HealthCheckController.java

@@ -0,0 +1,18 @@
+package com.tzld.piaoquan.recommend.feature.web;
+
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @author dyp
+ */
+@RestController
+@Slf4j
+public class HealthCheckController {
+
+    @GetMapping("/ok")
+    public String ok() {
+        return "ok";
+    }
+}

+ 1 - 1
recommend-feature-service/src/main/resources/application-dev.yml

@@ -29,7 +29,7 @@ spring:
         max-idle: 8
         min-idle: 0
   tair:
-    hostName: r-bp1ps6my7lzg8rdhwx682.redis.rds.aliyuncs.com
+    hostName: r-bp1hyi7jeuw3xf0rxh.redis.rds.aliyuncs.com
     port: 6379
     password: Wqsd@2019
     timeout: 1000

+ 1 - 1
recommend-feature-service/src/main/resources/application-pre.yml

@@ -25,7 +25,7 @@ spring:
         max-idle: 8
         min-idle: 0
   tair:
-    hostName: r-bp1ps6my7lzg8rdhwx682.redis.rds.aliyuncs.com
+    hostName: r-bp1hyi7jeuw3xf0rxh.redis.rds.aliyuncs.com
     port: 6379
     password: Wqsd@2019
     timeout: 1000

+ 1 - 1
recommend-feature-service/src/main/resources/application-prod.yml

@@ -25,7 +25,7 @@ spring:
         max-idle: 8
         min-idle: 0
   tair:
-    hostName: r-bp1ps6my7lzg8rdhwx682.redis.rds.aliyuncs.com
+    hostName: r-bp1hyi7jeuw3xf0rxh.redis.rds.aliyuncs.com
     port: 6379
     password: Wqsd@2019
     timeout: 1000

+ 1 - 1
recommend-feature-service/src/main/resources/application-test.yml

@@ -25,7 +25,7 @@ spring:
         max-idle: 8
         min-idle: 0
   tair:
-    hostName: r-bp1ps6my7lzg8rdhwx682.redis.rds.aliyuncs.com
+    hostName: r-bp1hyi7jeuw3xf0rxh.redis.rds.aliyuncs.com
     port: 6379
     password: Wqsd@2019
     timeout: 1000