public interface JedisClient
Description: Common interface of operation Redis-server
| 限定符和类型 | 字段和说明 |
|---|---|
static long |
DEFAULT_TIMEOUT |
static String |
RESULT_OK |
static Long |
RESULT_WHEN_EXCEPTION |
static String |
SET_EXPIRE_TIME_MILLISECOND |
static String |
SET_EXPIRE_TIME_SECOND |
static String |
SET_IF_EXIST |
static String |
SET_IF_NOT_EXIST |
| 限定符和类型 | 方法和说明 |
|---|---|
Long |
append(String key,
String value)
If the key already exists and is a string, this command appends the provided value at the end
of the string.
|
Long |
bigCount(String key) |
Long |
bitCount(String key,
long start,
long end) |
List<Long> |
bitField(String key,
String... arguments) |
Long |
bitOp(redis.clients.jedis.BitOP op,
String destKey,
String... srcKeys) |
Long |
decrease(String key)
Decrement the number stored at key by one.
|
Long |
decreaseBy(String key,
long decrement)
Decrement the number stored at key by decrement count.
|
Long |
delete(String... keys)
Delete from redis with keys... .
|
String |
echo(String string)
print string in redis
|
Object |
eval(String script) |
Object |
eval(String script,
int keyCount,
String... params) |
Object |
eval(String script,
List<String> keys,
List<String> args)
Eval a script in lua .
|
Object |
evalSha(String sha1) |
Object |
evalSha(String sha1,
int keyCount,
String... params) |
Object |
evalSha(String sha1,
List<String> keys,
List<String> args) |
Long |
exists(String... keys)
Test if the specified keys exist.
|
Boolean |
exists(String key)
if key exist or not .
|
Long |
expire(String key,
int seconds)
expire key in time of seconds
CMD: TTL seconds
this key will be removed at time after now in seconds. |
Long |
expire(String key,
long timeMillis)
expire key in time of milliseconds
CMD: expire key time
this key will be removed at time after now in seconds. |
Long |
expireAt(String key,
long unixTimestamp)
expire key at time of unix timestamp. it takes an absolute one in the form of a UNIX timestamp (Number of
seconds elapsed since 1 Gen 1970).
|
Long |
geoAdd(String key,
double longitude,
double latitude,
String value)
Add a geo location of value
|
Long |
geoAdd(String key,
Map<String,redis.clients.jedis.GeoCoordinate> memberCoordinateMap) |
Double |
geoDistant(String key,
String source,
String target) |
Double |
geoDistant(String key,
String source,
String target,
redis.clients.jedis.GeoUnit unit) |
List<String> |
geoHash(String key,
String... values) |
List<redis.clients.jedis.GeoCoordinate> |
geoPos(String key,
String... values) |
List<redis.clients.jedis.GeoRadiusResponse> |
geoRadius(String key,
double longitude,
double latitude,
double radius,
redis.clients.jedis.GeoUnit unit)
Find values that distant is in radius with longitude and latitude.
|
List<redis.clients.jedis.GeoRadiusResponse> |
geoRadius(String key,
double longitude,
double latitude,
double radius,
redis.clients.jedis.GeoUnit unit,
redis.clients.jedis.params.GeoRadiusParam param) |
List<redis.clients.jedis.GeoRadiusResponse> |
geoRadiusByMember(String key,
String member,
double radius,
redis.clients.jedis.GeoUnit unit) |
List<redis.clients.jedis.GeoRadiusResponse> |
geoRadiusByMember(String key,
String member,
double radius,
redis.clients.jedis.GeoUnit unit,
redis.clients.jedis.params.GeoRadiusParam param) |
List<redis.clients.jedis.GeoRadiusResponse> |
geoRadiusByMemberReadonly(String key,
String member,
double radius,
redis.clients.jedis.GeoUnit unit) |
List<redis.clients.jedis.GeoRadiusResponse> |
geoRadiusByMemberReadonly(String key,
String member,
double radius,
redis.clients.jedis.GeoUnit unit,
redis.clients.jedis.params.GeoRadiusParam param) |
List<redis.clients.jedis.GeoRadiusResponse> |
geoRadiusReadonly(String key,
double longitude,
double latitude,
double radius,
redis.clients.jedis.GeoUnit unit) |
List<redis.clients.jedis.GeoRadiusResponse> |
geoRadiusReadonly(String key,
double longitude,
double latitude,
double radius,
redis.clients.jedis.GeoUnit unit,
redis.clients.jedis.params.GeoRadiusParam param) |
List<String> |
get(String... keys)
Get the values of all the specified keys.
|
String |
get(String key)
Get value from redis with key.
|
Boolean |
getBit(String key,
long offset)
check if the offset of key is positive.
|
String |
getRange(String key,
long offset,
long endOffset)
get the substring of key that between offset and endOffset.
|
String |
getSet(String key,
String value)
atomic set this value and return the old value command.
|
Long |
increase(String key)
Increment the number stored at key by one.
|
Long |
increaseBy(String key,
long increment)
Increment the number stored at key by increment count.
|
Double |
increaseByFloat(String key,
float increment)
this is actually a string operation, that is, in Redis there are not "double" types.
|
Set<String> |
keys(String pattern)
Get a set of keys that exist in redis match with pattern.
|
List<String> |
listBlockingLeftPop(int timeout,
String... keys)
BLPOP (and BRPOP) is a blocking list pop primitive.
|
List<String> |
listBlockingRightPop(int timeout,
String... keys)
|
String |
listBlockingRightPopLeftPush(String srcKey,
String targetKey,
int timeout)
Pop a value from a list, push it to another list and return it; or block until one is available
|
String |
listIndex(String key,
long index)
Return the specified element of the list stored at the specified key. 0 is the first element, 1
the second and so on.
|
Long |
listInsert(String key,
redis.clients.jedis.ListPosition where,
String anchor,
String value)
Insert a value into list of where with anchor.
|
String |
listLeftPop(String key)
Pop out the HEAD value just push to the list.
|
Long |
listLeftPush(String key,
String... values)
Add the string value to the HEAD of the list.
|
Long |
listLeftPushExist(String key,
String... values)
Add the string value to the HEAD of the list.
|
Long |
listLength(String key)
Return the length of the list stored at the specified key.
|
String |
listPop(String key)
Pop out the value just push to the list.
|
Long |
listPush(String key,
String... values)
Add the string value to the TAIL of the list.
|
List<String> |
listRange(String key,
long start,
long end)
Return the specified elements of the list stored at the specified key.
|
Long |
listRemove(String key,
long count,
String value)
Remove the first count occurrences of the value element from the list.
|
String |
listRightPop(String key)
Pop out the TAIL value just push to the list.
|
String |
listRightPopLeftPush(String srcKey,
String targetKey)
Atomically return and remove the last (tail) element of the srckey list, and push the element
as the first (head) element of the dstkey list.
|
Long |
listRightPush(String key,
String... values)
Add the string value to the TAIL of the list.
|
Long |
listRightPushExist(String key,
String... values)
Add the string value to the TAIL of the list.
|
String |
listSet(String key,
long index,
String value)
Set a new value as the element at index position of the List at key.
|
String |
listTrim(String key,
long start,
long end)
Trim an existing list so that it will contain only the specified range of elements specified.
|
Map<String,String> |
mapAll(String key)
Return all the fields and associated values in a hash.
|
Long |
mapDelete(String key,
String... fields)
Remove the specified field from an hash stored at key.
|
Boolean |
mapExist(String key,
String field)
Test for existence of a specified field in a hash.
|
String |
mapGet(String key,
String field)
If key holds a hash, retrieve the value associated to the specified field.
|
Long |
mapIncreaseBy(String key,
String field,
long value)
Increment the number stored at field in the hash at key by value.
|
Double |
mapIncreaseByFloat(String key,
String field,
float value)
Increment the number stored at field in the hash at key by a double precision floating point
value.
|
Set<String> |
mapKeys(String key)
Return all the fields in a hash.
|
Long |
mapLength(String key)
Get the length of a hash key.
|
List<String> |
mapMultiGet(String key,
String... fields)
Retrieve the values associated to the specified fields.
|
Long |
mapSet(String key,
Map<String,String> map)
Set the specified hash map field to the specified value.
|
Long |
mapSet(String key,
String field,
String value)
Set the specified hash map field to the specified value.
|
Long |
mapSetNx(String key,
String field,
String value)
Set the specified hash field to the specified value if the field not exists.
|
List<String> |
mapValues(String key)
Return all the values in a hash.
|
String |
multiSet(String... keyValues)
set key values into a map structure.
|
Long |
multiSetNx(String... keyValues)
set key values info a map structure only if all keys not exist in map.
|
void |
patternSubscribe(redis.clients.jedis.JedisPubSub jedisPubSub,
String... patterns)
subscribe channels in patterns...
|
Long |
persist(String key)
Undo a
expire at turning the expire key into a normal key. |
Long |
publish(String channel,
String message)
publish message to channel.
|
List<Boolean> |
scriptExists(String... sha1) |
Boolean |
scriptExists(String sha1) |
String |
scriptLoad(String script) |
String |
set(String key,
String value)
Set a value with key with no expire times.
|
String |
set(String key,
String value,
long expireInMillis)
Set value with expire time .
|
String |
set(String key,
String value,
redis.clients.jedis.params.SetParams setParams)
Set value with some options like:
NX: set key only if key not exist
XX: set key only if key exist
PX: set key expire time in milliseconds.
|
Boolean |
setBit(String key,
long offset,
boolean value)
Sets or clears the bit at offset in the string value stored at key
set value:1 00000000000
setbit value:1 2 1
after set value:1 00100000000 |
Boolean |
setBit(String key,
long offset,
String value)
|
Long |
setRange(String key,
long offset,
String value)
cover the string value of key of new value that offset to key.
|
Long |
setsAdd(String key,
String... values)
Add the specified member to the set value stored at key.
|
Long |
setsDelete(String key,
String... values)
Remove the specified member from the set value stored at key.
|
Set<String> |
setsDifferent(String... keys)
Return the difference between the Set stored at key1 and all the Sets key2, ..., keyN
Example:
key1 = [x, a, b, c]
key2 = [c]
key3 = [a, d]
SDIFF key1,key2,key3 => [x, b]
Non existing keys are considered like empty sets.
|
Long |
setsDifferentStore(String destKey,
String... keys)
This command works exactly like
setsDifferent(String...) but instead of being returned
the resulting set is stored in destkey. |
Boolean |
setsExist(String key,
String value)
Return true if member is a member of the set stored at key, otherwise false is returned.
|
Set<String> |
setsInter(String... keys)
Return the members of a set resulting from the intersection of all the sets hold at the
specified keys.
|
Long |
setsInterStore(String destKey,
String... keys)
This command works exactly like
setsInter(String...) |
Long |
setsLength(String key)
Return the set cardinality (number of elements).
|
Long |
setsMove(String srcKey,
String targetKey,
String value)
Move the specified member from the set at srckey to the set at dstkey.
|
String |
setsPop(String key)
Remove a random element from a Set returning it as return value.
|
Set<String> |
setsPop(String key,
long count)
Remove a random element from a Set returning it as return value.
|
String |
setsRandomValue(String key)
Return a random element from a Set, without removing the element.
|
List<String> |
setsRandomValue(String key,
int count)
Return a count of random elements from a Set, without removing the element.
|
Set<String> |
setsUnion(String... keys)
Return the members of a set resulting from the union of all the sets hold at the specified
keys.
|
Long |
setsUnionStore(String destKey,
String... keys)
This command works exactly like
setsUnion(String...) |
Set<String> |
setsValues(String key)
Return all the members (elements) of the set value stored at key.
|
List<String> |
sort(String key)
Sort a Set or a List.
|
List<String> |
sort(String key,
redis.clients.jedis.SortingParams sortingParameters)
Sort a Set or a List accordingly to the specified parameters.
|
Long |
sortStore(String key,
redis.clients.jedis.SortingParams sortingParameters,
String destKey)
Sort a Set or a List and Store the Result at dstkey.
|
Long |
sortStore(String key,
String destKey)
Sort a Set or a List and Store the Result at dstkey.
|
void |
subscribe(redis.clients.jedis.JedisPubSub jedisPubSub,
String... channels)
subscribe channels ..
|
String |
subString(String key,
int start,
int end)
Return a subset of the string from offset start to offset end (both offsets are inclusive).
|
Long |
touch(String... keys)
Alters the last access time of a key(s).
|
Long |
ttl(String key)
Get the remaining time to live in seconds of a key.
|
String |
type(String key)
get the type of this key.
|
Long |
zsetAdd(String key,
double score,
String value)
Add the specified member having the specified score to the sorted set stored at key.
|
Long |
zsetAdd(String key,
double score,
String value,
redis.clients.jedis.params.ZAddParams params)
Add the specified member having the specified score to the sorted set stored at key.
|
Long |
zsetAdd(String key,
Map<String,Double> valueScores)
Add the specified member having the specified score to the sorted set stored at key.
|
Long |
zsetAdd(String key,
Map<String,Double> valueScores,
redis.clients.jedis.params.ZAddParams params)
Add the specified member having the specified score to the sorted set stored at key.
|
Long |
zsetDelete(String key,
String... values)
Remove the specified member from the sorted set value stored at key.
|
Long |
zsetDeleteRangeByIndex(String key,
long start,
long stop)
Remove all elements in the sorted set at key with rank between start and end.
|
Long |
zsetDeleteRangeByLex(String key,
String min,
String max) |
Long |
zsetDeleteRangeByScore(String key,
double min,
double max)
Remove all the elements in the sorted set at key with a score between min and max (including
elements with score equal to min or max).
|
Long |
zsetDeleteRangeByScore(String key,
String min,
String max)
|
Double |
zsetIncreaseBy(String key,
double increment,
String value)
If member already exists in the sorted set adds the increment to its score and updates the
position of the element in the sorted set accordingly.
|
Double |
zsetIncreaseBy(String key,
double increment,
String value,
redis.clients.jedis.params.ZIncrByParams params)
If member already exists in the sorted set adds the increment to its score and updates the
position of the element in the sorted set accordingly.
|
Long |
zsetIndexOf(String key,
String value)
Return the rank (or index) of member in the sorted set at key, with scores being ordered from
low to high.
|
Long |
zsetInterStore(String destKey,
String... keys)
Creates a union or intersection of N sorted sets given by keys k1 through kN, and stores it at
dstkey.
|
Long |
zsetInterStore(String destKey,
redis.clients.jedis.ZParams params,
String... keys)
Creates a union or intersection of N sorted sets given by keys k1 through kN, and stores it at
dstkey.
|
Long |
zsetLength(String key)
Return the sorted set cardinality (number of elements).
|
Long |
zsetLexLength(String key,
String min,
String max)
Return count of set values that lex value between min and max
such as:
a -> z
|
Set<String> |
zsetRange(String key,
long start,
long end)
Return a range of zset . this function such as
listRange(String, long, long) |
Set<String> |
zsetRangeByLex(String key,
String min,
String max)
|
Set<String> |
zsetRangeByLex(String key,
String min,
String max,
int offset,
int count) |
Set<String> |
zsetRangeByScore(String key,
double min,
double max)
Return the all the elements in the sorted set at key with a score between min and max
(including elements with score equal to min or max).
|
Set<String> |
zsetRangeByScore(String key,
double min,
double max,
int offset,
int count)
Return the all the elements in the sorted set at key with a score between min and max
(including elements with score equal to min or max).
|
Set<String> |
zsetRangeByScore(String key,
String min,
String max)
|
Set<String> |
zsetRangeByScore(String key,
String min,
String max,
int offset,
int count)
|
Set<redis.clients.jedis.Tuple> |
zsetRangeByScoreWithScores(String key,
double min,
double max)
Return the all the elements in the sorted set at key with a score between min and max
(including elements with score equal to min or max).
|
Set<redis.clients.jedis.Tuple> |
zsetRangeByScoreWithScores(String key,
double min,
double max,
int offset,
int count)
|
Set<redis.clients.jedis.Tuple> |
zsetRangeByScoreWithScores(String key,
String min,
String max)
|
Set<redis.clients.jedis.Tuple> |
zsetRangeByScoreWithScores(String key,
String min,
String max,
int offset,
int count)
|
Set<redis.clients.jedis.Tuple> |
zsetRangeWithScores(String key,
long start,
long end)
return range of zset.
|
Long |
zsetReverseIndexOf(String key,
String value)
Return the rank (or index) of member in the sorted set at key, with scores being ordered from
high to low.
|
Set<String> |
zsetReverseRange(String key,
long start,
long end)
return reverse range of zset.
|
Set<String> |
zsetReverseRangeByLex(String key,
String min,
String max) |
Set<String> |
zsetReverseRangeByLex(String key,
String min,
String max,
int offset,
int count) |
Set<String> |
zsetReverseRangeByScore(String key,
double min,
double max)
|
Set<String> |
zsetReverseRangeByScore(String key,
double min,
double max,
int offset,
int count) |
Set<String> |
zsetReverseRangeByScore(String key,
String min,
String max) |
Set<String> |
zsetReverseRangeByScore(String key,
String min,
String max,
int offset,
int count) |
Set<redis.clients.jedis.Tuple> |
zsetReverseRangeByScoreWithScores(String key,
double min,
double max) |
Set<redis.clients.jedis.Tuple> |
zsetReverseRangeByScoreWithScores(String key,
double min,
double max,
int offset,
int count) |
Set<redis.clients.jedis.Tuple> |
zsetReverseRangeByScoreWithScores(String key,
String min,
String max) |
Set<redis.clients.jedis.Tuple> |
zsetReverseRangeByScoreWithScores(String key,
String min,
String max,
int offset,
int count) |
Set<redis.clients.jedis.Tuple> |
zsetReverseRangeWithScores(String key,
long start,
long end)
return reverse range of zset.
|
Double |
zsetScore(String key,
String value)
Return the score of the specified element of the sorted set at key.
|
Long |
zsetUnionStore(String destKey,
String... keys)
Creates a union or intersection of N sorted sets given by keys k1 through kN, and stores it at
dstkey.
|
Long |
zsetUnionStore(String destKey,
redis.clients.jedis.ZParams params,
String... keys)
Creates a union or intersection of N sorted sets given by keys k1 through kN, and stores it at
dstkey.
|
static final Long RESULT_WHEN_EXCEPTION
static final long DEFAULT_TIMEOUT
String set(String key, String value)
set("key","value")
The string can't be longer than 1073741824 bytes (1GB).
And this will return RESULT_OK if succeed.key - keyvalue - valueString set(String key, String value, long expireInMillis)
set(String, String, SetParams)
set(key, value, SetParams.setParams().px(expireInMillis))
And this will return RESULT_OK if succeed.key - keyvalue - valueexpireInMillis - expire time in millisecondsString set(String key, String value, redis.clients.jedis.params.SetParams setParams)
SetParams param = SetParams.setParams().nx().px(123L);
And this will return RESULT_OK if succeed.key - keyvalue - valuesetParams - paramsString multiSet(String... keyValues)
keyValues - key value pairsLong multiSetNx(String... keyValues)
keyValues - String get(String key)
key - keyList<String> get(String... keys)
keys - keys to getLong exists(String... keys)
keys - keys to be testBoolean exists(String key)
key - key to be testLong expire(String key, int seconds)
CMD: TTL seconds
this key will be removed at time after now in seconds.
return :
1: the timeout was set.
0: the timeout was not set since the key already has an associated timeout
(this may happen only in Redis versions < 2.1.3, Redis >= 2.1.3 will
happily update the timeout), or the key does not exist.key - keyseconds - time in secondsLong expire(String key, long timeMillis)
CMD: expire key time
this key will be removed at time after now in seconds.
return :
1: the timeout was set.
0: the timeout was not set since the key already has an associated timeout
(this may happen only in Redis versions < 2.1.3, Redis >= 2.1.3 will
happily update the timeout), or the key does not exist.key - keytimeMillis - time in millisecondsLong expireAt(String key, long unixTimestamp)
key - keyunixTimestamp - timestampLong persist(String key)
expire at turning the expire key into a normal key.key - keyLong ttl(String key)
key - String echo(String string)
string - string to echoLong delete(String... keys)
jedis.unlink(keys) CMD: unlink ...
more. see Jedis
or JedisClusterkeys - keys to be removedString type(String key)
key - keySet<String> keys(String pattern)
pattern - pattern of keysLong touch(String... keys)
keys - keys to be touchString getSet(String key, String value)
key - keyvalue - new value of keyLong increase(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.
key - keyLong increaseBy(String key, long increment)
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.
key - keyincrement - increment countLong decrease(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, decremented, and then converted back as a string.
key - keyLong decreaseBy(String key, long decrement)
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, decremented, and then converted back as a string.
key - keydecrement - increment countDouble increaseByFloat(String key, float increment)
key - keyincrement - incrementLong append(String key, String value)
key - keyvalue - valueString subString(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.
key - keystart - start indexend - end indexBoolean setBit(String key, long offset, boolean value)
set value:1 00000000000
setbit value:1 2 1
after set value:1 00100000000key - keyoffset - offsetvalue - bit valueBoolean setBit(String key, long offset, String value)
key - keyoffset - offsetvalue - bit valueBoolean getBit(String key, long offset)
setBit(String, long, String)key - keyoffset - offsetLong setRange(String key, long offset, String value)
set 4 "FOO"
become"Hello FOO"
Do nothing if key not exist.key - keyoffset - offset to covervalue - new valueString getRange(String key, long offset, long endOffset)
key - keyoffset - start offset of stringendOffset - end offset of stringLong mapSet(String key, String field, String value)
key - key to hold this hash mapfield - field namevalue - valueLong mapSet(String key, Map<String,String> map)
CMD: HMSET key values...
returns:
key - keymap - value mapLong mapSetNx(String key, String field, String value)
key - keyfield - fieldvalue - valueLong mapIncreaseBy(String key, String field, long value)
key - keyfield - fieldvalue - increment.Double mapIncreaseByFloat(String key, String field, float value)
key - hash keyfield - fieldvalue - float incrementString mapGet(String key, String field)
key - keyfield - fieldList<String> mapMultiGet(String key, String... fields)
key - keyfields - fields to requestLong mapLength(String key)
key - hash keyBoolean mapExist(String key, String field)
key - keyfield - fieldSet<String> mapKeys(String key)
key - hash keyList<String> mapValues(String key)
key - hash keyMap<String,String> mapAll(String key)
key - hash keyLong mapDelete(String key, String... fields)
key - keyfields - fields to be removedLong listPush(String key, String... values)
listRightPush(String, String...)
If the key does not exist an empty list is created just before the append operation.
If the key exists but is not a List an error is returned.key - keyvalues - values to be pushLong listInsert(String key, redis.clients.jedis.ListPosition where, String anchor, String value)
ListPosition.BEFORE "FOO" will display as "VALUE" "FOO"
ListPosition.AFTER "FOO" will display as "FOO" "VALUE"
if key of list or anchor does not exist . do nothing.
return total size of list after operation.key - key of listwhere - position ListPositionanchor - anchor valuevalue - valueLong listRightPush(String key, String... values)
key - keyvalues - values to be pushLong listRightPushExist(String key, String... values)
key - keyvalues - values to be pushLong listLeftPush(String key, String... values)
key - keyvalues - values to be pushLong listLeftPushExist(String key, String... values)
key - keyvalues - values to be pushLong listLength(String key)
key - list keyList<String> listRange(String key, long start, long end)
For example LRANGE foobar 0 2 will return the first three elements of the list.
start and end can also be negative numbers indicating offsets from the end of the list. For example -1 is the last element of the list, -2 the penultimate element and so on.
Consistency with range functions in various programming languages
Note that if you have a list of numbers from 0 to 100, LRANGE 0 10 will return 11 elements, that is, rightmost item is included. This may or may not be consistent with behavior of range-related functions in your programming language of choice (think Ruby's Range.new, Array#slice or Python's range() function).
LRANGE behavior is consistent with one of Tcl.
Out-of-range indexes
Indexes out of range will not produce an error: if start is over the end of the list, or start > end, an empty list is returned. If end is over the end of the list Redis will threat it just like the last element of the list.
key - list keystart - start indexend - end index.String listTrim(String key, long start, long end)
For example LTRIM foobar 0 2 will modify the list stored at foobar key so that only the first three elements of the list will remain.
start and end can also be negative numbers indicating offsets from the end of the list. For example -1 is the last element of the list, -2 the penultimate element and so on.
Indexes out of range will not produce an error: if start is over the end of the list, or start > end, an empty list is left as value. If end over the end of the list Redis will threat it just like the last element of the list.
Hint: the obvious use of LTRIM is together with LPUSH/RPUSH. For example:
lpush("mylist", "someelement"); ltrim("mylist", 0, 99); *
The above two commands will push elements in the list taking care that the list will not grow without limits. This is very useful when using Redis to store logs for example. It is important to note that when used in this way LTRIM is an O(1) operation because in the average case just one element is removed from the tail of the list.
key - list keystart - start indexend - end index.String listIndex(String key, long index)
If the value stored at key is not of list type an error is returned. If the index is out of range a 'nil' reply is returned.
Note that even if the average time complexity is O(n) asking for the first or the last element of the list is O(1).
key - list keyindex - indexString listSet(String key, long index, String value)
Out of range indexes will generate an error.
Similarly to other list commands accepting indexes, the index can be negative to access elements starting from the end of the list. So -1 is the last element, -2 is the penultimate, and so forth.
key - list keyindex - indexvalue - valueLong listRemove(String key, long count, String value)
key - list keycount - count to be removedvalue - value to be removedString listPop(String key)
listPush(String, String...)
If the key does not exist or the list is already empty the special value 'nil' is returned.key - list keyString listRightPop(String key)
listPush(String, String...)
If the key does not exist or the list is already empty the special value 'nil' is returned.key - list keyString listLeftPop(String key)
listPush(String, String...)
If the key does not exist or the list is already empty the special value 'nil' is returned.key - list keyString listRightPopLeftPush(String srcKey, String targetKey)
If the key does not exist or the list is already empty the special value 'nil' is returned. If the srckey and dstkey are the same the operation is equivalent to removing the last element from the list and pushing it as first element of the list, so it's a "list rotation" command.
srcKey - source keytargetKey - target keyString listBlockingRightPopLeftPush(String srcKey, String targetKey, int timeout)
srcKey - source keytargetKey - target keytimeout - timeout count.List<String> listBlockingLeftPop(int timeout, String... keys)
The following is a description of the exact semantic. We describe BLPOP but the two commands are identical, the only difference is that BLPOP pops the element from the left (head) of the list, and BRPOP pops from the right (tail).
Non blocking behavior
When BLPOP is called, if at least one of the specified keys contain a non empty list, an element is popped from the head of the list and returned to the caller together with the name of the key (BLPOP returns a two elements array, the first element is the key, the second the popped value).
Keys are scanned from left to right, so for instance if you issue BLPOP list1 list2 list3 0 against a dataset where list1 does not exist but list2 and list3 contain non empty lists, BLPOP guarantees to return an element from the list stored at list2 (since it is the first non empty list starting from the left).
Blocking behavior
If none of the specified keys exist or contain non empty lists, BLPOP blocks until some other client performs a LPUSH or an RPUSH operation against one of the lists.
Once new data is present on one of the lists, the client finally returns with the name of the key unblocking it and the popped value.
When blocking, if a non-zero timeout is specified, the client will unblock returning a nil special value if the specified amount of seconds passed without a push operation against at least one of the specified keys.
The timeout argument is interpreted as an integer value. A timeout of zero means instead to block forever.
Multiple clients blocking for the same keys
Multiple clients can block for the same key. They are put into a queue, so the first to be served will be the one that started to wait earlier, in a first-blpopping first-served fashion.
blocking POP inside a MULTI/EXEC transaction
BLPOP and BRPOP can be used with pipelining (sending multiple commands and reading the replies in batch), but it does not make sense to use BLPOP or BRPOP inside a MULTI/EXEC block (a Redis transaction).
The behavior of BLPOP inside MULTI/EXEC when the list is empty is to return a multi-bulk nil reply, exactly what happens when the timeout is reached. If you like science fiction, think at it like if inside MULTI/EXEC the time will flow at infinite speed :)
timeout - time outkeys - keysList<String> listBlockingRightPop(int timeout, String... keys)
timeout - timeoutkeys - keysLong setsAdd(String key, String... values)
key - set keyvalues - Set<String> setsValues(String key)
key - set keyLong setsDelete(String key, String... values)
key - set keyvalues - values to be removedString setsPop(String key)
setsPop(String, long)key - keySet<String> setsPop(String key, long count)
key - set keycount - value count to be popLong setsLength(String key)
key - keyLong setsMove(String srcKey, String targetKey, String value)
If the source set does not exist or does not contain the specified element no operation is performed and zero is returned, otherwise the element is removed from the source set and added to the destination set. On success one is returned, even if the element was already present in the destination set.
An error is raised if the source or destination keys contain a non Set value.
returns:
srcKey - source keytargetKey - target keyvalue - value to be movedBoolean setsExist(String key, String value)
key - keyvalue - valueSet<String> setsInter(String... keys)
listRange(String, long, long) (String, long, long) LRANGE}
the result is sent to the client as a multi-bulk reply (see the protocol specification for more information).
If just a single key is specified, then this command produces the same result as
setsValues(String) (String) SMEMBERS}. Actually SMEMBERS is just syntax sugar for SINTER.
Non existing keys are considered like empty sets, so if one of the keys is missing an empty set is returned (since the intersection with an empty set always is an empty set).
keys - set keysLong setsInterStore(String destKey, String... keys)
setsInter(String...) SINTER} but instead of being returned
the resulting set is stored as dstkey.
destKey - target keykeys - source keysSet<String> setsUnion(String... keys)
listRange(String, long, long) LRANGE} the result is sent to the client as a
multi-bulk reply (see the protocol specification for more information). If just a single key is
specified, then this command produces the same result as setsValues(String) SMEMBERS}.
Non existing keys are considered like empty sets.
keys - set keysLong setsUnionStore(String destKey, String... keys)
setsUnion(String...) SUNION} but instead of being returned
the resulting set is stored as dstkey. Any existing value in dstkey will be over-written.
destKey - dest keykeys - keysSet<String> setsDifferent(String... keys)
Example:
key1 = [x, a, b, c] key2 = [c] key3 = [a, d] SDIFF key1,key2,key3 => [x, b]Non existing keys are considered like empty sets.
keys - key1 to keys all.Long setsDifferentStore(String destKey, String... keys)
setsDifferent(String...) but instead of being returned
the resulting set is stored in destkey.destKey - dest keykeys - keysString setsRandomValue(String key)
key - set keyList<String> setsRandomValue(String key, int count)
key - set keycount - value countLong zsetAdd(String key, double score, String value)
The score value can be the string representation of a double precision floating point number. returns:
key - keyscore - sort score of this valuevalue - valueLong zsetAdd(String key, double score, String value, redis.clients.jedis.params.ZAddParams params)
key - keyscore - the score of valuevalue - value of scoreparams - set paramsLong zsetAdd(String key, Map<String,Double> valueScores)
key - keyvalueScores - value score pairLong zsetAdd(String key, Map<String,Double> valueScores, redis.clients.jedis.params.ZAddParams params)
key - keyvalueScores - value score pairparams - add paramSet<String> zsetRange(String key, long start, long end)
listRange(String, long, long)key - set keystart - start indexend - end index.Long zsetDelete(String key, String... values)
key - zset keyvalues - valuesDouble zsetIncreaseBy(String key, double increment, String value)
The score value can be the string representation of a double precision floating point number. It's possible to provide a negative value to perform a decrement.
For an introduction to sorted sets check the Introduction to Redis data types page.
key - set keyincrement - incrementvalue - valueDouble zsetIncreaseBy(String key, double increment, String value, redis.clients.jedis.params.ZIncrByParams params)
The score value can be the string representation of a double precision floating point number. It's possible to provide a negative value to perform a decrement.
For an introduction to sorted sets check the Introduction to Redis data types page.
key - set keyincrement - incrementvalue - valueparams - incrBy paramsLong zsetIndexOf(String key, String value)
When the given member does not exist in the sorted set, the special value 'nil' is returned. The returned rank (or index) of the member is 0-based for both commands.
key - zset keyvalue - zset valueLong zsetReverseIndexOf(String key, String value)
When the given member does not exist in the sorted set, the special value 'nil' is returned. The returned rank (or index) of the member is 0-based for both commands.
key - zset keyvalue - zset valueSet<String> zsetReverseRange(String key, long start, long end)
zsetRange(String, long, long)key - zset keystart - start indexend - end indexLong zsetLength(String key)
key - keyDouble zsetScore(String key, String value)
key - zset keyvalue - zset valueSet<redis.clients.jedis.Tuple> zsetRangeWithScores(String key, long start, long end)
zsetRange(String, long, long)
witch is contain in Tuple with element and score.key - zset keystart - start indexend - end indexSet<String> zsetRangeByScore(String key, double min, double max)
The elements having the same score are returned sorted lexicographically as ASCII strings (this follows from a property of Redis sorted sets and does not involve further computation).
Using the optional zsetRangeByScore(String, double, double) LIMIT} it's possible
to get only a range of the matching elements in an SQL-alike way. Note that if offset is large
the commands needs to traverse the list for offset elements and this adds up to the O(M)
figure.
The command is similar to
zsetRangeByScore(String, double, double)ZRANGEBYSCORE} but instead of returning the
actual elements in the specified interval, it just returns the number of matching elements.
Exclusive intervals and infinity
min and max can be -inf and +inf, so that you are not required to know what's the greatest or smallest element in order to take, for instance, elements "up to a given value".
Also while the interval is for default closed (inclusive) it's possible to specify open intervals prefixing the score with a "(" character, so for instance:
ZRANGEBYSCORE zset (1.3 5
Will return all the values with score > 1.3 and <= 5, while for instance:
ZRANGEBYSCORE zset (5 (10
Will return all the values with score > 5 and < 10 (5 and 10 excluded).
key - set keymin - min scoremax - max scorezsetRangeByScore(String, double, double),
zsetRangeByScore(String, double, double, int, int),
zsetRangeByScoreWithScores(String, double, double),
zsetRangeByScoreWithScores(String, double, double, int, int)Set<String> zsetRangeByScore(String key, String min, String max)
key - set keymin - min scoremax - max scoreSet<String> zsetRangeByScore(String key, double min, double max, int offset, int count)
The elements having the same score are returned sorted lexicographically as ASCII strings (this follows from a property of Redis sorted sets and does not involve further computation).
Using the optional LIMIT it's possible
to get only a range of the matching elements in an SQL-alike way. Note that if offset is large
the commands needs to traverse the list for offset elements and this adds up to the O(M)
figure.
The command is similar to
ZRANGEBYSCORE but instead of returning the
actual elements in the specified interval, it just returns the number of matching elements.
Exclusive intervals and infinity
min and max can be -inf and +inf, so that you are not required to know what's the greatest or smallest element in order to take, for instance, elements "up to a given value".
Also while the interval is for default closed (inclusive) it's possible to specify open intervals prefixing the score with a "(" character, so for instance:
ZRANGEBYSCORE zset (1.3 5
Will return all the values with score > 1.3 and <= 5, while for instance:
ZRANGEBYSCORE zset (5 (10
Will return all the values with score > 5 and < 10 (5 and 10 excluded).
key - set keymin - min scoremax - max scoreoffset - offset indexcount - count of setSet<String> zsetRangeByScore(String key, String min, String max, int offset, int count)
key - set keymin - min scoremax - max scoreoffset - offset indexcount - count of setSet<redis.clients.jedis.Tuple> zsetRangeByScoreWithScores(String key, double min, double max)
The elements having the same score are returned sorted lexicographically as ASCII strings (this follows from a property of Redis sorted sets and does not involve further computation).
Using the optional zsetRangeByScore(String, String, String, int, int) it's possible
to get only a range of the matching elements in an SQL-alike way. Note that if offset is large
the commands needs to traverse the list for offset elements and this adds up to the O(M)
figure.
The command is similar to
ZRANGEBYSCORE but instead of returning the
actual elements in the specified interval, it just returns the number of matching elements.
Exclusive intervals and infinity
min and max can be -inf and +inf, so that you are not required to know what's the greatest or smallest element in order to take, for instance, elements "up to a given value".
Also while the interval is for default closed (inclusive) it's possible to specify open intervals prefixing the score with a "(" character, so for instance:
ZRANGEBYSCORE zset (1.3 5
Will return all the values with score > 1.3 and <= 5, while for instance:
ZRANGEBYSCORE zset (5 (10
Will return all the values with score > 5 and < 10 (5 and 10 excluded).
key - keymin - min scoremax - max scoreSet<redis.clients.jedis.Tuple> zsetRangeByScoreWithScores(String key, String min, String max)
key - keymin - min scoremax - max scoreSet<redis.clients.jedis.Tuple> zsetRangeByScoreWithScores(String key, double min, double max, int offset, int count)
zsetRangeByScoreWithScores(String, String, String)
zsetRangeByScore(String, double, double, int ,int)key - keymin - min scoremax - max scoreSet<redis.clients.jedis.Tuple> zsetRangeByScoreWithScores(String key, String min, String max, int offset, int count)
zsetRangeByScoreWithScores(String, String, String)
zsetRangeByScore(String, double, double, int ,int)key - keymin - min scoremax - max scoreSet<redis.clients.jedis.Tuple> zsetReverseRangeWithScores(String key, long start, long end)
zsetRange(String, long, long)
witch is contain in Tuple with element and score.key - zset keystart - start indexend - end indexSet<String> zsetReverseRangeByScore(String key, double min, double max)
key - keymin - minmax - maxSet<String> zsetReverseRangeByScore(String key, double min, double max, int offset, int count)
Set<String> zsetReverseRangeByScore(String key, String min, String max, int offset, int count)
Set<redis.clients.jedis.Tuple> zsetReverseRangeByScoreWithScores(String key, double min, double max)
Set<redis.clients.jedis.Tuple> zsetReverseRangeByScoreWithScores(String key, String min, String max)
Set<redis.clients.jedis.Tuple> zsetReverseRangeByScoreWithScores(String key, double min, double max, int offset, int count)
Set<redis.clients.jedis.Tuple> zsetReverseRangeByScoreWithScores(String key, String min, String max, int offset, int count)
Long zsetDeleteRangeByIndex(String key, long start, long stop)
key - set keystart - start indexstop - end indexLong zsetDeleteRangeByScore(String key, double min, double max)
key - keymin - minmax - maxLong zsetDeleteRangeByScore(String key, String min, String max)
key - keymin - minmax - maxLong zsetUnionStore(String destKey, String... keys)
As the terms imply, the ZINTERSTORE command requires an
element to be present in each of the given inputs to be inserted in the result. The
ZUNIONSTORE command inserts all elements across all
inputs.
Using the WEIGHTS option, it is possible to add weight to each input sorted set. This means that the score of each element in the sorted set is first multiplied by this weight before being passed to the aggregation. When this option is not given, all weights default to 1.
With the AGGREGATE option, it's possible to specify how the results of the union or intersection are aggregated. This option defaults to SUM, where the score of an element is summed across the inputs where it exists. When this option is set to be either MIN or MAX, the resulting set will contain the minimum or maximum score of an element across the inputs where it exists.
destKey - target keykeys - source set's keysLong zsetUnionStore(String destKey, redis.clients.jedis.ZParams params, String... keys)
As the terms imply, the ZINTERSTORE command requires an
element to be present in each of the given inputs to be inserted in the result. The
ZUNIONSTORE command inserts all elements across all
inputs.
Using the WEIGHTS option, it is possible to add weight to each input sorted set. This means that the score of each element in the sorted set is first multiplied by this weight before being passed to the aggregation. When this option is not given, all weights default to 1.
With the AGGREGATE option, it's possible to specify how the results of the union or intersection are aggregated. This option defaults to SUM, where the score of an element is summed across the inputs where it exists. When this option is set to be either MIN or MAX, the resulting set will contain the minimum or maximum score of an element across the inputs where it exists.
destKey - target keyparams - set paramskeys - source set's keysLong zsetInterStore(String destKey, String... keys)
As the terms imply, the ZINTERSTORE command requires an
element to be present in each of the given inputs to be inserted in the result. The
ZUNIONSTORE command inserts all elements across all
inputs.
Using the WEIGHTS option, it is possible to add weight to each input sorted set. This means that the score of each element in the sorted set is first multiplied by this weight before being passed to the aggregation. When this option is not given, all weights default to 1.
With the AGGREGATE option, it's possible to specify how the results of the union or intersection are aggregated. This option defaults to SUM, where the score of an element is summed across the inputs where it exists. When this option is set to be either MIN or MAX, the resulting set will contain the minimum or maximum score of an element across the inputs where it exists.
destKey - target keykeys - source set's keysLong zsetInterStore(String destKey, redis.clients.jedis.ZParams params, String... keys)
As the terms imply, the ZINTERSTORE command requires an
element to be present in each of the given inputs to be inserted in the result. The
ZUNIONSTORE command inserts all elements across all
inputs.
Using the WEIGHTS option, it is possible to add weight to each input sorted set. This means that the score of each element in the sorted set is first multiplied by this weight before being passed to the aggregation. When this option is not given, all weights default to 1.
With the AGGREGATE option, it's possible to specify how the results of the union or intersection are aggregated. This option defaults to SUM, where the score of an element is summed across the inputs where it exists. When this option is set to be either MIN or MAX, the resulting set will contain the minimum or maximum score of an element across the inputs where it exists.
destKey - target keyparams - set paramskeys - source set's keysLong zsetLexLength(String key, String min, String max)
key - keymin - min lexmax - max lexSet<String> zsetRangeByLex(String key, String min, String max)
key - keymin - min lexmax - max lexSet<String> zsetRangeByLex(String key, String min, String max, int offset, int count)
Set<String> zsetReverseRangeByLex(String key, String min, String max, int offset, int count)
List<String> sort(String key)
Sort the elements contained in the List, Set, or Sorted Set value at key. By default sorting is numeric with elements being compared as double precision floating point numbers. This is the simplest form of SORT.
key - keysortStore(String, String),
sort(String, SortingParams),
sortStore(String, SortingParams, String)List<String> sort(String key, redis.clients.jedis.SortingParams sortingParameters)
examples:
Given are the following sets and key/values:
x = [1, 2, 3] y = [a, b, c] k1 = z k2 = y k3 = x w1 = 9 w2 = 8 w3 = 7Sort Order:
sort(x) or sort(x, sp.asc()) -> [1, 2, 3] sort(x, sp.desc()) -> [3, 2, 1] sort(y) -> [c, a, b] sort(y, sp.alpha()) -> [a, b, c] sort(y, sp.alpha().desc()) -> [c, a, b]Limit (e.g. for Pagination):
sort(x, sp.limit(0, 2)) -> [1, 2] sort(y, sp.alpha().desc().limit(1, 2)) -> [b, a]Sorting by external keys:
sort(x, sb.by(w*)) -> [3, 2, 1] sort(x, sb.by(w*).desc()) -> [1, 2, 3]Getting external keys:
sort(x, sp.by(w*).get(k*)) -> [x, y, z] sort(x, sp.by(w*).get(#).get(k*)) -> [3, x, 2, y, 1, z]
key - keysortingParameters - sorting parametersLong sortStore(String key, String destKey)
Sort the elements contained in the List, Set, or Sorted Set value at key and store the result at dstkey. By default sorting is numeric with elements being compared as double precision floating point numbers. This is the simplest form of SORT.
key - keydestKey - target keyLong sortStore(String key, redis.clients.jedis.SortingParams sortingParameters, String destKey)
Sort the elements contained in the List, Set, or Sorted Set value at key and store the result at dstkey. By default sorting is numeric with elements being compared as double precision floating point numbers. This is the simplest form of SORT.
key - keysortingParameters - paramdestKey - target keyLong geoAdd(String key, double longitude, double latitude, String value)
key - key to geolongitude - longitudelatitude - latitudevalue - valueDouble geoDistant(String key, String source, String target, redis.clients.jedis.GeoUnit unit)
List<redis.clients.jedis.GeoRadiusResponse> geoRadius(String key, double longitude, double latitude, double radius, redis.clients.jedis.GeoUnit unit)
key - keylongitude - lonlatitude - latradius - radiusunit - unitList<redis.clients.jedis.GeoRadiusResponse> geoRadiusReadonly(String key, double longitude, double latitude, double radius, redis.clients.jedis.GeoUnit unit)
List<redis.clients.jedis.GeoRadiusResponse> geoRadius(String key, double longitude, double latitude, double radius, redis.clients.jedis.GeoUnit unit, redis.clients.jedis.params.GeoRadiusParam param)
List<redis.clients.jedis.GeoRadiusResponse> geoRadiusReadonly(String key, double longitude, double latitude, double radius, redis.clients.jedis.GeoUnit unit, redis.clients.jedis.params.GeoRadiusParam param)
List<redis.clients.jedis.GeoRadiusResponse> geoRadiusByMember(String key, String member, double radius, redis.clients.jedis.GeoUnit unit)
List<redis.clients.jedis.GeoRadiusResponse> geoRadiusByMemberReadonly(String key, String member, double radius, redis.clients.jedis.GeoUnit unit)
List<redis.clients.jedis.GeoRadiusResponse> geoRadiusByMember(String key, String member, double radius, redis.clients.jedis.GeoUnit unit, redis.clients.jedis.params.GeoRadiusParam param)
List<redis.clients.jedis.GeoRadiusResponse> geoRadiusByMemberReadonly(String key, String member, double radius, redis.clients.jedis.GeoUnit unit, redis.clients.jedis.params.GeoRadiusParam param)
void subscribe(redis.clients.jedis.JedisPubSub jedisPubSub,
String... channels)
jedisPubSub - callback when channels has publish messagechannels - changesLong publish(String channel, String message)
channel - target channel.message - messagevoid patternSubscribe(redis.clients.jedis.JedisPubSub jedisPubSub,
String... patterns)
jedisPubSub - callbackpatterns - channel patternObject eval(String script, List<String> keys, List<String> args)
redis 127.0.0.1:6379> eval "return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}" 2 key1 key2 first second
1) "key1"
2) "key2"
3) "first"
4) "second"
script - script contentkeys - keysargs - argCopyright © 2020. All rights reserved.