コード例 #1
0
 @Override
 protected void storeSession(final RedisSession session) {
   if (!session.redisMap.isEmpty()) {
     final Map<String, String> toStore =
         session.redisMap.containsKey("attributes")
             ? session.redisMap
             : new TreeMap<String, String>(session.redisMap);
     if (toStore.containsKey("attributes"))
       toStore.put("attributes", serializer.serialize(session.getSessionAttributes()));
     LOG.debug(
         "[RedisSessionManager] storeSession - Storing session id={}", session.getClusterId());
     jedisExecutor.execute(
         new JedisCallback<Object>() {
           @Override
           public Object execute(Jedis jedis) {
             session.lastSaved = System.currentTimeMillis();
             toStore.put("lastSaved", "" + session.lastSaved);
             return jedis.multi(
                 new TransactionBlock() {
                   @Override
                   public void execute() throws JedisException {
                     final String key =
                         RedisSessionIdManager.REDIS_SESSION_KEY + session.getClusterId();
                     super.hmset(key, toStore);
                     int ttl = session.getMaxInactiveInterval();
                     if (ttl > 0) {
                       super.expire(key, ttl);
                     }
                   }
                 });
           }
         });
     session.redisMap.clear();
   }
 }
コード例 #2
0
 @Override
 protected void deleteSession(final RedisSession session) {
   LOG.debug(
       "[RedisSessionManager] deleteSession - Deleting from Redis session id={}",
       session.getClusterId());
   jedisExecutor.execute(
       new JedisCallback<Object>() {
         @Override
         public Object execute(Jedis jedis) {
           return jedis.del(RedisSessionIdManager.REDIS_SESSION_KEY + session.getClusterId());
         }
       });
 }