public class RedisKeyValueAdapter extends org.springframework.data.keyvalue.core.AbstractKeyValueAdapter implements InitializingBean, ApplicationContextAware, ApplicationListener<RedisKeyspaceEvent>
KeyValueAdapter implementation. Uses binary codec to read/write data from/to Redis. Objects
are stored in a Redis Hash using the value of RedisHash, the KeyspaceConfiguration or just
Class.getName() as a prefix.
@RedisHash("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
KeyValueAdapter is not intended to store simple types such as String values.
Please use RedisTemplate for this purpose.| Modifier and Type | Class and Description |
|---|---|
static class |
RedisKeyValueAdapter.EnableKeyspaceEvents |
| Modifier | Constructor and Description |
|---|---|
protected |
RedisKeyValueAdapter()
Default constructor.
|
|
RedisKeyValueAdapter(RedisOperations<?,?> redisOps)
Creates new
RedisKeyValueAdapter with default RedisMappingContext and default
RedisCustomConversions. |
|
RedisKeyValueAdapter(RedisOperations<?,?> redisOps,
RedisConverter redisConverter)
Creates new
RedisKeyValueAdapter with specific RedisConverter. |
|
RedisKeyValueAdapter(RedisOperations<?,?> redisOps,
RedisMappingContext mappingContext)
Creates new
RedisKeyValueAdapter with default RedisCustomConversions. |
|
RedisKeyValueAdapter(RedisOperations<?,?> redisOps,
RedisMappingContext mappingContext,
CustomConversions customConversions)
Deprecated.
|
|
RedisKeyValueAdapter(RedisOperations<?,?> redisOps,
RedisMappingContext mappingContext,
CustomConversions customConversions)
Creates new
RedisKeyValueAdapter. |
| Modifier and Type | Method and Description |
|---|---|
void |
afterPropertiesSet() |
void |
clear() |
boolean |
contains(Object id,
String keyspace) |
long |
count(String keyspace) |
byte[] |
createKey(String keyspace,
String id) |
Object |
delete(Object id,
String keyspace) |
<T> T |
delete(Object id,
String keyspace,
Class<T> type) |
void |
deleteAllOf(String keyspace) |
void |
destroy() |
CloseableIterator<Map.Entry<Object,Object>> |
entries(String keyspace) |
<T> T |
execute(RedisCallback<T> callback)
Execute
RedisCallback via underlying RedisOperations. |
Object |
get(Object id,
String keyspace) |
<T> T |
get(Object id,
String keyspace,
Class<T> type) |
List<?> |
getAllOf(String keyspace) |
List<?> |
getAllOf(String keyspace,
long offset,
int rows) |
RedisConverter |
getConverter()
Get the
RedisConverter in use. |
void |
onApplicationEvent(RedisKeyspaceEvent event) |
Object |
put(Object id,
Object item,
String keyspace) |
void |
setApplicationContext(ApplicationContext applicationContext) |
void |
setEnableKeyspaceEvents(RedisKeyValueAdapter.EnableKeyspaceEvents enableKeyspaceEvents)
Configure usage of
KeyExpirationEventMessageListener. |
void |
setKeyspaceNotificationsConfigParameter(String keyspaceNotificationsConfigParameter)
Configure the notify-keyspace-events property if not already set.
|
byte[] |
toBytes(Object source)
Convert given source to binary representation using the underlying
ConversionService. |
void |
update(PartialUpdate<?> update) |
public RedisKeyValueAdapter(RedisOperations<?,?> redisOps)
RedisKeyValueAdapter with default RedisMappingContext and default
RedisCustomConversions.redisOps - must not be null.public RedisKeyValueAdapter(RedisOperations<?,?> redisOps, RedisMappingContext mappingContext)
RedisKeyValueAdapter with default RedisCustomConversions.redisOps - must not be null.mappingContext - must not be null.@Deprecated public RedisKeyValueAdapter(RedisOperations<?,?> redisOps, RedisMappingContext mappingContext, CustomConversions customConversions)
RedisKeyValueAdapter(RedisOperations, RedisMappingContext, org.springframework.data.convert.CustomConversions).RedisKeyValueAdapter.redisOps - must not be null.mappingContext - must not be null.customConversions - can be null.public RedisKeyValueAdapter(RedisOperations<?,?> redisOps, RedisMappingContext mappingContext, @Nullable CustomConversions customConversions)
RedisKeyValueAdapter.redisOps - must not be null.mappingContext - must not be null.customConversions - can be null.public RedisKeyValueAdapter(RedisOperations<?,?> redisOps, RedisConverter redisConverter)
RedisKeyValueAdapter with specific RedisConverter.redisOps - must not be null.redisConverter - must not be null.protected RedisKeyValueAdapter()
public Object put(Object id, Object item, String keyspace)
put in interface org.springframework.data.keyvalue.core.KeyValueAdapterpublic boolean contains(Object id, String keyspace)
contains in interface org.springframework.data.keyvalue.core.KeyValueAdapter@Nullable public Object get(Object id, String keyspace)
get in interface org.springframework.data.keyvalue.core.KeyValueAdapter@Nullable public <T> T get(Object id, String keyspace, Class<T> type)
get in interface org.springframework.data.keyvalue.core.KeyValueAdapterget in class org.springframework.data.keyvalue.core.AbstractKeyValueAdapterpublic Object delete(Object id, String keyspace)
delete in interface org.springframework.data.keyvalue.core.KeyValueAdapterpublic <T> T delete(Object id, String keyspace, Class<T> type)
delete in interface org.springframework.data.keyvalue.core.KeyValueAdapterdelete in class org.springframework.data.keyvalue.core.AbstractKeyValueAdapterpublic List<?> getAllOf(String keyspace)
getAllOf in interface org.springframework.data.keyvalue.core.KeyValueAdapterpublic void deleteAllOf(String keyspace)
deleteAllOf in interface org.springframework.data.keyvalue.core.KeyValueAdapterpublic CloseableIterator<Map.Entry<Object,Object>> entries(String keyspace)
entries in interface org.springframework.data.keyvalue.core.KeyValueAdapterpublic long count(String keyspace)
count in interface org.springframework.data.keyvalue.core.KeyValueAdapterpublic void update(PartialUpdate<?> update)
@Nullable public <T> T execute(RedisCallback<T> callback)
RedisCallback via underlying RedisOperations.callback - must not be null.RedisOperations.execute(RedisCallback)public RedisConverter getConverter()
RedisConverter in use.public void clear()
clear in interface org.springframework.data.keyvalue.core.KeyValueAdapterpublic byte[] toBytes(Object source)
ConversionService.source - ConverterNotFoundExceptionpublic void setEnableKeyspaceEvents(RedisKeyValueAdapter.EnableKeyspaceEvents enableKeyspaceEvents)
KeyExpirationEventMessageListener.enableKeyspaceEvents - public void setKeyspaceNotificationsConfigParameter(String keyspaceNotificationsConfigParameter)
String or
null to retain existing server settings.keyspaceNotificationsConfigParameter - can be null.public void afterPropertiesSet()
afterPropertiesSet in interface InitializingBeanInitializingBean.afterPropertiesSet()public void destroy()
throws Exception
destroy in interface DisposableBeanExceptionpublic void onApplicationEvent(RedisKeyspaceEvent event)
onApplicationEvent in interface ApplicationListener<RedisKeyspaceEvent>public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
setApplicationContext in interface ApplicationContextAwareBeansExceptionCopyright © 2011–2019 Pivotal Software, Inc.. All rights reserved.