0

I have trouble executing pipeline commands in spring data redis. I am using StringRedisTemplate. spring-data-redis 1.6.1, spring boot 1.3.2, and jedis both 2.7.3 and 2.8.0.

The code:

public void saveUserActivityEvents(Event... events) {   
    List<Object> results = stringRedisTemplate.executePipelined(
              new RedisCallback<Object>() {
                public Object doInRedis(RedisConnection connection) throws DataAccessException {
                  StringRedisConnection stringRedisConn = (StringRedisConnection)connection;
                  for(int i=0; i< events.length; i++) {
                    Event event = events[i];
                    String userId = getUserId(event.getUser());       
                    String eventType = event.getEventType();
                    String itemId = event.getItem();
                    Integer amount = event.getAmount() == null ? 0 : Integer.parseInt(event.getAmount());
                    Double timestamp = Double.valueOf(event.getTimestamp());
                    Map<String, String> valueMap= new HashMap<String, String>();            
                    valueMap.put("itemId", itemId);
                    valueMap.put("userId", userId);
                    String userItemEventsKey = StrSubstitutor.replace(Constants.KEY_USER_ITEM_EVENTS, valueMap);
                    valueMap.put("userId", userId);     
                    String userItemsKey = StrSubstitutor.replace(Constants.KEY_USER_ITEMS, valueMap);
                    stringRedisConn.zAdd(userItemsKey, timestamp, itemId);
                    stringRedisConn.hIncrBy(userItemEventsKey, eventType, amount);                      
                    long expireInMs = TimeoutUtils.toMillis(getExpiryTimeInDays(event.getUser()), TimeUnit.DAYS);
                    stringRedisConn.pExpire(userItemEventsKey, expireInMs);
                  }
                return null;
              }
            });



}

It blows with the exception in subject when executing pExpire. I've tried with different flavour suggested in reference guide: with

execute(redisCallback, true, true)

The same result. Any idea? Thanks

clandestino_bgd
  • 143
  • 1
  • 2
  • 11
  • Figured out myself by looking at spring-data-redis code. Currently the max value of expiry in millis is Integer.MAX_VALUE. If it is bigger than that, spring-data-redis JedisConnection is trying to get the redis server time through Jedis instance and this is causing all the problems. I see this is a known feature in spring-data-redis but cannot think of any good work around if you have expiry times > 24 Days – clandestino_bgd Mar 03 '16 at 11:50
  • https://jira.spring.io/browse/DATAREDIS-472 – clandestino_bgd Mar 03 '16 at 14:15

0 Answers0