Class ValkeyKeyValueAdapter
java.lang.Object
org.springframework.data.keyvalue.core.AbstractKeyValueAdapter
io.valkey.springframework.data.valkey.core.ValkeyKeyValueAdapter
- All Implemented Interfaces:
EventListener,org.springframework.beans.factory.Aware,org.springframework.beans.factory.DisposableBean,org.springframework.beans.factory.InitializingBean,org.springframework.context.ApplicationContextAware,org.springframework.context.ApplicationListener<ValkeyKeyspaceEvent>,org.springframework.context.Lifecycle,org.springframework.context.Phased,org.springframework.context.SmartLifecycle,org.springframework.data.keyvalue.core.KeyValueAdapter
public class ValkeyKeyValueAdapter
extends org.springframework.data.keyvalue.core.AbstractKeyValueAdapter
implements org.springframework.beans.factory.InitializingBean, org.springframework.context.SmartLifecycle, org.springframework.context.ApplicationContextAware, org.springframework.context.ApplicationListener<ValkeyKeyspaceEvent>
Valkey specific
Example
The
KeyValueAdapter implementation. Uses binary codec to read/write data from/to Valkey. Objects
are stored in a Valkey Hash using the value of ValkeyHash, the KeyspaceConfiguration or just
Class.getName() as a prefix. Example
@ValkeyHash("persons")
class Person {
@Id String id;
String name;
}
prefix ID
| |
V V
hgetall persons:5d67b7e1-8640-4475-beeb-c666fab4c0e5
1) id
2) 5d67b7e1-8640-4475-beeb-c666fab4c0e5
3) name
4) Rand al'Thor
The
KeyValueAdapter is not intended to store simple types such as String values.
Please use ValkeyTemplate for this purpose.- Since:
- 1.7
- Author:
- Christoph Strobl, Mark Paluch, Andrey Muchnik, John Blum
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumstatic enumConfiguration flag controlling storage of phantom keys (shadow copies) of expiring entities to read them later when publishingValkeyKeyspaceEvent. -
Field Summary
Fields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedDefault constructor.ValkeyKeyValueAdapter(ValkeyOperations<?, ?> valkeyOps) Creates newValkeyKeyValueAdapterwith defaultValkeyMappingContextand defaultValkeyCustomConversions.ValkeyKeyValueAdapter(ValkeyOperations<?, ?> valkeyOps, ValkeyConverter valkeyConverter) Creates newValkeyKeyValueAdapterwith specificValkeyConverter.ValkeyKeyValueAdapter(ValkeyOperations<?, ?> valkeyOps, ValkeyMappingContext mappingContext) Creates newValkeyKeyValueAdapterwith defaultValkeyCustomConversions.ValkeyKeyValueAdapter(ValkeyOperations<?, ?> valkeyOps, ValkeyMappingContext mappingContext, org.springframework.data.convert.CustomConversions customConversions) Creates newValkeyKeyValueAdapter. -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidclear()booleanlongbyte[]<T> TvoiddeleteAllOf(String keyspace) voiddestroy()<T> Texecute(ValkeyCallback<T> callback) ExecuteValkeyCallbackvia underlyingValkeyOperations.<T> TList<?><T> Iterable<T><T> List<T>Get all elements for given keyspace.Get theValkeyConverterin use.booleanvoidvoidsetApplicationContext(org.springframework.context.ApplicationContext applicationContext) voidsetEnableKeyspaceEvents(ValkeyKeyValueAdapter.EnableKeyspaceEvents enableKeyspaceEvents) Configure usage ofKeyExpirationEventMessageListener.voidsetKeyspaceNotificationsConfigParameter(String keyspaceNotificationsConfigParameter) Configure the notify-keyspace-events property if not already set.voidsetMessageListenerContainer(ValkeyMessageListenerContainer messageListenerContainer) Configure aValkeyMessageListenerContainerto listen for Keyspace expiry events.voidsetShadowCopy(ValkeyKeyValueAdapter.ShadowCopy shadowCopy) Configure storage of phantom keys (shadow copies) of expiring entities.voidstart()voidstop()byte[]Convert given source to binary representation using the underlyingConversionService.voidupdate(PartialUpdate<?> update) Methods inherited from class org.springframework.data.keyvalue.core.AbstractKeyValueAdapter
count, find, find, getQueryEngineMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.context.ApplicationListener
supportsAsyncExecutionMethods inherited from interface org.springframework.data.keyvalue.core.KeyValueAdapter
entries, existsMethods inherited from interface org.springframework.context.SmartLifecycle
getPhase, isAutoStartup, stop
-
Constructor Details
-
ValkeyKeyValueAdapter
Creates newValkeyKeyValueAdapterwith defaultValkeyMappingContextand defaultValkeyCustomConversions.- Parameters:
valkeyOps- must not be null.
-
ValkeyKeyValueAdapter
Creates newValkeyKeyValueAdapterwith defaultValkeyCustomConversions.- Parameters:
valkeyOps- must not be null.mappingContext- must not be null.
-
ValkeyKeyValueAdapter
public ValkeyKeyValueAdapter(ValkeyOperations<?, ?> valkeyOps, ValkeyMappingContext mappingContext, @Nullable org.springframework.data.convert.CustomConversions customConversions) Creates newValkeyKeyValueAdapter.- Parameters:
valkeyOps- must not be null.mappingContext- must not be null.customConversions- can be null.- Since:
- 2.0
-
ValkeyKeyValueAdapter
Creates newValkeyKeyValueAdapterwith specificValkeyConverter.- Parameters:
valkeyOps- must not be null.valkeyConverter- must not be null.
-
ValkeyKeyValueAdapter
protected ValkeyKeyValueAdapter()Default constructor.
-
-
Method Details
-
put
- Specified by:
putin interfaceorg.springframework.data.keyvalue.core.KeyValueAdapter
-
contains
- Specified by:
containsin interfaceorg.springframework.data.keyvalue.core.KeyValueAdapter
-
get
- Specified by:
getin interfaceorg.springframework.data.keyvalue.core.KeyValueAdapter
-
get
- Specified by:
getin interfaceorg.springframework.data.keyvalue.core.KeyValueAdapter- Overrides:
getin classorg.springframework.data.keyvalue.core.AbstractKeyValueAdapter
-
delete
- Specified by:
deletein interfaceorg.springframework.data.keyvalue.core.KeyValueAdapter
-
delete
- Specified by:
deletein interfaceorg.springframework.data.keyvalue.core.KeyValueAdapter- Overrides:
deletein classorg.springframework.data.keyvalue.core.AbstractKeyValueAdapter
-
getAllOf
- Specified by:
getAllOfin interfaceorg.springframework.data.keyvalue.core.KeyValueAdapter
-
getAllOf
- Specified by:
getAllOfin interfaceorg.springframework.data.keyvalue.core.KeyValueAdapter
-
getAllOf
Get all elements for given keyspace.- Parameters:
keyspace- the keyspace to fetch entities from.type- the desired target type.offset- index value to start reading.rows- maximum number or entities to return.- Returns:
- never null.
- Since:
- 2.5
-
deleteAllOf
- Specified by:
deleteAllOfin interfaceorg.springframework.data.keyvalue.core.KeyValueAdapter
-
entries
public org.springframework.data.util.CloseableIterator<Map.Entry<Object,Object>> entries(String keyspace) - Specified by:
entriesin interfaceorg.springframework.data.keyvalue.core.KeyValueAdapter
-
count
- Specified by:
countin interfaceorg.springframework.data.keyvalue.core.KeyValueAdapter
-
update
-
execute
ExecuteValkeyCallbackvia underlyingValkeyOperations.- Parameters:
callback- must not be null.- See Also:
-
getConverter
Get theValkeyConverterin use.- Returns:
- never null.
-
clear
public void clear()- Specified by:
clearin interfaceorg.springframework.data.keyvalue.core.KeyValueAdapter
-
createKey
-
toBytes
Convert given source to binary representation using the underlyingConversionService. -
setEnableKeyspaceEvents
public void setEnableKeyspaceEvents(ValkeyKeyValueAdapter.EnableKeyspaceEvents enableKeyspaceEvents) Configure usage ofKeyExpirationEventMessageListener.- Since:
- 1.8
-
setMessageListenerContainer
Configure aValkeyMessageListenerContainerto listen for Keyspace expiry events. The container can only be set when this bean hasn't been yetinitialized.- Parameters:
messageListenerContainer- the container to use.- Throws:
IllegalStateException- when trying to set aValkeyMessageListenerContainerafterafterPropertiesSet()has been called to initialize a managed container instance.- Since:
- 2.7.2
-
setKeyspaceNotificationsConfigParameter
Configure the notify-keyspace-events property if not already set. Use an emptyStringor null to retain existing server settings.- Parameters:
keyspaceNotificationsConfigParameter- can be null.- Since:
- 1.8
-
setShadowCopy
Configure storage of phantom keys (shadow copies) of expiring entities.- Parameters:
shadowCopy- must not be null.- Since:
- 2.3
-
isRunning
public boolean isRunning()- Specified by:
isRunningin interfaceorg.springframework.context.Lifecycle
-
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Since:
- 1.8
- See Also:
-
InitializingBean.afterPropertiesSet()
-
start
public void start()- Specified by:
startin interfaceorg.springframework.context.Lifecycle
-
stop
public void stop()- Specified by:
stopin interfaceorg.springframework.context.Lifecycle
-
destroy
- Specified by:
destroyin interfaceorg.springframework.beans.factory.DisposableBean- Throws:
Exception
-
onApplicationEvent
- Specified by:
onApplicationEventin interfaceorg.springframework.context.ApplicationListener<ValkeyKeyspaceEvent>
-
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException - Specified by:
setApplicationContextin interfaceorg.springframework.context.ApplicationContextAware- Throws:
org.springframework.beans.BeansException
-