Package org.apache.storm.redis.state
Class RedisKeyValueState<K,V>
java.lang.Object
org.apache.storm.redis.state.RedisKeyValueState<K,V>
- All Implemented Interfaces:
Iterable<Map.Entry<K,
,V>> KeyValueState<K,
,V> State
A redis based implementation that persists the state in Redis.
-
Field Summary
-
Constructor Summary
ConstructorDescriptionRedisKeyValueState
(String namespace) RedisKeyValueState
(String namespace, JedisClusterConfig jedisClusterConfig, Serializer<K> keySerializer, Serializer<V> valueSerializer) RedisKeyValueState
(String namespace, JedisPoolConfig poolConfig) RedisKeyValueState
(String namespace, JedisPoolConfig poolConfig, Serializer<K> keySerializer, Serializer<V> valueSerializer) RedisKeyValueState
(String namespace, RedisCommandsInstanceContainer container, Serializer<K> keySerializer, Serializer<V> valueSerializer) -
Method Summary
Modifier and TypeMethodDescriptionvoid
commit()
Persist the current state.void
commit
(long txid) Commit a previously prepared transaction.Deletes the value mapped to the key, if there is any.Returns the value mapped to the key.Returns the value mapped to the key or defaultValue if no mapping is found.iterator()
void
prepareCommit
(long txid) Invoked by the framework to prepare a transaction for commit.void
Maps the value with the key.void
rollback()
Rollback a prepared transaction to the previously committed state.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
ITERATOR_CHUNK_SIZE
public static final int ITERATOR_CHUNK_SIZE- See Also:
-
EMPTY_PENDING_COMMIT_MAP
-
-
Constructor Details
-
RedisKeyValueState
-
RedisKeyValueState
-
RedisKeyValueState
public RedisKeyValueState(String namespace, JedisPoolConfig poolConfig, Serializer<K> keySerializer, Serializer<V> valueSerializer) -
RedisKeyValueState
public RedisKeyValueState(String namespace, JedisClusterConfig jedisClusterConfig, Serializer<K> keySerializer, Serializer<V> valueSerializer) -
RedisKeyValueState
public RedisKeyValueState(String namespace, RedisCommandsInstanceContainer container, Serializer<K> keySerializer, Serializer<V> valueSerializer)
-
-
Method Details
-
put
Description copied from interface:KeyValueState
Maps the value with the key.- Specified by:
put
in interfaceKeyValueState<K,
V> - Parameters:
key
- the keyvalue
- the value
-
get
Description copied from interface:KeyValueState
Returns the value mapped to the key.- Specified by:
get
in interfaceKeyValueState<K,
V> - Parameters:
key
- the key- Returns:
- the value or null if no mapping is found
-
get
Description copied from interface:KeyValueState
Returns the value mapped to the key or defaultValue if no mapping is found.- Specified by:
get
in interfaceKeyValueState<K,
V> - Parameters:
key
- the keydefaultValue
- the value to return if no mapping is found- Returns:
- the value or defaultValue if no mapping is found
-
delete
Description copied from interface:KeyValueState
Deletes the value mapped to the key, if there is any.- Specified by:
delete
in interfaceKeyValueState<K,
V> - Parameters:
key
- the key
-
iterator
-
prepareCommit
public void prepareCommit(long txid) Description copied from interface:State
Invoked by the framework to prepare a transaction for commit. It should be possible to commit the prepared state later.The same txid can be prepared again, but the next txid cannot be prepared when previous one is not yet committed.
- Specified by:
prepareCommit
in interfaceState
- Parameters:
txid
- the transaction id
-
commit
public void commit(long txid) Description copied from interface:State
Commit a previously prepared transaction. It should be possible to retrieve a committed state later. -
commit
public void commit()Description copied from interface:State
Persist the current state. This is used when the component manages the state. -
rollback
public void rollback()Description copied from interface:State
Rollback a prepared transaction to the previously committed state.
-