/** * 清空缓存 */ @Override public void removeAll(){ log.debug("@GenericCache remove all cache"); Set<K> keys = getKeyHashOps().keys(); if(keys.size() > 0){ getKeyHashOps().delete(keys.toArray());//删除主键缓存 if(unique != null){ //删除默认唯一键缓存 getUniqueHashOps().delete(getUniqueHashOps().keys().toArray()); } for(String keyName: customKeys){ //删除自定义字段缓存 BoundHashOperations<String, Object, V> map = customHashOpsHolder.get(keyName); if(map != null) map.delete(map.keys().toArray()); } } }
@Override public V loadByCustom(String keyName, Object keyValue){ if(StringUtils.isNotEmpty(keyName) && keyValue!=null){ V v = null; BoundHashOperations<String, Object, V> customHashOps = customHashOpsHolder.get(coreConfig.getCtx()+Constants.COLON+clazz.getSimpleName()+Constants.COLON+keyName); if(customHashOps != null) v = customHashOps.get(keyValue); log.debug(String.format("@GenericCache get cache value with custom key name: %s and key value: %s and return value: %s ", keyName, keyValue, v)); return v; }else{ log.warn(String.format("@GenericCache cant not get cache value with empty keyName %s and empty keyValue %s",keyName,keyValue)); return null; } }
@Override public <HK, HV> BoundHashOperations<K, HK, HV> boundHashOps(K key) { try { return redisTemplate.boundHashOps(key); } catch (Exception ex) { throw new RedisBaoException(ex); } }
@Override public BoundHashOperations<String, K, V> getKeyHashOps() { return getCacheService().getKeyHashOps(); }
@Override public BoundHashOperations<String, Object, V> getUniqueHashOps() { return getCacheService().getUniqueHashOps(); }
/** * @return the keyHashOps */ @Override public BoundHashOperations<String, K, V> getKeyHashOps() { return keyHashOps; }
/** * @param keyHashOps the keyHashOps to set */ public void setKeyHashOps(BoundHashOperations<String, K, V> keyHashOps) { this.keyHashOps = keyHashOps; }
/** * @param uniqueHashOps the uniqueHashOps to set */ public void setUniqueHashOps( BoundHashOperations<String, Object, V> uniqueHashOps) { this.uniqueHashOps = uniqueHashOps; }
/** * @return the uniqueHashOps */ @Override public BoundHashOperations<String, Object, V> getUniqueHashOps() { return uniqueHashOps; }
@Override public <HK, HV> BoundHashOperations<K, HK, HV> boundHashOps(K key) { throw new MethodNotSupportException("myRedisTemplate not support this method : boundHashOps(K key) , please use opsForXX"); //return new DefaultBoundHashOperations<K, HK, HV>(key, this); }
BoundHashOperations<byte[], byte[], Object> getHashOps(Serializable keyspace) { return redisOps.boundHashOps(converter.getConversionService().convert(keyspace, byte[].class)); }
public RedisRequestRepository(BoundHashOperations<String, String, Request> hashOps) { this.hashOps = hashOps; }
/** * Gets the {@link BoundHashOperations} to operate on a {@link Session}. * @param sessionId the id of the {@link Session} to work with * @return the {@link BoundHashOperations} to operate on a {@link Session} */ private BoundHashOperations<Object, Object, Object> getSessionBoundHashOperations( String sessionId) { String key = getSessionKey(sessionId); return this.sessionRedisOperations.boundHashOps(key); }
/** * 获取主键缓存Operations * @return */ BoundHashOperations<String, K, V> getKeyHashOps();
/** * 获取唯一键缓存Operations * @return */ BoundHashOperations<String, Object, V> getUniqueHashOps();
/** * Return the {@link BoundHashOperations} operation for Redis. * * @return {@code BoundHashOperations} for Redis */ private BoundHashOperations<String, String, String> hashOps() { return this.redisOperations.boundHashOps("spring.cloud.resource.uri"); }
<HK, HV> BoundHashOperations<K, HK, HV> boundHashOps(K key);