Class RedisKeyValueStore
- java.lang.Object
-
- org.nuxeo.runtime.kv.AbstractKeyValueStoreProvider
-
- org.nuxeo.ecm.core.redis.contribs.RedisKeyValueStore
-
- All Implemented Interfaces:
KeyValueStore,KeyValueStoreProvider
public class RedisKeyValueStore extends AbstractKeyValueStoreProvider
Redis implementation of a Key/Value Store Provider.The following configuration properties are available:
- namespace: the Redis namespace to use for keys (in addition to the global Redis namespace configured in the Redis
service). DEPRECATED since 10.10, use the descriptor's
<namespace>element instead.
- Since:
- 9.1
-
-
Field Summary
Fields Modifier and Type Field Description protected byte[]compareAndDelSHAprotected byte[]compareAndSetSHAprotected byte[]compareNullAndSetSHAprotected Stringnamespacestatic StringNAMESPACE_PROPDeprecated.since 10.10protected static LongONE-
Fields inherited from class org.nuxeo.runtime.kv.AbstractKeyValueStoreProvider
name, UTF_8_DECODERS
-
-
Constructor Summary
Constructors Constructor Description RedisKeyValueStore()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description longaddAndGet(String key, long delta)Atomically adds the delta to the value associated to the key, interpreted as a long represented as a string.voidclear()Clears the content of this Key/Value store provider.voidclose()Closes this Key/Value store provider.booleancompareAndSet(String key, byte[] expected, byte[] value, long ttl)Atomically sets the value associated to the key to the given value, with the given TTL, if the current value is the expected value.static StringecapeGlob(String prefix)Escape glob-like wildcards and [] char ranges with a backslash.byte[]get(String key)Retrieves the value associated to the key.Map<String,byte[]>get(Collection<String> keys)Retrieves the key/value map associated with the keys.protected static byte[]getBytes(String key)Map<String,Long>getLongs(Collection<String> keys)Retrieves the key/value map associated with the keys.protected String[]getNamespace(KeyValueStoreDescriptor descriptor)Map<String,String>getStrings(Collection<String> keys)Retrieves the key/value map associated with the keys.protected List<byte[]>getValuesForKeys(Collection<String> keys)voidinitialize(KeyValueStoreDescriptor descriptor)Initializes this Key/Value store provider.Stream<String>keyStream()Returns aStreamof the keys contained in this Key/Value store provider.Stream<String>keyStream(String prefix)Returns aStreamof the keys with the given prefix contained in this Key/Value store provider.voidput(String key, byte[] value, long ttl)Sets the value associated to the key, and a TTL.booleansetTTL(String key, long ttl)Sets the TTL for an existing key.-
Methods inherited from class org.nuxeo.runtime.kv.AbstractKeyValueStoreProvider
bytesToLong, bytesToString, compareAndSet, compareAndSet, compareAndSet, getLong, getString, longToBytes, put, put, put, put, put, stringToBytes, toString
-
-
-
-
Field Detail
-
NAMESPACE_PROP
@Deprecated public static final String NAMESPACE_PROP
Deprecated.since 10.10- See Also:
- Constant Field Values
-
ONE
protected static final Long ONE
-
namespace
protected String namespace
-
compareAndSetSHA
protected byte[] compareAndSetSHA
-
compareAndDelSHA
protected byte[] compareAndDelSHA
-
compareNullAndSetSHA
protected byte[] compareNullAndSetSHA
-
-
Method Detail
-
getBytes
protected static byte[] getBytes(String key)
-
initialize
public void initialize(KeyValueStoreDescriptor descriptor)
Description copied from interface:KeyValueStoreProviderInitializes this Key/Value store provider.- Specified by:
initializein interfaceKeyValueStoreProvider- Overrides:
initializein classAbstractKeyValueStoreProvider- Parameters:
descriptor- the store provider descriptor
-
getNamespace
protected String[] getNamespace(KeyValueStoreDescriptor descriptor)
-
keyStream
public Stream<String> keyStream()
Description copied from interface:KeyValueStoreProviderReturns aStreamof the keys contained in this Key/Value store provider.This operation may be slow and should only be used for management or debug purposes.
- Returns:
- the stream of keys
-
keyStream
public Stream<String> keyStream(String prefix)
Description copied from interface:KeyValueStoreProviderReturns aStreamof the keys with the given prefix contained in this Key/Value store provider.This operation may be slow and should only be used for management or debug purposes.
- Returns:
- the stream of keys
-
ecapeGlob
public static String ecapeGlob(String prefix)
Escape glob-like wildcards and [] char ranges with a backslash.
-
close
public void close()
Description copied from interface:KeyValueStoreProviderCloses this Key/Value store provider.
-
clear
public void clear()
Description copied from interface:KeyValueStoreProviderClears the content of this Key/Value store provider.
-
put
public void put(String key, byte[] value, long ttl)
Description copied from interface:KeyValueStoreSets the value associated to the key, and a TTL.- Parameters:
key- the keyvalue- the value, which may benullttl- the TTL, in seconds (0 for infinite)
-
get
public byte[] get(String key)
Description copied from interface:KeyValueStoreRetrieves the value associated to the key.- Parameters:
key- the key- Returns:
- the value, or
nullif there is no value
-
get
public Map<String,byte[]> get(Collection<String> keys)
Description copied from interface:KeyValueStoreRetrieves the key/value map associated with the keys.- Specified by:
getin interfaceKeyValueStore- Overrides:
getin classAbstractKeyValueStoreProvider- Parameters:
keys- the keys- Returns:
- the key/value map
-
getStrings
public Map<String,String> getStrings(Collection<String> keys)
Description copied from interface:KeyValueStoreRetrieves the key/value map associated with the keys.- Specified by:
getStringsin interfaceKeyValueStore- Overrides:
getStringsin classAbstractKeyValueStoreProvider- Parameters:
keys- the keys- Returns:
- the key/value map
-
getLongs
public Map<String,Long> getLongs(Collection<String> keys)
Description copied from interface:KeyValueStoreRetrieves the key/value map associated with the keys.- Specified by:
getLongsin interfaceKeyValueStore- Overrides:
getLongsin classAbstractKeyValueStoreProvider- Parameters:
keys- the keys- Returns:
- the key/value map
-
getValuesForKeys
protected List<byte[]> getValuesForKeys(Collection<String> keys)
- Since:
- 9.10
-
setTTL
public boolean setTTL(String key, long ttl)
Description copied from interface:KeyValueStoreSets the TTL for an existing key.- Parameters:
key- the keyttl- the TTL, in seconds (0 for infinite)- Returns:
trueif the TTL has been set, orfalseif the key does not exist
-
compareAndSet
public boolean compareAndSet(String key, byte[] expected, byte[] value, long ttl)
Description copied from interface:KeyValueStoreAtomically sets the value associated to the key to the given value, with the given TTL, if the current value is the expected value.Note value comparison is done by value and not by reference.
- Parameters:
key- the keyexpected- the expected value, which may benullvalue- the updated value, which may benullttl- the TTL, in seconds (0 for infinite)- Returns:
trueif the value was updated, orfalseif not (the expected value was not found)
-
addAndGet
public long addAndGet(String key, long delta) throws NumberFormatException
Description copied from interface:KeyValueStoreAtomically adds the delta to the value associated to the key, interpreted as a long represented as a string.If the value does not exist (if
KeyValueStore.get(java.lang.String)would returnnull), it is interpreted as0.- Specified by:
addAndGetin interfaceKeyValueStore- Overrides:
addAndGetin classAbstractKeyValueStoreProvider- Parameters:
key- the keydelta- the delta to add- Returns:
- the new value
- Throws:
NumberFormatException- if the existing value cannot be interpreted as along
-
-