Java Code Examples for org.springframework.data.redis.core.BoundValueOperations#set()
The following examples show how to use
org.springframework.data.redis.core.BoundValueOperations#set() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RedisSecurityContextRepository.java From onetwo with Apache License 2.0 | 6 votes |
private void saveSecurityContext(HttpServletRequest request, HttpServletResponse response, SecurityContext context){ String sid = getSessionId(request); if(StringUtils.isBlank(sid)){ SaveToSessionResponseWrapper responseWrapper = WebUtils.getNativeResponse(response, SaveToSessionResponseWrapper.class); sid = responseWrapper.getSid(); saveSessionCookies(request, response, sid); } /*LoginUserDetails loginUser = SecurityUtils.getCurrentLoginUser(context); if(loginUser!=null){ loginUser.setToken(sid); }*/ BoundValueOperations<String, SecurityContext> bondOps = getSessionBoundOps(sid); //当前spring-data-redis版本不支持setex,分成两个操作 bondOps.set(context); setSecurityContextExpireTime(request); }
Example 2
Source File: JwtTokenRedisStore.java From onetwo with Apache License 2.0 | 6 votes |
/*** * auth server store accessToken * tokenEndpoint store acessToken */ @Override public void storeAccessToken(OAuth2AccessToken token, OAuth2Authentication authentication) { DefaultOAuth2AccessToken at = (DefaultOAuth2AccessToken) token; String tokenId = getTokenId(at); Assert.hasLength(tokenId, "tokenId can not be null"); String key = getStoreKey(tokenId); JwtStoredTokenValue value = JwtStoredTokenValue.builder() .token(at.getValue()) .build(); BoundValueOperations<String, JwtStoredTokenValue> ops = redisTemplate.boundValueOps(key); //保存到redis并设置过期时间 ops.set(value, at.getExpiresIn(), TimeUnit.MILLISECONDS); //把tokenvalue置换为tokenId at.setValue(tokenId); }
Example 3
Source File: DefaultPersistenceService.java From spring-boot-email-tools with Apache License 2.0 | 5 votes |
protected void addOps(final EmailSchedulingData emailSchedulingData) { final String orderingKey = orderingKey(emailSchedulingData); final String valueKey = emailSchedulingData.getId(); final double score = calculateScore(emailSchedulingData); BoundZSetOperations<String, String> orderingZSetOps = orderingTemplate.boundZSetOps(orderingKey); orderingZSetOps.add(valueKey, score); orderingZSetOps.persist(); BoundValueOperations<String, EmailSchedulingData> valueValueOps = valueTemplate.boundValueOps(valueKey); valueValueOps.set(emailSchedulingData); valueValueOps.persist(); }
Example 4
Source File: JsonRedisTemplateTest.java From onetwo with Apache License 2.0 | 5 votes |
@Test public void testJsonRedisTemplate(){ String key = "test:data"; BoundValueOperations<Object, Object> ops = (BoundValueOperations<Object, Object>)jsonRedisTemplate.boundValueOps(key); JsonData data = new JsonData(); data.setAge(111); data.setName("testName"); ops.set(data); JsonData data2 = (JsonData)ops.get(); assertThat(data2).isEqualTo(data); jsonRedisTemplate.delete(key); }
Example 5
Source File: RedisCacheAspect.java From jeecg with Apache License 2.0 | 4 votes |
@Around("simplePointcut() && @annotation(ehcache)") public Object aroundLogCalls(ProceedingJoinPoint joinPoint,Ehcache ehcache)throws Throwable { String targetName = joinPoint.getTarget().getClass().getName(); String methodName = joinPoint.getSignature().getName(); Object[] arguments = joinPoint.getArgs(); String cacheKey =""; if(StringUtils.isNotBlank(ehcache.cacheName())){ cacheKey=ehcache.cacheName(); }else{ cacheKey=getCacheKey(targetName, methodName, arguments); } Object result=null; BoundValueOperations<String,Object> valueOps = redisTemplate.boundValueOps(cacheKey); if(ehcache.eternal()){ //永久缓存 result = valueOps.get(); }else{ //临时缓存 result = valueOps.get(); valueOps.expire(20, TimeUnit.MINUTES); } if (result == null) { if ((arguments != null) && (arguments.length != 0)) { result = joinPoint.proceed(arguments); } else { result = joinPoint.proceed(); } if(ehcache.eternal()){ //永久缓存 valueOps.set(result); }else{ //临时缓存 valueOps.set(result,20, TimeUnit.MINUTES); } } return result; }