Page tree
Skip to end of metadata
Go to start of metadata

CAST supports Redis via its NoSQL for Java extension. Details about how this support is provided for Java with Spring Data source code is discussed below.

Supported Libraries

Supported Operations

Operation

Methods Supported

Insert
  •  org.springframework.data.redis.core.ValueOperations.set
  •  org.springframework.data.redis.core.ValueOperations.multiSet
  •  org.springframework.data.redis.core.ValueOperations.setIfAbsent
  •  org.springframework.data.redis.core.ListOperations.leftPush
  •  org.springframework.data.redis.core.ListOperations.leftPushAll
  •  org.springframework.data.redis.core.ListOperations.rightPush 
  •  org.springframework.data.redis.core.ListOperations.rightPushAll
  •  org.springframework.data.redis.core.ListOperations.set
  •  org.springframework.data.redis.core.HashOperations.putAll
  •  org.springframework.data.redis.core.HashOperations.put
  •  org.springframework.data.redis.core.HashOperations.putIfAbsent
  •  org.springframework.data.redis.core.SetOperations.add
Select
  •  org.springframework.data.redis.core.ValueOperations.get
  •  org.springframework.data.redis.core.ValueOperations.multiGet
  •  org.springframework.data.redis.core.ValueOperations.size
  •  org.springframework.data.redis.core.ValueOperations.bitField
  •  org.springframework.data.redis.core.ListOperations.range
  •  org.springframework.data.redis.core.ListOperations.size
  •  org.springframework.data.redis.core.HashOperations.hasKey
  •  org.springframework.data.redis.core.HashOperations.get
  •  org.springframework.data.redis.core.HashOperations.multiGet
  •  org.springframework.data.redis.core.HashOperations.keys
  •  org.springframework.data.redis.core.HashOperations.lengthOfValue
  •  org.springframework.data.redis.core.HashOperations.size
  •  org.springframework.data.redis.core.HashOperations.entries
  •  org.springframework.data.redis.core.SetOperations.size
  •  org.springframework.data.redis.core.SetOperations.isMember
  •  org.springframework.data.redis.core.SetOperations.members
Delete
  •  org.springframework.data.redis.core.ListOperations.remove
  •  org.springframework.data.redis.core.HashOperations.delete
  •  org.springframework.data.redis.core.SetOperations.remove
  •  org.springframework.data.redis.core.SetOperations.pop
Update
  •  org.springframework.data.redis.core.ValueOperations.increment
  •  org.springframework.data.redis.core..ValueOperations.decrement
  •  org.springframework.data.redis.core.ValueOperations.getAndSet

Objects

Icon

Description

Java Redis Connection

Java Redis Collection

Java unknown Redis Connection

Java Unknown Redis Collection

Links

Links are created for transaction and function point needs:

Link typeWhen is this created?Methods Supported
parentLink

Between Redis connection object and Redis collection object


useLink

Between the caller Java method object and Redis collection object





useSelectLink
  • multiGet
  • get
  • keys
  • entries
useInsertLink
  •  set
  •  put
  •  putAll
  •  add
  •  leftpush

useDeleteLink

  • delete
  • remove
useUpdateLink
  • increment
  • decrement

What results can you expect?

Once the analysis/snapshot generation has completed, you can view the results in the normal manner (for example via CAST Enlighten). Some examples are shown below.

Redis Connections and Collections

 Connections and Collections
@Autowired
private ServiceConfigResource serviceConfigResource;

RedisConnectionFactory switchRedisMaster() {
         return getRedisConnectionFactory(serviceConfigResource.getSwitchRedisMaster(), serviceConfigResource.getDisRedisPort());
}
Java based configurations
@Configuration
@RefreshScope
@Getter
public class ServiceConfigResource {

    	@Value("${disredis.host.disRedisHost1}")
     	private String switchRedisMaster;

    	@Value("${disredis.host.disRedisHost2}")
     	private String switchRedisSlave1;

     	@Value("${disredis.host.disRedisHost3}")
      	private String switchRedisSlave2;

	    @Value("${disredis.port.disRedisPort1}")
    	private int disRedisPort; 

      	@Value("${useRoomSharedUsedTable}")
       	private int useRoomSharedUsedTable;

}

Xml based configurations
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:p="http://www.springframework.org/schema/p"
  xmlns:redis="http://www.springframework.org/schema/redis"
  xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/redis http://www.springframework.org/schema/redis/spring-redis.xsd
        ">
    
<!-- Jedis Connection -->    
<bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
   p:host-name="localhost" p:port="6379" />
  
<!-- Redis Template -->
<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate">
	<property name="connectionFactory" ref="jedisConnectionFactory" />
	<property name="valueSerializer">
		<bean id="redisJsonSerializer" class="org.springframework.data.redis.serializer.JacksonJsonRedisSerializer">
			<constructor-arg type="java.lang.Class" value="redis.User"/>
		</bean>   
	</property>
</bean>

<bean class="redis.UserRepository"/>

</beans>

lettuce
 public ReactiveRedisConnectionFactory build() {
    LettuceClientConfiguration clientConfig;
    LettuceClientConfiguration.LettuceClientConfigurationBuilder builder =
        LettuceClientConfiguration.builder();
    if (ssl) {
      builder.commandTimeout(Duration.ofSeconds(timeout)).useSsl();
    }
    clientConfig = builder.build();

    RedisStandaloneConfiguration configuration = new RedisStandaloneConfiguration();
    configuration.setHostName(host);
    configuration.setPassword(password);
    configuration.setPort(port);
    return new LettuceConnectionFactory(configuration, clientConfig);

Insert Operation for various Redis Collections

 Insert operations
@Bean(name = "switch_redis_master")
    <T> RedisTemplate<String, T> switchMasterRedis() {
        RedisTemplate template = new RedisTemplate<>();
        FastJsonRedisSerializer fastJsonRedisSerializer = new FastJsonRedisSerializer(Object.class);
        template.setConnectionFactory(switchRedisMaster());
        template.setKeySerializer(new StringRedisSerializer());
        template.setValueSerializer(fastJsonRedisSerializer);
        return template;
    }

@Autowired
@Qualifier("switch_redis_master")
private RedisTemplate<String, Integer> redisTemplate;


private boolean invokeFrequencyValidate(String agentCode, Date checkInDate, Date checkOutDate) {
        int openingHotelNum = hotelService.getOpeningHotelNum();
        Date currentDate = new Date();
        // 16-90
        if (AbstractDateUtils.isAfter(checkInDate, AbstractDateUtils.getDeltaDateByDays(currentDate, 15))) {
            Integer count = redisTemplate.opsForValue().get(agentCode + "_" + SIXTEEN_TO_NINETY);
            if (count == null) {
                redisTemplate.opsForValue().set(agentCode + "_" + SIXTEEN_TO_NINETY, 1, TIME_PERIOD_THREE, TimeUnit.MINUTES);
                return true;
            }
            if (count >= maxQueryBase + openingHotelNum / FIFTEEN_OUTER_DIVIDED) {
                return false;
            }
            return true;
        }

Select Operation for various Redis Collections

 Select Operations
private List<RoomShareUsedCountEntity> calculateRoomShareUsedCountWithType(StandardRoomWithTypeRequest standardRoomWithTypeRequest) {
        List<String> validDateList = calculateAllKeyDate(standardRoomWithTypeRequest.getCheckInDate(), standardRoomWithTypeRequest.getCheckOutDate());
        List<String> fullKey = Lists.newArrayList();

        List<UsedShareRoomCount> allUsedShareRoomCountList = Lists.newArrayList();
        for (String key : fullKey) {
            List<UsedShareRoomCount> value = (List<UsedShareRoomCount>) usedShareRoomCountSlaveRedisTemplate.opsForValue().get(key);
        }
        if (CollectionUtils.isEmpty(allUsedShareRoomCountList)) {
            return Lists.newArrayList();
        }
        return convert2RoomShareUsedCountEntityFromUsedShareCount(allUsedShareRoomCountList);
    }

Update Operation for various Redis Collections

 Update operations
private boolean invokeFrequencyValidate(String agentCode, Date checkInDate, Date checkOutDate) {

        int openingHotelNum = hotelService.getOpeningHotelNum();
        Date currentDate = new Date();
        // 16-90
        if (AbstractDateUtils.isAfter(checkInDate, AbstractDateUtils.getDeltaDateByDays(currentDate, 15))) {
            Integer count = redisTemplate.opsForValue().get(agentCode + "_" + SIXTEEN_TO_NINETY);
            if (count == null) {
                redisTemplate.opsForValue().set(agentCode + "_" + SIXTEEN_TO_NINETY, 1, TIME_PERIOD_THREE, TimeUnit.MINUTES);
                return true;
            }
            if (count >= maxQueryBase + openingHotelNum / FIFTEEN_OUTER_DIVIDED) {
                return false;
            }
            redisTemplate.opsForValue().increment(agentCode + "_" + SIXTEEN_TO_NINETY, 1);
            return true;
        }

Delete Operation for various Redis Collections

 Delete Operations
public void delete(String key) {
		template.opsForValue().getOperations().delete(key);
	}

Evolution

  • Resolution increased for connection and collection objects
  • Connections names are resolved for the Redis.connection
  • Identifying connection and collection for XML based configuration
  • Support for Set and Hash operations

Future Development

  • Support for Reactive Redis operations

Limitations

Collections and connection names are resolved as known only in the following situations:

For lettuce configuration

  • Connection/ collection name is passed using properties files.
  • No labels