@Override public void clear() { getOperations().delete(Collections.singleton(getKey())); }
public void cleanExpiredSessions() { long now = System.currentTimeMillis(); long prevMin = roundDownMinute(now); if (logger.isDebugEnabled()) { logger.debug("Cleaning up sessions expiring at " + new Date(prevMin)); } String expirationKey = getExpirationKey(prevMin); Set<Object> sessionsToExpire = this.redis.boundSetOps(expirationKey).members(); this.redis.delete(expirationKey); for (Object session : sessionsToExpire) { String sessionKey = getSessionKey((String) session); touch(sessionKey); } }
@Test public void deleteNullSession() { given(this.redisOperations.boundHashOps(anyString())) .willReturn(this.boundHashOperations); String id = "abc"; this.redisRepository.deleteById(id); verify(this.redisOperations, times(0)).delete(anyString()); verify(this.redisOperations, times(0)).delete(anyString()); }
@Override public void deleteById(String sessionId) { RedisSession session = getSession(sessionId, true); if (session == null) { return; } cleanupPrincipalIndex(session); this.expirationPolicy.onDelete(session); String expireKey = getExpiredKey(session.getId()); this.sessionRedisOperations.delete(expireKey); session.setMaxInactiveInterval(Duration.ZERO); save(session); }
@Test public void onExpirationUpdatedDeleteOnZero() throws Exception { String sessionKey = this.policy.getSessionKey("expires:" + this.session.getId()); long originalExpirationTimeInMs = ONE_MINUTE_AGO; this.session.setMaxInactiveInterval(Duration.ZERO); this.policy.onExpirationUpdated(originalExpirationTimeInMs, this.session); // verify the original is removed verify(this.setOperations).remove("expires:" + this.session.getId()); verify(this.setOperations).add("expires:" + this.session.getId()); verify(this.sessionRedisOperations).delete(sessionKey); verify(this.setOperations).expire( this.session.getMaxInactiveInterval().plusMinutes(5).getSeconds(), TimeUnit.SECONDS); }
@Test public void saveExpired() { RedisSession session = this.redisRepository.new RedisSession(new MapSession()); session.setMaxInactiveInterval(Duration.ZERO); given(this.redisOperations.boundHashOps(anyString())) .willReturn(this.boundHashOperations); given(this.redisOperations.boundSetOps(anyString())) .willReturn(this.boundSetOperations); this.redisRepository.save(session); String id = session.getId(); verify(this.redisOperations, atLeastOnce()).delete(getKey("expires:" + id)); verify(this.redisOperations, never()).boundValueOps(getKey("expires:" + id)); }
@Test public void changeRedisNamespace() { String namespace = "foo:bar"; this.redisRepository.setRedisKeyNamespace(namespace); RedisSession session = this.redisRepository.new RedisSession(new MapSession()); session.setMaxInactiveInterval(Duration.ZERO); given(this.redisOperations.boundHashOps(anyString())) .willReturn(this.boundHashOperations); given(this.redisOperations.boundSetOps(anyString())) .willReturn(this.boundSetOperations); this.redisRepository.save(session); String id = session.getId(); verify(this.redisOperations, atLeastOnce()) .delete(namespace + ":sessions:expires:" + id); verify(this.redisOperations, never()) .boundValueOps(namespace + ":sessions:expires:" + id); }
@Test public void delete() { String attrName = "attrName"; MapSession expected = new MapSession(); expected.setLastAccessedTime(Instant.now().minusSeconds(60)); expected.setAttribute(attrName, "attrValue"); given(this.redisOperations.boundHashOps(anyString())) .willReturn(this.boundHashOperations); given(this.redisOperations.boundSetOps(anyString())) .willReturn(this.boundSetOperations); Map map = map(RedisOperationsSessionRepository.getSessionAttrNameKey(attrName), expected.getAttribute(attrName), RedisOperationsSessionRepository.CREATION_TIME_ATTR, expected.getCreationTime().toEpochMilli(), RedisOperationsSessionRepository.MAX_INACTIVE_ATTR, (int) expected.getMaxInactiveInterval().getSeconds(), RedisOperationsSessionRepository.LAST_ACCESSED_ATTR, expected.getLastAccessedTime().toEpochMilli()); given(this.boundHashOperations.entries()).willReturn(map); given(this.redisOperations.boundSetOps(anyString())) .willReturn(this.boundSetOperations); String id = expected.getId(); this.redisRepository.deleteById(id); assertThat(getDelta().get(RedisOperationsSessionRepository.MAX_INACTIVE_ATTR)) .isEqualTo(0); verify(this.redisOperations, atLeastOnce()).delete(getKey("expires:" + id)); verify(this.redisOperations, never()).boundValueOps(getKey("expires:" + id)); }
this.redis.delete(sessionKey);
/** * Clear the Redis Queue specified by {@link #boundListOperations}. */ @ManagedOperation public void clearQueue() { this.boundListOperations.getOperations().delete(this.boundListOperations.getKey()); }
/** * Clear the Redis Queue specified by {@link #boundListOperations}. */ @ManagedOperation public void clearQueue() { this.boundListOperations.getOperations().delete(this.boundListOperations.getKey()); }
@GetMapping("/logout") public ModelAndView logout(HttpServletRequest request, HttpServletResponse response, Map<String, Object> map) { Cookie cookie = CookieUtil.get(request, CookieConstant.TOKEN); if (cookie != null) { redisTemplate.opsForValue().getOperations().delete(String.format(RedisConstant.TOKEN_PREFIX, cookie.getValue())); CookieUtil.set(response, CookieConstant.TOKEN, null, 0); } map.put("msg", ResultEnum.LOGIN_FAIL); map.put("url", "/sell/seller/order/list"); return new ModelAndView("common/success", map); } }
public void deleteAll() { Set<String> keys = redisTemplate.keys("*"); Iterator<String> it = keys.iterator(); while(it.hasNext()){ redisTemplate.opsForValue().getOperations().delete(it.next()); } }
public void deleteObjectByKey(String key) throws Exception { if (null==key) return; ValueOperations<String, Object> operations = this.redisTemplate.opsForValue(); operations.getOperations().delete(key); }
public void reset(String metricName) { String key = keyFor(metricName); if (this.zSetOperations.remove(key) == 1) { this.redisOperations.delete(key); } }
/** * 将权限信息从缓存中删除 */ @Override public V remove(K key) throws CacheException { V v = redisTemplate.opsForValue().get(key); redisTemplate.opsForValue().getOperations().delete(key); return v; }
@Override public void clearAuthorizationInfoCacheByUserId(long userId) { SysUser sysUser = sysUserMapper.selectById(userId); if (sysUser != null) { redisTemplate.opsForValue().getOperations().delete(SystemConstant.shiro_cache_prefix + sysUser.getLoginName()); } log.debug("clear authorization info cache userId : {}", userId); }
@Override public V delete(String key) { V value = get(key); if (value != null) { redisTemplate.opsForValue().getOperations().delete(key); } return value; }
@Override public void closeIpIntercept() { //更新字典数据 SysDataItem sysDataItem = new SysDataItem(); sysDataItem.setId(4L); sysDataItem.setKeyValue("false"); sysDataItemMapper.update(sysDataItem); //删除缓存 redisTemplate.opsForValue().getOperations().delete("3-ip_forbidden"); redisTemplate.opsForSet().getOperations().delete("ip_intercepter"); }
@Override public void updateDateItem(SysDataItem sysDataItem) { redisTemplate.opsForValue().getOperations().delete(sysDataItem.getSysDataGroupId() + "-" + sysDataItem.getKeyName()); sysDataItemMapper.update(sysDataItem); }