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)
|
|
RedisKeyValueAdapter(RedisOperations<?,?> redisOps,
RedisConverter redisConverter)
Creates new
RedisKeyValueAdapter with specific RedisConverter . |
|
RedisKeyValueAdapter(RedisOperations<?,?> redisOps,
RedisMappingContext mappingContext)
Creates new
RedisKeyValueAdapter with default CustomConversions . |
|
RedisKeyValueAdapter(RedisOperations<?,?> redisOps,
RedisMappingContext mappingContext,
CustomConversions customConversions)
Creates new
RedisKeyValueAdapter . |
public RedisKeyValueAdapter(RedisOperations<?,?> redisOps)
redisOps
- must not be null.public RedisKeyValueAdapter(RedisOperations<?,?> redisOps, RedisMappingContext mappingContext)
RedisKeyValueAdapter
with default CustomConversions
.redisOps
- must not be null.mappingContext
- must not be null.public RedisKeyValueAdapter(RedisOperations<?,?> redisOps, RedisMappingContext mappingContext, 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(Serializable id, Object item, Serializable keyspace)
put
in interface org.springframework.data.keyvalue.core.KeyValueAdapter
public boolean contains(Serializable id, Serializable keyspace)
contains
in interface org.springframework.data.keyvalue.core.KeyValueAdapter
public Object get(Serializable id, Serializable keyspace)
get
in interface org.springframework.data.keyvalue.core.KeyValueAdapter
public <T> T get(Serializable id, Serializable keyspace, Class<T> type)
get
in interface org.springframework.data.keyvalue.core.KeyValueAdapter
get
in class org.springframework.data.keyvalue.core.AbstractKeyValueAdapter
id
- keyspace
- type
- public Object delete(Serializable id, Serializable keyspace)
delete
in interface org.springframework.data.keyvalue.core.KeyValueAdapter
public <T> T delete(Serializable id, Serializable keyspace, Class<T> type)
delete
in interface org.springframework.data.keyvalue.core.KeyValueAdapter
delete
in class org.springframework.data.keyvalue.core.AbstractKeyValueAdapter
public List<?> getAllOf(Serializable keyspace)
getAllOf
in interface org.springframework.data.keyvalue.core.KeyValueAdapter
public List<?> getAllOf(Serializable keyspace, int offset, int rows)
public void deleteAllOf(Serializable keyspace)
deleteAllOf
in interface org.springframework.data.keyvalue.core.KeyValueAdapter
public CloseableIterator<Map.Entry<Serializable,Object>> entries(Serializable keyspace)
entries
in interface org.springframework.data.keyvalue.core.KeyValueAdapter
public long count(Serializable keyspace)
count
in interface org.springframework.data.keyvalue.core.KeyValueAdapter
public void update(PartialUpdate<?> update)
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.KeyValueAdapter
public byte[] toBytes(Object source)
ConversionService
.source
- ConverterNotFoundException
public 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 InitializingBean
InitializingBean.afterPropertiesSet()
public void destroy() throws Exception
destroy
in interface DisposableBean
Exception
public void onApplicationEvent(RedisKeyspaceEvent event)
onApplicationEvent
in interface ApplicationListener<RedisKeyspaceEvent>
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
setApplicationContext
in interface ApplicationContextAware
BeansException
Copyright © 2011–2018 Pivotal Software, Inc.. All rights reserved.