|
|
@ -29,7 +29,6 @@ import org.thingsboard.server.common.data.HasVersion; |
|
|
import java.io.Serializable; |
|
|
import java.io.Serializable; |
|
|
import java.util.Arrays; |
|
|
import java.util.Arrays; |
|
|
import java.util.Collection; |
|
|
import java.util.Collection; |
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
|
|
@Slf4j |
|
|
@Slf4j |
|
|
public abstract class VersionedRedisTbCache<K extends Serializable, V extends Serializable & HasVersion> extends RedisTbTransactionalCache<K, V> implements VersionedTbCache<K, V> { |
|
|
public abstract class VersionedRedisTbCache<K extends Serializable, V extends Serializable & HasVersion> extends RedisTbTransactionalCache<K, V> implements VersionedTbCache<K, V> { |
|
|
@ -102,19 +101,31 @@ public abstract class VersionedRedisTbCache<K extends Serializable, V extends Se |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void put(K key, V value, Long version) { |
|
|
public void put(K key, V value, Long version) { |
|
|
log.trace("put [{}][{}][{}]", key, value, version); |
|
|
|
|
|
doPut(key, value, version, cacheTtl); |
|
|
doPut(key, value, version, cacheTtl); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public void put(K key, V value, RedisConnection connection) { |
|
|
|
|
|
Long version = value != null ? value.getVersion() : 0; |
|
|
|
|
|
byte[] rawKey = getRawKey(key); |
|
|
|
|
|
doPut(rawKey, value, version, cacheTtl, connection); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
private void doPut(K key, V value, Long version, Expiration expiration) { |
|
|
private void doPut(K key, V value, Long version, Expiration expiration) { |
|
|
|
|
|
log.trace("put [{}][{}][{}]", key, value, version); |
|
|
if (version == null) { |
|
|
if (version == null) { |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
final byte[] rawKey = getRawKey(key); |
|
|
final byte[] rawKey = getRawKey(key); |
|
|
|
|
|
try (var connection = getConnection(rawKey)) { |
|
|
|
|
|
doPut(rawKey, value, version, expiration, connection); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void doPut(byte[] rawKey, V value, Long version, Expiration expiration, RedisConnection connection) { |
|
|
byte[] rawValue = getRawValue(value); |
|
|
byte[] rawValue = getRawValue(value); |
|
|
byte[] rawVersion = StringRedisSerializer.UTF_8.serialize(String.valueOf(version)); |
|
|
byte[] rawVersion = StringRedisSerializer.UTF_8.serialize(String.valueOf(version)); |
|
|
byte[] rawExpiration = StringRedisSerializer.UTF_8.serialize(String.valueOf(expiration.getExpirationTimeInSeconds())); |
|
|
byte[] rawExpiration = StringRedisSerializer.UTF_8.serialize(String.valueOf(expiration.getExpirationTimeInSeconds())); |
|
|
try (var connection = getConnection(rawKey)) { |
|
|
|
|
|
try { |
|
|
try { |
|
|
connection.scriptingCommands().evalSha(SET_VERSIONED_VALUE_SHA, ReturnType.VALUE, 1, rawKey, rawValue, rawVersion, rawExpiration); |
|
|
connection.scriptingCommands().evalSha(SET_VERSIONED_VALUE_SHA, ReturnType.VALUE, 1, rawKey, rawValue, rawVersion, rawExpiration); |
|
|
} catch (InvalidDataAccessApiUsageException e) { |
|
|
} catch (InvalidDataAccessApiUsageException e) { |
|
|
@ -131,7 +142,6 @@ public abstract class VersionedRedisTbCache<K extends Serializable, V extends Se |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void evict(K key, Long version) { |
|
|
public void evict(K key, Long version) { |
|
|
@ -143,7 +153,6 @@ public abstract class VersionedRedisTbCache<K extends Serializable, V extends Se |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void putIfAbsent(K key, V value) { |
|
|
public void putIfAbsent(K key, V value) { |
|
|
log.trace("putIfAbsent [{}][{}]", key, value); |
|
|
|
|
|
throw new NotImplementedException("putIfAbsent is not supported by versioned cache"); |
|
|
throw new NotImplementedException("putIfAbsent is not supported by versioned cache"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -157,14 +166,4 @@ public abstract class VersionedRedisTbCache<K extends Serializable, V extends Se |
|
|
throw new NotImplementedException("evictOrPut is not supported by versioned cache"); |
|
|
throw new NotImplementedException("evictOrPut is not supported by versioned cache"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public TbCacheTransaction<K, V> newTransactionForKey(K key) { |
|
|
|
|
|
throw new NotImplementedException("newTransactionForKey is not supported by versioned cache"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public TbCacheTransaction<K, V> newTransactionForKeys(List<K> keys) { |
|
|
|
|
|
throw new NotImplementedException("newTransactionForKeys is not supported by versioned cache"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|