public interface StringCommands extends BitCommands
Modifier and Type | Method and Description |
---|---|
long |
append(java.lang.String key,
java.lang.String value)
Append Command
If the key already exists and is a string, this command appends the provided value at the end
of the string.
|
long |
decr(java.lang.String key)
Decr Command
Decrement the number stored at key by one.
|
long |
decrBy(java.lang.String key,
long decrement)
DecrBy Command
DECRBY work just like
DECR but instead to decrement by 1 the
decrement is integer. |
java.lang.String |
get(java.lang.String key)
Get Command
Get the value of the specified key.
|
java.lang.String |
getDel(java.lang.String key)
GetDel Command
Get the value of key and delete the key.
|
java.lang.String |
getEx(java.lang.String key,
GetExParams params)
GetEx Command
Get the value of key and optionally set its expiration.
|
java.lang.String |
getrange(java.lang.String key,
long startOffset,
long endOffset)
GetRange Command
Return the substring of the string value stored at key, determined by the offsets start
and end (both are inclusive).
|
java.lang.String |
getSet(java.lang.String key,
java.lang.String value)
Deprecated.
|
long |
incr(java.lang.String key)
Incr Command
Increment the number stored at key by one.
|
long |
incrBy(java.lang.String key,
long increment)
IncrBy Command
INCRBY work just like
INCR but instead to increment by 1 the
increment is integer. |
double |
incrByFloat(java.lang.String key,
double increment)
IncrByFloat Command
INCRBYFLOAT work just like
incrBy(String, long) INCRBY} but increments by floats
instead of integers. |
LCSMatchResult |
lcs(java.lang.String keyA,
java.lang.String keyB,
LCSParams params)
Calculate the longest common subsequence of keyA and keyB.
|
java.util.List<java.lang.String> |
mget(java.lang.String... keys)
MGet Command
Get the values of all the specified keys.
|
java.lang.String |
mset(java.lang.String... keysvalues)
MSet Command
Set the respective keys to the respective values.
|
long |
msetnx(java.lang.String... keysvalues)
MSetNX Command
Set the respective keys to the respective values.
|
java.lang.String |
psetex(java.lang.String key,
long milliseconds,
java.lang.String value)
PSetEx Command
PSETEX works exactly like
SETEX with the sole difference
that the expire time is specified in milliseconds instead of seconds. |
java.lang.String |
set(java.lang.String key,
java.lang.String value)
Set Command
Set the string value as value of the key.
|
java.lang.String |
set(java.lang.String key,
java.lang.String value,
SetParams params)
Set Command
Set the string value as value of the key.
|
java.lang.String |
setex(java.lang.String key,
long seconds,
java.lang.String value)
|
java.lang.String |
setGet(java.lang.String key,
java.lang.String value) |
java.lang.String |
setGet(java.lang.String key,
java.lang.String value,
SetParams params) |
long |
setnx(java.lang.String key,
java.lang.String value)
SetNE Command
SETNX works exactly like
SET with the only difference that if
the key already exists no operation is performed. |
long |
setrange(java.lang.String key,
long offset,
java.lang.String value)
SetRange Command
GETRANGE overwrite part of the string stored at key, starting at the specified offset, for the entire
length of value.
|
long |
strlen(java.lang.String key)
StrLen Command
Return the length of the string value stored at key.
|
java.lang.String |
substr(java.lang.String key,
int start,
int end)
SubStr Command
Return a subset of the string from offset start to offset end (both offsets are inclusive).
|
java.lang.String set(java.lang.String key, java.lang.String value)
Time complexity: O(1)
key
- value
- java.lang.String set(java.lang.String key, java.lang.String value, SetParams params)
Time complexity: O(1)
key
- value
- params
- SetParams
OK
if SET
was executed correctly, or null
if the SET
operation was not performed because the user specified the NX or XX option
but the condition was not met.java.lang.String get(java.lang.String key)
Time complexity: O(1)
key
- java.lang.String setGet(java.lang.String key, java.lang.String value)
java.lang.String setGet(java.lang.String key, java.lang.String value, SetParams params)
java.lang.String getDel(java.lang.String key)
Time complexity: O(1)
key
- java.lang.String getEx(java.lang.String key, GetExParams params)
GET
,
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)
key
- params
- GetExParams
long setrange(java.lang.String key, long offset, java.lang.String value)
Time complexity: O(1)
key
- offset
- value
- java.lang.String getrange(java.lang.String key, long startOffset, long endOffset)
Time complexity: O(N) where N is the length of the returned string
key
- startOffset
- endOffset
- @Deprecated java.lang.String getSet(java.lang.String key, java.lang.String value)
setGet(java.lang.String, java.lang.String)
.Time complexity: O(1)
key
- value
- long setnx(java.lang.String key, java.lang.String value)
SET
with the only difference that if
the key already exists no operation is performed. SETNX actually means "SET if Not Exists".
Time complexity: O(1)
key
- value
- java.lang.String setex(java.lang.String key, long seconds, java.lang.String value)
SET
+ EXPIRE
.
The operation is atomic.
Time complexity: O(1)
key
- seconds
- value
- java.lang.String psetex(java.lang.String key, long milliseconds, java.lang.String value)
SETEX
with the sole difference
that the expire time is specified in milliseconds instead of seconds.
Time complexity: O(1)
key
- milliseconds
- value
- java.util.List<java.lang.String> mget(java.lang.String... keys)
Time complexity: O(1) for every key
keys
- java.lang.String mset(java.lang.String... keysvalues)
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.
keysvalues
- pairs of keys and their values
e.g mset("foo", "foovalue", "bar", "barvalue")long msetnx(java.lang.String... keysvalues)
MSET
will
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.
keysvalues
- pairs of keys and their values
e.g msetnx("foo", "foovalue", "bar", "barvalue")long incr(java.lang.String key)
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)
key
- the key to incrementlong incrBy(java.lang.String key, long increment)
INCR
but 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)
key
- the key to incrementincrement
- the value to increment bydouble incrByFloat(java.lang.String key, double increment)
incrBy(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)
key
- the key to incrementincrement
- the value to increment bylong decr(java.lang.String key)
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)
key
- the key to decrementlong decrBy(java.lang.String key, long decrement)
DECR
but 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)
key
- the key to decrementdecrement
- the value to decrement bylong append(java.lang.String key, java.lang.String value)
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.
key
- the key to append tovalue
- the value to appendjava.lang.String substr(java.lang.String key, int start, int end)
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.
key
- start
- end
- long strlen(java.lang.String key)
key
- LCSMatchResult lcs(java.lang.String keyA, java.lang.String keyB, LCSParams params)
keyA
- keyB
- params
- Copyright © 2025. All rights reserved.