Interface StringCommands
- All Superinterfaces:
BitCommands
- All Known Subinterfaces:
JedisCommands
- All Known Implementing Classes:
Jedis,JedisCluster,JedisPooled,JedisSentineled,JedisSharding,UnifiedJedis
-
Method Summary
Modifier and TypeMethodDescriptionlongAppend Command If the key already exists and is a string, this command appends the provided value at the end of the string.longDecr Command Decrement the number stored at key by one.longDecrBy Command DECRBY work just likeDECRbut instead to decrement by 1 the decrement is integer.Get Command Get the value of the specified key.GetDel Command Get the value of key and delete the key.getEx(String key, GetExParams params) GetEx Command Get the value of key and optionally set its expiration.GetRange Command Return the substring of the string value stored at key, determined by the offsets start and end (both are inclusive).GetSet Command GETSET is an atomic set this value and return the old value command.longIncr Command Increment the number stored at key by one.longIncrBy Command INCRBY work just likeINCRbut instead to increment by 1 the increment is integer.doubleincrByFloat(String key, double increment) IncrByFloat Command INCRBYFLOAT work just likeincrBy(String, long)INCRBY} but increments by floats instead of integers.Calculate the longest common subsequence of keyA and keyB.MGet Command Get the values of all the specified keys.MSet Command Set the the respective keys to the respective values.longMSetNX Command Set the respective keys to the respective values.PSetEx Command PSETEX works exactly likeSETEXwith the sole difference that the expire time is specified in milliseconds instead of seconds.Set Command Set the string value as value of the key.Set Command Set the string value as value of the key.WARNING:SetParams.get()MUST NOT be used with this method.longSetNE Command SETNX works exactly likeSETwith the only difference that if the key already exists no operation is performed.longSetRange Command GETRANGE overwrite part of the string stored at key, starting at the specified offset, for the entire length of value.strAlgoLCSKeys(String keyA, String keyB, StrAlgoLCSParams params) Deprecated.STRALGO LCS command will be removed from Redis 7.longStrLen Command Return the length of the string value stored at key.SubStr Command Return a subset of the string from offset start to offset end (both offsets are inclusive).
-
Method Details
-
set
Set Command Set the string value as value of the key. The string can't be longer than 1073741824 bytes (1 GB).Time complexity: O(1)
- Parameters:
key-value-- Returns:
- OK
-
set
Set Command Set the string value as value of the key. Can be used with optional params.Time complexity: O(1)
- Parameters:
key-value-params-SetParams- Returns:
- simple-string-reply
OKifSETwas executed correctly, ornullif theSEToperation was not performed because the user specified the NX or XX option but the condition was not met.
-
get
Get Command Get the value of the specified key. If the key does not exist the special value 'nil' is returned. If the value stored at key is not a string an error is returned because GET can only handle string values.Time complexity: O(1)
- Parameters:
key-- Returns:
- The value stored in key
-
setGet
WARNING:SetParams.get()MUST NOT be used with this method. -
getDel
GetDel Command Get the value of key and delete the key. This command is similar to GET, except for the fact that it also deletes the key on success (if and only if the key's value type is a string).Time complexity: O(1)
- Parameters:
key-- Returns:
- The value stored in key
-
getEx
GetEx Command Get the value of key and optionally set its expiration. GETEX is similar toGET, but is a write command with additional options: EX seconds -- Set the specified expire time, in seconds. PX milliseconds -- Set the specified expire time, in milliseconds. EXAT timestamp-seconds -- Set the specified Unix time at which the key will expire, in seconds. PXAT timestamp-milliseconds -- Set the specified Unix time at which the key will expire, in milliseconds. PERSIST -- Remove the time to live associated with the key.Time complexity: O(1)
- Parameters:
key-params-GetExParams- Returns:
- The value stored in key
-
setrange
SetRange Command GETRANGE overwrite part of the string stored at key, starting at the specified offset, for the entire length of value. If the offset is larger than the current length of the string at key, the string is padded with zero-bytes to make offset fit. Non-existing keys are considered as empty strings, so this command will make sure it holds a string large enough to be able to set value at offset.Time complexity: O(1)
- Parameters:
key-offset-value-- Returns:
- The length of the string after it was modified by the command
-
getrange
GetRange Command Return the substring of the string value stored at key, determined by the offsets start and end (both are inclusive). Negative offsets can be used in order to provide an offset starting from the end of the string. So -1 means the last character, -2 the penultimate and so forth.Time complexity: O(N) where N is the length of the returned string
- Parameters:
key-startOffset-endOffset-- Returns:
- The substring
-
getSet
GetSet Command GETSET is an atomic set this value and return the old value command. Set key to the string value and return the old value stored at key. The string can't be longer than 1073741824 byte (1 GB).Time complexity: O(1)
- Parameters:
key-value-- Returns:
- The old value that was stored in key
-
setnx
SetNE Command SETNX works exactly likeSETwith the only difference that if the key already exists no operation is performed. SETNX actually means "SET if Not Exists".Time complexity: O(1)
- Parameters:
key-value-- Returns:
- 1 if the key was set, 0 otherwise
-
setex
SetEx Command The command is exactly equivalent to the following group of commands:SET+EXPIRE. The operation is atomic.Time complexity: O(1)
- Parameters:
key-seconds-value-- Returns:
- OK
-
psetex
PSetEx Command PSETEX works exactly likeSETEXwith the sole difference that the expire time is specified in milliseconds instead of seconds.Time complexity: O(1)
- Parameters:
key-milliseconds-value-- Returns:
- OK
-
mget
MGet Command Get the values of all the specified keys. If one or more keys don't exist or is not of type String, a 'nil' value is returned instead of the value of the specified key, but the operation never fails.Time complexity: O(1) for every key
- Parameters:
keys-- Returns:
- Multi bulk reply
-
mset
MSet Command Set the the respective keys to the respective values. MSET will replace old values with new values, whileMSETNXwill not perform any operation at all even if just a single key already exists.Because of this semantic MSETNX can be used in order to set different keys representing different fields of an unique logic object in a way that ensures that either all the fields or none at all are set.
Both MSET and MSETNX are atomic operations. This means that for instance if the keys A and B are modified, another connection talking to Redis can either see the changes to both A and B at once, or no modification at all.
- Parameters:
keysvalues- pairs of keys and their values e.g mset("foo", "foovalue", "bar", "barvalue")- Returns:
- OK
-
msetnx
MSetNX Command Set the respective keys to the respective values.MSETwill replace old values with new values, while MSETNX will not perform any operation at all even if just a single key already exists.Because of this semantic MSETNX can be used in order to set different keys representing different fields of an unique logic object in a way that ensures that either all the fields or none at all are set.
Both MSET and MSETNX are atomic operations. This means that for instance if the keys A and B are modified, another connection talking to Redis can either see the changes to both A and B at once, or no modification at all.
- Parameters:
keysvalues- pairs of keys and their values e.g msetnx("foo", "foovalue", "bar", "barvalue")- Returns:
- 1 if the all the keys were set, 0 if no key was set (at least one key already existed)
-
incr
Incr Command Increment the number stored at key by one. If the key does not exist or contains a value of a wrong type, set the key to the value of "0" before to perform the increment operation.INCR commands are limited to 64 bit signed integers.
Note: this is actually a string operation, that is, in Redis there are not "integer" types. Simply the string stored at the key is parsed as a base 10 64 bit signed integer, incremented, and then converted back as a string.
Time complexity: O(1)
- Parameters:
key- the key to increment- Returns:
- The value of the key after the increment
-
incrBy
IncrBy Command INCRBY work just likeINCRbut instead to increment by 1 the increment is integer.INCR commands are limited to 64 bit signed integers.
Note: this is actually a string operation, that is, in Redis there are not "integer" types. Simply the string stored at the key is parsed as a base 10 64 bit signed integer, incremented, and then converted back as a string.
Time complexity: O(1)
- Parameters:
key- the key to incrementincrement- the value to increment by- Returns:
- The value of the key after the increment
-
incrByFloat
IncrByFloat Command INCRBYFLOAT work just likeincrBy(String, long)INCRBY} but increments by floats instead of integers.INCRBYFLOAT commands are limited to double precision floating point values.
Note: this is actually a string operation, that is, in Redis there are not "double" types. Simply the string stored at the key is parsed as a base double precision floating point value, incremented, and then converted back as a string. There is no DECRYBYFLOAT but providing a negative value will work as expected.
Time complexity: O(1)
- Parameters:
key- the key to incrementincrement- the value to increment by- Returns:
- The value of the key after the increment
-
decr
Decr Command Decrement the number stored at key by one. If the key does not exist or contains a value of a wrong type, set the key to the value of "0" before to perform the decrement operation.DECR commands are limited to 64 bit signed integers.
Note: this is actually a string operation, that is, in Redis there are not "integer" types. Simply the string stored at the key is parsed as a base 10 64 bit signed integer, incremented, and then converted back as a string.
Time complexity: O(1)
- Parameters:
key- the key to decrement- Returns:
- The value of the key after the decrement
-
decrBy
DecrBy Command DECRBY work just likeDECRbut instead to decrement by 1 the decrement is integer.DECRBY commands are limited to 64 bit signed integers.
Note: this is actually a string operation, that is, in Redis there are not "integer" types. Simply the string stored at the key is parsed as a base 10 64 bit signed integer, incremented, and then converted back as a string.
Time complexity: O(1)
- Parameters:
key- the key to decrementdecrement- the value to decrement by- Returns:
- The value of the key after the decrement
-
append
Append Command If the key already exists and is a string, this command appends the provided value at the end of the string. If the key does not exist it is created and set as an empty string, so APPEND will be very similar to SET in this special case.Time complexity: O(1). The amortized time complexity is O(1) assuming the appended value is small and the already present value is of any size, since the dynamic string library used by Redis will double the free space available on every reallocation.
- Parameters:
key- the key to append tovalue- the value to append- Returns:
- The total length of the string after the append operation.
-
substr
SubStr Command Return a subset of the string from offset start to offset end (both offsets are inclusive). Negative offsets can be used in order to provide an offset starting from the end of the string. So -1 means the last char, -2 the penultimate and so forth.The function handles out of range requests without raising an error, but just limiting the resulting range to the actual length of the string.
Time complexity: O(start+n) (with start being the start index and n the total length of the requested range). Note that the lookup part of this command is O(1) so for small strings this is actually an O(1) command.
- Parameters:
key-start-end-- Returns:
- The substring
-
strlen
StrLen Command Return the length of the string value stored at key.- Parameters:
key-- Returns:
- The length of the string at key, or 0 when key does not exist
-
strAlgoLCSKeys
Deprecated.STRALGO LCS command will be removed from Redis 7.LCScan be used instead of this method.Calculate the longest common subsequence of keyA and keyB.- Parameters:
keyA-keyB-params-- Returns:
- According to StrAlgoLCSParams to decide to return content to fill LCSMatchResult.
-
lcs
Calculate the longest common subsequence of keyA and keyB.- Parameters:
keyA-keyB-params-- Returns:
- According to LCSParams to decide to return content to fill LCSMatchResult.
-