Skip to content

Commit

Permalink
redis version
Browse files Browse the repository at this point in the history
  • Loading branch information
nelito committed Oct 29, 2019
1 parent d507c74 commit 92c051d
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableOAuth2Client;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
Expand All @@ -31,8 +33,21 @@ public static void main(String[] args) {
@Bean
ProjectClient projectClient(
RestOperations restOperations,
@Value("${registration.server.endpoint}") String registrationEndpoint
@Value("${registration.server.endpoint}") String registrationEndpoint, ProjectInfoRedisRepository redisRepository
) {
return new ProjectClient(restOperations, registrationEndpoint);
return new ProjectClient(restOperations, registrationEndpoint, redisRepository);
}

// @Bean
// JedisConnectionFactory jedisConnectionFactory() {
// return new JedisConnectionFactory();
// }
//
// @Bean
// public RedisTemplate<String, Object> redisTemplate() {
// RedisTemplate<String, Object> template = new RedisTemplate<>();
// template.setConnectionFactory(jedisConnectionFactory());
// return template;
// }

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.web.client.RestOperations;


import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

Expand All @@ -13,24 +12,22 @@ public class ProjectClient {
private final String endpoint;
private ConcurrentMap<Long, ProjectInfo> projectInfoCache = new ConcurrentHashMap<>();

// private Jedis jedis = new Jedis();


private ProjectInfoRedisRepository redisRepository;


public ProjectClient(RestOperations restOperations, String registrationServerEndpoint) {
public ProjectClient(RestOperations restOperations, String registrationServerEndpoint, ProjectInfoRedisRepository redisRepository) {
this.restOperations = restOperations;
this.endpoint = registrationServerEndpoint;
this.redisRepository = redisRepository;
}

@HystrixCommand(fallbackMethod = "getProjectFromCache")
public ProjectInfo getProject(long projectId) {
ProjectInfo projectInfo = restOperations.getForObject(endpoint + "/projects/" + projectId, ProjectInfo.class);
// jedis.set(String.valueOf(projectId), projectInfo);
// projectInfoCache.put();
redisRepository.save(projectInfo);
return projectInfo;
}
public ProjectInfo getProjectFromCache(long projectId) {
return projectInfoCache.get(projectId);
return redisRepository.findById(projectId).get();
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package io.pivotal.pal.tracker.backlog;

import org.springframework.data.annotation.Id;
import org.springframework.data.redis.core.RedisHash;

import java.io.Serializable;

@RedisHash("ProjectInfo")
public class ProjectInfo implements Serializable {

private static final long serialVersionUID = -8243145428016231L;

@Id
private Long id;
public final boolean active;

private ProjectInfo() {
Expand Down Expand Up @@ -38,4 +44,12 @@ public String toString() {
"active=" + active +
'}';
}

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
package io.pivotal.pal.tracker.backlog;

public class ProjectInfoRedisRepository {
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface ProjectInfoRedisRepository extends CrudRepository<ProjectInfo, Long> {
}
1 change: 1 addition & 0 deletions manifest-backlog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ applications:
- tracker-service-registry
- tracker-circuit-breaker-dashboard
- tracker-sso
- redisCache

0 comments on commit 92c051d

Please sign in to comment.