0

我在 spring data redis 中执行管道命令时遇到问题。我正在使用 StringRedisTemplate。spring-data-redis 1.6.1、spring boot 1.3.2 和 jedis 2.7.3 和 2.8.0。

编码:

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;
              }
            });



}

执行 pExpire 时,它​​会在主题中出现异常。我尝试过参考指南中建议的不同口味:with

execute(redisCallback, true, true)

同样的结果。任何想法?谢谢

4

0 回答 0