Class UnifiedJedis
- java.lang.Object
-
- redis.clients.jedis.UnifiedJedis
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
- Direct Known Subclasses:
JedisCluster,JedisPooled
public class UnifiedJedis extends java.lang.Object implements java.io.CloseableUnified Jedis compatibility wrapper for Valkey GLIDE client. This class provides a unified API that works seamlessly with both standalone and cluster Valkey/Redis servers, while leveraging Valkey GLIDE underneath for enhanced performance, reliability, and feature support.This compatibility layer enables existing Jedis applications to migrate to Valkey GLIDE with minimal code changes while benefiting from GLIDE's advanced capabilities:
- Unified API for both standalone and cluster deployments
- Improved connection management and automatic failover
- Enhanced error handling and retry mechanisms
- Better performance optimizations and connection pooling
- Support for the latest Valkey and Redis features
- Automatic cluster topology discovery and updates
The class implements the same method signatures as the original Jedis UnifiedJedis client, ensuring drop-in compatibility for most use cases. The implementation automatically detects whether it's connected to a standalone or cluster deployment and routes commands appropriately.
Example usage for standalone server:
try (UnifiedJedis jedis = new UnifiedJedis("localhost", 6379)) { jedis.set("key", "value"); String value = jedis.get("key"); }Example usage for cluster:
Set<HostAndPort> nodes = new HashSet<>(); nodes.add(new HostAndPort("localhost", 7000)); nodes.add(new HostAndPort("localhost", 7001)); try (UnifiedJedis jedis = new UnifiedJedis(nodes)) { jedis.set("key", "value"); String value = jedis.get("key"); }Note: Some advanced Jedis features may require migration to native GLIDE APIs for optimal performance. This compatibility layer focuses on the most commonly used operations while maintaining API compatibility.
- Since:
- 1.0.0
- See Also:
GlideClient,GlideClusterClient,JedisClientConfig
-
-
Field Summary
Fields Modifier and Type Field Description protected glide.api.BaseClientbaseClientprotected booleanclosedprotected JedisClientConfigconfigprotected glide.api.GlideClientglideClientprotected glide.api.GlideClusterClientglideClusterClientprotected booleanisClusterModeprotected java.lang.StringresourceId
-
Constructor Summary
Constructors Modifier Constructor Description UnifiedJedis()Create a new UnifiedJedis instance with default localhost:6379 connection.protectedUnifiedJedis(glide.api.GlideClient glideClient, JedisClientConfig jedisConfig)Protected constructor for internal use with standalone clientprotectedUnifiedJedis(glide.api.GlideClusterClient glideClusterClient, JedisClientConfig jedisConfig)Protected constructor for internal use with cluster clientUnifiedJedis(java.lang.String url)Create a new UnifiedJedis instance with URL string connection.UnifiedJedis(java.lang.String host, int port)Create a new UnifiedJedis instance with specified host and port.UnifiedJedis(java.lang.String host, int port, int timeout)Constructor with host, port and timeoutUnifiedJedis(java.lang.String host, int port, int timeout, java.lang.String password)Constructor with host, port, timeout and passwordUnifiedJedis(java.lang.String host, int port, int timeout, java.lang.String password, int database)Constructor with host, port, timeout, password and databaseUnifiedJedis(java.lang.String host, int port, int timeout, java.lang.String password, int database, java.lang.String clientName)Constructor with host, port, timeout, password, database and clientNameUnifiedJedis(java.lang.String host, int port, JedisClientConfig clientConfig)Constructor with host, port and configUnifiedJedis(java.net.URI uri)Create a new UnifiedJedis instance with URI configuration.UnifiedJedis(java.net.URI uri, JedisClientConfig config)Create a new UnifiedJedis instance with URI and custom configuration.UnifiedJedis(java.util.Set<HostAndPort> jedisClusterNodes)Constructor for cluster with Set of nodesUnifiedJedis(java.util.Set<HostAndPort> jedisClusterNodes, JedisClientConfig clientConfig)Constructor for cluster with Set of nodes and configUnifiedJedis(java.util.Set<HostAndPort> jedisClusterNodes, JedisClientConfig clientConfig, int maxAttempts)Constructor for cluster with Set of nodes, config and max attempts Note: maxAttempts is for Jedis compatibility but not used in GLIDE configurationUnifiedJedis(java.util.Set<HostAndPort> jedisClusterNodes, JedisClientConfig clientConfig, int maxAttempts, java.time.Duration maxTotalRetriesDuration)Constructor for cluster with Set of nodes, config, max attempts and max retry duration Note: maxAttempts and maxTotalRetriesDuration are for Jedis compatibility but not used in GLIDE configurationUnifiedJedis(ConnectionProvider provider)Constructor with ConnectionProvider (for compatibility)UnifiedJedis(ConnectionProvider provider, int maxAttempts, java.time.Duration maxTotalRetriesDuration)Constructor with ConnectionProvider and max attemptsUnifiedJedis(HostAndPort hostAndPort)Create a new UnifiedJedis instance with HostAndPort configuration.UnifiedJedis(HostAndPort hostAndPort, JedisClientConfig clientConfig)Create a new UnifiedJedis instance with full configuration control.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description longappend(byte[] key, byte[] value)APPEND Command Append a value to a key.longappend(java.lang.String key, java.lang.String value)Append a value to the end of the string stored at a key.longbitcount(byte[] key)BITCOUNT Command Count set bits in a string.longbitcount(byte[] key, long start, long end)BITCOUNT Command Count set bits in a string within a range.longbitcount(byte[] key, long start, long end, BitCountOption option)BITCOUNT Command Count set bits in a string within a range with bit count option.longbitcount(java.lang.String key)Count the number of set bits (bits with value 1) in the string stored at key.longbitcount(java.lang.String key, long start, long end)Count the number of set bits in a specific range of the string stored at key.longbitcount(java.lang.String key, long start, long end, BitCountOption option)Count the number of set bits (population counting) in a string within a specified range with indexing option.java.util.List<java.lang.Long>bitfield(byte[] key, byte[]... arguments)BITFIELD Command Perform arbitrary bitfield integer operations on strings.java.util.List<java.lang.Long>bitfield(java.lang.String key, java.lang.String... arguments)BITFIELD Command Treat a Redis string as an array of bits and perform arbitrary bit field operations on it.java.util.List<java.lang.Long>bitfieldReadonly(byte[] key, byte[]... arguments)BITFIELD_RO Command Read-only variant of the BITFIELD command.java.util.List<java.lang.Long>bitfieldReadonly(java.lang.String key, java.lang.String... arguments)BITFIELD_RO Command Read-only variant of the BITFIELD command.longbitop(BitOP op, byte[] destKey, byte[]... srcKeys)BITOP Command Perform bitwise operations between strings.longbitop(BitOP op, java.lang.String destKey, java.lang.String... srcKeys)BITOP Command Perform a bitwise operation between multiple keys (containing string values) and store the result in the destination key.longbitpos(byte[] key, boolean value)BITPOS Command Return the position of the first bit set to 1 or 0 in a string.longbitpos(byte[] key, boolean value, BitPosParams params)BITPOS Command Return the position of the first bit set to 1 or 0 in a string with additional parameters.longbitpos(java.lang.String key, boolean value)BITPOS Command Return the position of the first bit set to 1 or 0 in a string.longbitpos(java.lang.String key, boolean value, BitPosParams params)BITPOS Command Return the position of the first bit set to 1 or 0 in a string with additional parameters.protected voidcheckNotClosed()Checks if the client connection is closed and throws an exception if it is.voidclose()Close the connection.booleancopy(byte[] srcKey, byte[] dstKey, boolean replace)COPY Command Copy a key to another key.booleancopy(java.lang.String srcKey, java.lang.String dstKey, boolean replace)COPY Command Copy the value stored at the source key to the destination key.longdecr(byte[] key)DECR Command Decrement the integer value of a key by one.longdecr(java.lang.String key)Decrement the integer value stored at a key by 1.longdecrBy(byte[] key, long decrement)DECRBY Command Decrement the integer value of a key by the given amount.longdecrBy(java.lang.String key, long decrement)Decrement the integer value stored at a key by the specified amount.longdel(byte[] key)DEL Command Delete a single key from the database using a binary key name.longdel(byte[]... keys)DEL Command Removes the specified keys.longdel(java.lang.String key)DEL Command Delete a single key from the database.longdel(java.lang.String... keys)DEL Command Delete one or more keys from the database.byte[]dump(byte[] key)DUMP Command Serialize the value stored at key in a Redis-specific format.byte[]dump(java.lang.String key)DUMP Command Serialize the value stored at key in a Redis-specific format and return it to the user.booleanexists(byte[] key)EXISTS Command Returns if key exists.longexists(byte[]... keys)EXISTS Command Returns the number of keys existing among the ones specified as arguments.booleanexists(java.lang.String key)Check if a key exists in the database.longexists(java.lang.String... keys)Check how many of the specified keys exist in the database.longexpire(byte[] key, long seconds)EXPIRE Command Set a timeout on key.longexpire(byte[] key, long seconds, ExpiryOption expiryOption)EXPIRE Command Set a timeout on key with expiry option.longexpire(java.lang.String key, long seconds)Set an expiration timeout on a key in seconds.longexpire(java.lang.String key, long seconds, ExpiryOption expiryOption)Set an expiration timeout on a key in seconds with additional options.longexpireAt(byte[] key, long unixTime)EXPIREAT Command Set the expiration for a key as a UNIX timestamp.longexpireAt(byte[] key, long unixTime, ExpiryOption expiryOption)EXPIREAT Command Set the expiration for a key as a UNIX timestamp with expiry option.longexpireAt(java.lang.String key, long unixTime)Set an expiration time for a key as a Unix timestamp in seconds.longexpireAt(java.lang.String key, long unixTime, ExpiryOption expiryOption)Set the expiration time of a key to a specific Unix timestamp with expiry options.longexpireTime(byte[] key)EXPIRETIME Command Returns the absolute Unix timestamp at which the given key will expire.longexpireTime(java.lang.String key)Get the absolute Unix timestamp at which the key will expire.byte[]get(byte[] key)GET Command Get the value of key.java.lang.Stringget(java.lang.String key)Get the string value stored at a key.booleangetbit(byte[] key, long offset)GETBIT Command Returns the bit value at offset in the string value stored at key.booleangetbit(java.lang.String key, long offset)Get the bit value at the specified offset in the string stored at key.byte[]getDel(byte[] key)GETDEL Command Get the value of key and delete the key.java.lang.StringgetDel(java.lang.String key)Get the value of a key and delete the key atomically.byte[]getEx(byte[] key, GetExParams params)GETEX Command Get the value of key and optionally set its expiration.java.lang.StringgetEx(java.lang.String key, GetExParams params)Get the value of a key and optionally set its expiration.byte[]getrange(byte[] key, long startOffset, long endOffset)GETRANGE Command Returns the substring of the string value stored at key.java.lang.Stringgetrange(java.lang.String key, long startOffset, long endOffset)Get a substring of the string stored at a key.byte[]getSet(byte[] key, byte[] value)GETSET Command Atomically set key to value and return the old value stored at key.java.lang.StringgetSet(java.lang.String key, java.lang.String value)Deprecated.UsesetGet(String, String)insteadlongincr(byte[] key)INCR Command Increment the integer value of a key by one.longincr(java.lang.String key)Increment the integer value stored at a key by 1.longincrBy(byte[] key, long increment)INCRBY Command Increment the integer value of a key by the given amount.longincrBy(java.lang.String key, long increment)Increment the integer value stored at a key by the specified amount.doubleincrByFloat(byte[] key, double increment)INCRBYFLOAT Command Increment the float value of a key by the given amount.doubleincrByFloat(java.lang.String key, double increment)Increment the floating-point value stored at a key by the specified amount.booleanisClosed()Check if the connection is closed.java.util.Set<byte[]>keys(byte[] pattern)KEYS Command Find all keys matching the given pattern.java.util.Set<java.lang.String>keys(java.lang.String pattern)Find all keys matching a given pattern.java.util.List<byte[]>mget(byte[]... keys)MGET Command Returns the values of all specified keys.java.util.List<java.lang.String>mget(java.lang.String... keys)Get the values of multiple keys in a single operation.java.lang.Stringmigrate(java.lang.String host, int port, byte[] key, int timeout)MIGRATE Command Atomically transfer a key from a Redis instance to another one.java.lang.Stringmigrate(java.lang.String host, int port, int timeout, MigrateParams params, byte[]... keys)MIGRATE Command Atomically transfer keys from a Redis instance to another one with additional parameters.java.lang.Stringmigrate(java.lang.String host, int port, int timeout, MigrateParams params, java.lang.String... keys)MIGRATE Command Atomically transfer keys from a Redis instance to another one with additional parameters.java.lang.Stringmigrate(java.lang.String host, int port, java.lang.String key, int timeout)MIGRATE Command Atomically transfer a key from a Redis instance to another one.longmove(java.lang.String key, int dbIndex)MOVE Command Move key from the currently selected database to the specified destination database.java.lang.Stringmset(byte[]... keysvalues)MSET Command Sets the given keys to their respective values.java.lang.Stringmset(java.lang.String... keysvalues)MSET Command Set multiple key-value pairs in a single atomic operation.longmsetnx(byte[]... keysvalues)MSETNX Command Sets the given keys to their respective values, only if none of the keys exist.longmsetnx(java.lang.String... keysvalues)MSETNX Command Set multiple keys to multiple values, only if none of the keys exist.longpersist(byte[] key)PERSIST Command Remove the existing timeout on key.longpersist(java.lang.String key)Remove the expiration from a key, making it persistent.longpexpire(byte[] key, long milliseconds)PEXPIRE Command Set a timeout on key in milliseconds.longpexpire(byte[] key, long milliseconds, ExpiryOption expiryOption)PEXPIRE Command Set a timeout on key in milliseconds with expiry option.longpexpire(java.lang.String key, long milliseconds)Set the expiration time of a key in milliseconds.longpexpire(java.lang.String key, long milliseconds, ExpiryOption expiryOption)Set the expiration time of a key in milliseconds with expiry options.longpexpireAt(byte[] key, long millisecondsTimestamp)PEXPIREAT Command Set the expiration for a key as a UNIX timestamp in milliseconds.longpexpireAt(byte[] key, long millisecondsTimestamp, ExpiryOption expiryOption)PEXPIREAT Command Set the expiration for a key as a UNIX timestamp in milliseconds with expiry option.longpexpireAt(java.lang.String key, long millisecondsTimestamp)Set the expiration time of a key to a specific Unix timestamp in milliseconds.longpexpireAt(java.lang.String key, long millisecondsTimestamp, ExpiryOption expiryOption)Set the expiration time of a key to a specific Unix timestamp in milliseconds with expiry options.longpexpireTime(byte[] key)PEXPIRETIME Command Returns the absolute Unix timestamp in milliseconds at which the given key will expire.longpexpireTime(java.lang.String key)Get the absolute Unix timestamp in milliseconds at which the key will expire.longpfadd(byte[] key, byte[]... elements)PFADD Command Adds elements to the HyperLogLog data structure.longpfadd(java.lang.String key, java.lang.String... elements)Add elements to a HyperLogLog data structure.longpfcount(byte[] key)PFCOUNT Command Returns the approximated cardinality of the HyperLogLog.longpfcount(byte[]... keys)PFCOUNT Command Returns the approximated cardinality of the union of multiple HyperLogLogs.longpfcount(java.lang.String key)Get the estimated cardinality of a HyperLogLog.longpfcount(java.lang.String... keys)Get the estimated cardinality of the union of multiple HyperLogLogs.java.lang.Stringpfmerge(byte[] destkey, byte[]... sourcekeys)PFMERGE Command Merge multiple HyperLogLog values into a unique value.java.lang.Stringpfmerge(java.lang.String destkey, java.lang.String... sourcekeys)Merge multiple HyperLogLog structures into a destination key.java.lang.Stringping()Test if the server is alive and responding.java.lang.Stringping(java.lang.String message)Test if the server is alive and echo back a custom message.java.lang.Stringpsetex(byte[] key, long milliseconds, byte[] value)PSETEX Command Set key to hold the binary value and set key to timeout after a given number of milliseconds.java.lang.Stringpsetex(java.lang.String key, long milliseconds, java.lang.String value)PSETEX Command Set the value of a key with an expiration time in milliseconds.longpttl(byte[] key)PTTL Command Returns the remaining time to live of a key in milliseconds.longpttl(java.lang.String key)Get the remaining time to live of a key in milliseconds.java.lang.StringrandomKey()Returns a random key from the currently selected database.java.lang.Stringrename(byte[] oldkey, byte[] newkey)RENAME Command Rename a key.java.lang.Stringrename(java.lang.String oldkey, java.lang.String newkey)Rename a key to a new name.longrenamenx(byte[] oldkey, byte[] newkey)RENAMENX Command Rename a key, only if the new key does not exist.longrenamenx(java.lang.String oldkey, java.lang.String newkey)Rename a key to a new name only if the destination key does not already exist.java.lang.Stringrestore(byte[] key, long ttl, byte[] serializedValue)RESTORE Command Create a key using the provided serialized value.java.lang.Stringrestore(byte[] key, long ttl, byte[] serializedValue, RestoreParams params)RESTORE Command Create a key using the provided serialized value with additional parameters.java.lang.Stringrestore(java.lang.String key, long ttl, byte[] serializedValue)RESTORE Command Create a key using the provided serialized value, previously obtained using DUMP.java.lang.Stringrestore(java.lang.String key, long ttl, byte[] serializedValue, RestoreParams params)RESTORE Command Create a key using the provided serialized value with additional restore parameters.ScanResult<byte[]>scan(byte[] cursor)SCAN Command Incrementally iterate over the key space.ScanResult<byte[]>scan(byte[] cursor, ScanParams params)SCAN Command Incrementally iterate over the key space with additional parameters.ScanResult<byte[]>scan(byte[] cursor, ScanParams params, byte[] type)SCAN Command Incrementally iterate over the key space with parameters and type filtering.ScanResult<java.lang.String>scan(java.lang.String cursor)Incrementally iterate over the keys in the database.ScanResult<java.lang.String>scan(java.lang.String cursor, ScanParams params)Incrementally iterate over the keys in the database with additional parameters.ScanResult<java.lang.String>scan(java.lang.String cursor, ScanParams params, java.lang.String type)SCAN Command Incrementally iterate over the keys in the database with additional parameters and type filtering.java.lang.Stringselect(int database)Select the database to use for subsequent operations.java.lang.Stringset(byte[] key, byte[] value)SET Command Set key to hold the binary value.java.lang.Stringset(byte[] key, byte[] value, SetParams params)SET Command Set key to hold the binary value with additional parameters.java.lang.Stringset(java.lang.String key, java.lang.String value)SET Command Set the string value of a key.java.lang.Stringset(java.lang.String key, java.lang.String value, SetParams params)SET Command Set the string value of a key with optional parameters.booleansetbit(byte[] key, long offset, boolean value)SETBIT Command Sets or clears the bit at offset in the string value stored at key.booleansetbit(java.lang.String key, long offset, boolean value)SETBIT Command Set the bit value at the specified offset in the string stored at key.java.lang.Stringsetex(byte[] key, long seconds, byte[] value)SETEX Command Set key to hold the binary value and set key to timeout after a given number of seconds.java.lang.Stringsetex(java.lang.String key, long seconds, java.lang.String value)SETEX Command Set the value of a key with an expiration time in seconds.byte[]setGet(byte[] key, byte[] value)SET Command Set key to hold the binary value and return the old value.byte[]setGet(byte[] key, byte[] value, SetParams params)SET Command Set key to hold the binary value with parameters and return the old value.java.lang.StringsetGet(java.lang.String key, java.lang.String value)SET Command Atomically set the value of a key and return its old value.java.lang.StringsetGet(java.lang.String key, java.lang.String value, SetParams params)SET Command Atomically set the value of a key with parameters and return its old value.longsetnx(byte[] key, byte[] value)SETNX Command Set key to hold binary value if key does not exist.longsetnx(java.lang.String key, java.lang.String value)SETNX Command Set the value of a key only if the key does not already exist.longsetrange(byte[] key, long offset, byte[] value)SETRANGE Command Overwrites part of the string stored at key, starting at the specified offset.longsetrange(java.lang.String key, long offset, java.lang.String value)SETRANGE Command Overwrite part of the string stored at a key, starting at the specified offset.java.util.List<byte[]>sort(byte[] key)SORT Command Sort the elements in a list, set or sorted set.longsort(byte[] key, byte[] dstkey)SORT Command Sort the elements and store the result in a destination key.java.util.List<byte[]>sort(byte[] key, SortingParams sortingParams)SORT Command Sort the elements in a list, set or sorted set with additional parameters.longsort(byte[] key, SortingParams sortingParams, byte[] dstkey)SORT Command Sort the elements with parameters and store the result in a destination key.java.util.List<java.lang.String>sort(java.lang.String key)SORT Command Sort the elements in a list, set or sorted set.longsort(java.lang.String key, java.lang.String dstkey)SORT Command Sort the elements and store the result in a destination key.java.util.List<java.lang.String>sort(java.lang.String key, SortingParams sortingParams)SORT Command Sort the elements in a list, set or sorted set with additional parameters for controlling the sorting behavior, including ordering, limiting results, and external key patterns.longsort(java.lang.String key, SortingParams sortingParams, java.lang.String dstkey)SORT Command Sort the elements with parameters and store the result in a destination key.java.util.List<byte[]>sortReadonly(byte[] key, SortingParams sortingParams)SORT_RO Command Read-only variant of the SORT command.java.util.List<java.lang.String>sortReadonly(java.lang.String key, SortingParams sortingParams)SORT_RO Command Read-only variant of the SORT command.longstrlen(byte[] key)STRLEN Command Returns the length of the string value stored at key.longstrlen(java.lang.String key)Get the length of the string value stored at a key.byte[]substr(byte[] key, int start, int end)SUBSTR Command Returns a substring of the string value stored at key.java.lang.Stringsubstr(java.lang.String key, int start, int end)Deprecated.Usegetrange(String, long, long)insteadlongtouch(byte[] key)TOUCH Command Alters the last access time of a key.longtouch(byte[]... keys)TOUCH Command Alters the last access time of multiple keys.longtouch(java.lang.String key)TOUCH Command Alters the last access time of a key.longtouch(java.lang.String... keys)TOUCH Command Alters the last access time of multiple keys.longttl(byte[] key)TTL Command Returns the remaining time to live of a key.longttl(java.lang.String key)Get the remaining time to live of a key in seconds.java.lang.Stringtype(byte[] key)TYPE Command Returns the string representation of the type of the value stored at key.java.lang.Stringtype(java.lang.String key)Get the data type of the value stored at a key.longunlink(byte[] key)UNLINK Command Delete a key asynchronously in another thread.longunlink(byte[]... keys)UNLINK Command Delete multiple keys asynchronously in another thread.longunlink(java.lang.String key)Asynchronously delete a key from the database.longunlink(java.lang.String... keys)Asynchronously delete multiple keys from the database.
-
-
-
Field Detail
-
baseClient
protected final glide.api.BaseClient baseClient
-
glideClient
protected final glide.api.GlideClient glideClient
-
glideClusterClient
protected final glide.api.GlideClusterClient glideClusterClient
-
config
protected final JedisClientConfig config
-
resourceId
protected final java.lang.String resourceId
-
isClusterMode
protected final boolean isClusterMode
-
closed
protected volatile boolean closed
-
-
Constructor Detail
-
UnifiedJedis
public UnifiedJedis()
Create a new UnifiedJedis instance with default localhost:6379 connection. This constructor is suitable for development and testing environments where Valkey/Redis is running locally with default settings.- Throws:
JedisConnectionException- if the connection cannot be established
-
UnifiedJedis
public UnifiedJedis(java.lang.String host, int port)Create a new UnifiedJedis instance with specified host and port. Uses default configuration settings for connection timeout, socket timeout, and other client parameters.- Parameters:
host- the Valkey/Redis server host (must not be null)port- the Valkey/Redis server port (must be positive)- Throws:
JedisConnectionException- if the connection cannot be established
-
UnifiedJedis
public UnifiedJedis(HostAndPort hostAndPort)
Create a new UnifiedJedis instance with HostAndPort configuration. This constructor provides a convenient way to specify connection details using the HostAndPort utility class.- Parameters:
hostAndPort- the host and port configuration (must not be null)- Throws:
JedisConnectionException- if the connection cannot be established
-
UnifiedJedis
public UnifiedJedis(java.lang.String url)
Create a new UnifiedJedis instance with URL string connection. The URL should follow the format: redis://[username:password@]host:port[/database] or rediss://[username:password@]host:port[/database] for SSL connections.- Parameters:
url- the connection URL string (must not be null and must be valid)- Throws:
JedisConnectionException- if the connection cannot be establishedjava.lang.IllegalArgumentException- if the URL format is invalid
-
UnifiedJedis
public UnifiedJedis(java.net.URI uri)
Create a new UnifiedJedis instance with URI configuration. The URI should follow the format: redis://[username:password@]host:port[/database] or rediss://[username:password@]host:port[/database] for SSL connections.- Parameters:
uri- the connection URI (must not be null and must be valid)- Throws:
JedisConnectionException- if the connection cannot be establishedjava.lang.IllegalArgumentException- if the URI format is invalid
-
UnifiedJedis
public UnifiedJedis(java.net.URI uri, JedisClientConfig config)Create a new UnifiedJedis instance with URI and custom configuration. This constructor allows you to override default settings while still using URI-based connection parameters.- Parameters:
uri- the connection URI (must not be null and must be valid)config- the client configuration to use (must not be null)- Throws:
JedisConnectionException- if the connection cannot be establishedjava.lang.IllegalArgumentException- if the URI format is invalid
-
UnifiedJedis
public UnifiedJedis(HostAndPort hostAndPort, JedisClientConfig clientConfig)
Create a new UnifiedJedis instance with full configuration control. This constructor provides the most flexibility for configuring connection parameters, timeouts, SSL settings, authentication, and other client options.- Parameters:
hostAndPort- the host and port configuration (must not be null)clientConfig- the comprehensive client configuration (must not be null)- Throws:
JedisConnectionException- if the connection cannot be establishedjava.lang.IllegalArgumentException- if configuration parameters are invalid
-
UnifiedJedis
public UnifiedJedis(java.lang.String host, int port, JedisClientConfig clientConfig)Constructor with host, port and config
-
UnifiedJedis
public UnifiedJedis(java.lang.String host, int port, int timeout, java.lang.String password)Constructor with host, port, timeout and password
-
UnifiedJedis
public UnifiedJedis(java.lang.String host, int port, int timeout)Constructor with host, port and timeout
-
UnifiedJedis
public UnifiedJedis(java.lang.String host, int port, int timeout, java.lang.String password, int database)Constructor with host, port, timeout, password and database
-
UnifiedJedis
public UnifiedJedis(java.lang.String host, int port, int timeout, java.lang.String password, int database, java.lang.String clientName)Constructor with host, port, timeout, password, database and clientName
-
UnifiedJedis
public UnifiedJedis(java.util.Set<HostAndPort> jedisClusterNodes)
Constructor for cluster with Set of nodes
-
UnifiedJedis
public UnifiedJedis(java.util.Set<HostAndPort> jedisClusterNodes, JedisClientConfig clientConfig)
Constructor for cluster with Set of nodes and config
-
UnifiedJedis
public UnifiedJedis(java.util.Set<HostAndPort> jedisClusterNodes, JedisClientConfig clientConfig, int maxAttempts)
Constructor for cluster with Set of nodes, config and max attempts Note: maxAttempts is for Jedis compatibility but not used in GLIDE configuration
-
UnifiedJedis
public UnifiedJedis(java.util.Set<HostAndPort> jedisClusterNodes, JedisClientConfig clientConfig, int maxAttempts, java.time.Duration maxTotalRetriesDuration)
Constructor for cluster with Set of nodes, config, max attempts and max retry duration Note: maxAttempts and maxTotalRetriesDuration are for Jedis compatibility but not used in GLIDE configuration
-
UnifiedJedis
public UnifiedJedis(ConnectionProvider provider)
Constructor with ConnectionProvider (for compatibility)
-
UnifiedJedis
public UnifiedJedis(ConnectionProvider provider, int maxAttempts, java.time.Duration maxTotalRetriesDuration)
Constructor with ConnectionProvider and max attempts
-
UnifiedJedis
protected UnifiedJedis(glide.api.GlideClient glideClient, JedisClientConfig jedisConfig)Protected constructor for internal use with standalone client
-
UnifiedJedis
protected UnifiedJedis(glide.api.GlideClusterClient glideClusterClient, JedisClientConfig jedisConfig)Protected constructor for internal use with cluster client
-
-
Method Detail
-
checkNotClosed
protected void checkNotClosed()
Checks if the client connection is closed and throws an exception if it is. This method is called before every operation to ensure the client is in a valid state.- Throws:
JedisException- if the client has been closed
-
set
public java.lang.String set(java.lang.String key, java.lang.String value)SET Command Set the string value of a key. If the key already exists, its value will be overwritten regardless of its type. This is the most basic Valkey SET operation.Time complexity: O(1)
- Parameters:
key- the key to set (must not be null)value- the string value to set (must not be null)- Returns:
- "OK" if successful
- Throws:
JedisException- if the operation fails- Since:
- Valkey 1.0.0
-
get
public java.lang.String get(java.lang.String key)
Get the string value stored at a key. This is the most fundamental Valkey GET operation for retrieving string values from the database.- Parameters:
key- the key to retrieve the value from (must not be null)- Returns:
- the string value stored at the key, or null if the key does not exist
- Throws:
JedisException- if the operation fails or the key contains a non-string value- Since:
- Valkey 1.0.0
-
del
public long del(java.lang.String... keys)
DEL Command Delete one or more keys from the database. This operation removes the keys and their associated values completely. Non-existent keys are ignored and do not cause an error.The operation is atomic when deleting a single key, but when multiple keys are specified, the deletion happens sequentially. In cluster mode, if keys map to different hash slots, the command will be executed multiple times.
Performance Considerations:
- For large objects (lists, sets, hashes with many elements), consider using
unlink(String...)for non-blocking deletion - Deleting many keys at once may block the server briefly
Time complexity: O(N) where N is the number of keys to delete. O(M) additional time is spent for each key if it contains M elements (for complex data types like lists, sets, etc.).
- Parameters:
keys- the keys to delete (must not be null, can be empty)- Returns:
- the number of keys that were actually deleted (0 to keys.length)
- Throws:
JedisException- if the operation fails- Since:
- Valkey 1.0.0
- API Note:
- In cluster mode, if keys map to different hash slots, multiple round trips may be required
- For large objects (lists, sets, hashes with many elements), consider using
-
del
public long del(java.lang.String key)
DEL Command Delete a single key from the database. This operation removes the key and its associated value completely. If the key does not exist, the operation is ignored and returns 0.This is a convenience method that delegates to
del(String...)with a single key.Time complexity: O(1) for simple data types, O(M) for complex data types where M is the number of elements in the data structure.
- Parameters:
key- the key to delete (must not be null)- Returns:
- 1 if the key was deleted, 0 if the key did not exist
- Throws:
JedisException- if the operation fails- Since:
- Valkey 1.0.0
- See Also:
for deleting multiple keys,for non-blocking deletion of large objects
-
del
public long del(byte[]... keys)
DEL Command Removes the specified keys.- Parameters:
keys- the keys to delete- Returns:
- the number of keys that were removed
- Throws:
JedisException- if the operation fails- Since:
- Valkey 1.0.0
-
del
public long del(byte[] key)
DEL Command Delete a single key from the database using a binary key name. This operation removes the key and its associated value completely. If the key does not exist, the operation is ignored and returns 0.This method accepts a binary (byte array) key name, which is useful when working with non-UTF-8 encoded keys or when you need to store binary data as key names.
This is a convenience method that delegates to
del(byte[]...)with a single key.Time complexity: O(1) for simple data types, O(M) for complex data types where M is the number of elements in the data structure.
- Parameters:
key- the binary key to delete (must not be null)- Returns:
- 1 if the key was deleted, 0 if the key did not exist
- Throws:
JedisException- if the operation fails- Since:
- Valkey 1.0.0
- See Also:
for deleting multiple binary keys,for deleting string keys
-
ping
public java.lang.String ping()
Test if the server is alive and responding. This command is often used for health checks and connection testing. The server will respond with "PONG" if it's functioning correctly.- Returns:
- "PONG" if the server is responding
- Throws:
JedisException- if the operation fails or connection is lost- Since:
- Valkey 1.0.0
- See Also:
- valkey.io for details.
-
ping
public java.lang.String ping(java.lang.String message)
Test if the server is alive and echo back a custom message. This variant of PING allows you to send a custom message that will be echoed back by the server, useful for testing message integrity and round-trip functionality.- Parameters:
message- the message to echo back (must not be null)- Returns:
- the echoed message exactly as sent
- Throws:
JedisException- if the operation fails or connection is lost- Since:
- Valkey 2.8.0
- See Also:
- valkey.io for details.
-
isClosed
public boolean isClosed()
Check if the connection is closed.
-
close
public void close()
Close the connection.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable
-
set
public java.lang.String set(java.lang.String key, java.lang.String value, SetParams params)SET Command Set the string value of a key with optional parameters. This method provides advanced SET functionality including conditional setting, expiration, and atomic get-and-set operations.The SetParams object allows you to specify:
- Existence conditions (NX - only if key doesn't exist, XX - only if key exists)
- Expiration settings (EX, PX, EXAT, PXAT, KEEPTTL)
- GET option to return the old value atomically
Time complexity: O(1)
- Parameters:
key- the key to set (must not be null)value- the value to set (must not be null)params- the SET parameters for conditional setting and expiration (can be null for basic SET)- Returns:
- "OK" if successful, null if not set due to NX/XX conditions, or the old value if GET option is used
- Throws:
JedisException- if the operation fails- Since:
- Valkey 1.0.0
-
setGet
public java.lang.String setGet(java.lang.String key, java.lang.String value)SET Command Atomically set the value of a key and return its old value. This operation is atomic, meaning no other client can modify the key between getting the old value and setting the new one. This is equivalent to SET with the GET option.Time complexity: O(1)
- Parameters:
key- the key to set (must not be null)value- the new value to set (must not be null)- Returns:
- the old value stored at the key, or null if the key did not exist
- Throws:
JedisException- if the operation fails- Since:
- Valkey 6.2.0
-
setGet
public java.lang.String setGet(java.lang.String key, java.lang.String value, SetParams params)SET Command Atomically set the value of a key with parameters and return its old value. This combines the functionality of SET with parameters and the GET option for atomic operations.Time complexity: O(1)
- Parameters:
key- the key to set (must not be null)value- the new value to set (must not be null)params- the SET parameters for conditional setting and expiration (can be null for basic operation)- Returns:
- the old value stored at the key, or null if the key did not exist or conditions weren't met
- Throws:
JedisException- if the operation fails- Since:
- Valkey 6.2.0
-
mget
public java.util.List<java.lang.String> mget(java.lang.String... keys)
Get the values of multiple keys in a single operation. This is more efficient than multiple individual GET operations, especially when dealing with network latency. Non-existent keys will return null values in the corresponding positions.- Parameters:
keys- the keys to retrieve values for (must not be null, can be empty)- Returns:
- a list of values corresponding to the given keys, with null for non-existent keys
- Throws:
JedisException- if the operation fails- Since:
- Valkey 1.0.0
- See Also:
- valkey.io for details.
-
mset
public java.lang.String mset(java.lang.String... keysvalues)
MSET Command Set multiple key-value pairs in a single atomic operation. This is more efficient than multiple individual SET operations and is guaranteed to be atomic - either all keys are set or none are set if an error occurs.Time complexity: O(N) where N is the number of keys to set
- Parameters:
keysvalues- alternating keys and values (key1, value1, key2, value2, ...). Must have an even number of arguments.- Returns:
- "OK" if successful
- Throws:
java.lang.IllegalArgumentException- if the number of arguments is oddJedisException- if the operation fails- Since:
- Valkey 1.0.1
- API Note:
- In cluster mode, all keys must map to the same hash slot
-
setnx
public long setnx(java.lang.String key, java.lang.String value)SETNX Command Set the value of a key only if the key does not already exist. This is useful for implementing distributed locks or ensuring that initialization values are not overwritten.Time complexity: O(1)
- Parameters:
key- the key to set (must not be null)value- the value to set (must not be null)- Returns:
- 1 if the key was set, 0 if the key already exists and was not set
- Throws:
JedisException- if the operation fails- Since:
- Valkey 1.0.0
-
setex
public java.lang.String setex(java.lang.String key, long seconds, java.lang.String value)SETEX Command Set the value of a key with an expiration time in seconds. The key will be automatically deleted after the specified number of seconds. This is equivalent to SET with EX option.Time complexity: O(1)
- Parameters:
key- the key to set (must not be null)seconds- the expiration time in seconds (must be positive)value- the value to set (must not be null)- Returns:
- "OK" if successful
- Throws:
JedisException- if the operation fails- Since:
- Valkey 2.0.0
-
psetex
public java.lang.String psetex(java.lang.String key, long milliseconds, java.lang.String value)PSETEX Command Set the value of a key with an expiration time in milliseconds. The key will be automatically deleted after the specified number of milliseconds. This provides more precise timing control than SETEX. This is equivalent to SET with PX option.Time complexity: O(1)
- Parameters:
key- the key to set (must not be null)milliseconds- the expiration time in milliseconds (must be positive)value- the value to set (must not be null)- Returns:
- "OK" if successful
- Throws:
JedisException- if the operation fails- Since:
- Valkey 2.6.0
-
getSet
@Deprecated public java.lang.String getSet(java.lang.String key, java.lang.String value)Deprecated.UsesetGet(String, String)insteadAtomically get the current value of a key and set it to a new value. This method is deprecated in favor ofsetGet(String, String)which provides the same functionality with a clearer name.- Parameters:
key- the key to get and set (must not be null)value- the new value to set (must not be null)- Returns:
- the old value stored at the key, or null if the key did not exist
- Throws:
JedisException- if the operation fails- Since:
- Valkey 1.0.0
- See Also:
- valkey.io for details.
-
getDel
public java.lang.String getDel(java.lang.String key)
Get the value of a key and delete the key atomically. This operation is useful for implementing queues or consuming values that should only be processed once. The operation is atomic, ensuring no race conditions between getting and deleting.- Parameters:
key- the key to get and delete (must not be null)- Returns:
- the value that was stored at the key, or null if the key did not exist
- Throws:
JedisException- if the operation fails- Since:
- Valkey 6.2.0
- See Also:
- valkey.io for details.
-
getEx
public java.lang.String getEx(java.lang.String key, GetExParams params)Get the value of a key and optionally set its expiration. This command allows you to retrieve a value while simultaneously updating its expiration time, which is useful for implementing sliding window expiration patterns.- Parameters:
key- the key to get (must not be null)params- the expiration parameters (can be null to just get without changing expiration)- Returns:
- the value stored at the key, or null if the key does not exist
- Throws:
JedisException- if the operation fails- Since:
- Valkey 6.2.0
- See Also:
- valkey.io for details.
-
append
public long append(java.lang.String key, java.lang.String value)Append a value to the end of the string stored at a key. If the key does not exist, it is created with an empty string as its value before performing the append operation.- Parameters:
key- the key whose value to append to (must not be null)value- the value to append (must not be null)- Returns:
- the length of the string after the append operation
- Throws:
JedisException- if the operation fails- Since:
- Valkey 2.0.0
- See Also:
- valkey.io for details.
-
strlen
public long strlen(java.lang.String key)
Get the length of the string value stored at a key. If the key does not exist, it is treated as an empty string and returns 0.- Parameters:
key- the key to get the string length for (must not be null)- Returns:
- the length of the string stored at the key, or 0 if the key does not exist
- Throws:
JedisException- if the operation fails or the key contains a non-string value- Since:
- Valkey 2.2.0
- See Also:
- valkey.io for details.
-
incr
public long incr(java.lang.String key)
Increment the integer value stored at a key by 1. If the key does not exist, it is set to 0 before performing the increment operation. The value must be representable as a 64-bit signed integer.- Parameters:
key- the key whose value to increment (must not be null)- Returns:
- the value of the key after incrementing
- Throws:
JedisException- if the operation fails or the value is not an integer- Since:
- Valkey 1.0.0
- See Also:
- valkey.io for details.
-
incrBy
public long incrBy(java.lang.String key, long increment)Increment the integer value stored at a key by the specified amount. If the key does not exist, it is set to 0 before performing the increment operation. The value must be representable as a 64-bit signed integer.- Parameters:
key- the key whose value to increment (must not be null)increment- the amount to increment by (can be negative for decrement)- Returns:
- the value of the key after incrementing
- Throws:
JedisException- if the operation fails or the value is not an integer- Since:
- Valkey 1.0.0
- See Also:
- valkey.io for details.
-
incrByFloat
public double incrByFloat(java.lang.String key, double increment)Increment the floating-point value stored at a key by the specified amount. If the key does not exist, it is set to 0 before performing the increment operation. The value must be representable as a double-precision floating-point number.- Parameters:
key- the key whose value to increment (must not be null)increment- the floating-point amount to increment by (can be negative for decrement)- Returns:
- the value of the key after incrementing
- Throws:
JedisException- if the operation fails or the value is not a valid float- Since:
- Valkey 2.6.0
- See Also:
- valkey.io for details.
-
decr
public long decr(java.lang.String key)
Decrement the integer value stored at a key by 1. If the key does not exist, it is set to 0 before performing the decrement operation. The value must be representable as a 64-bit signed integer.- Parameters:
key- the key whose value to decrement (must not be null)- Returns:
- the value of the key after decrementing
- Throws:
JedisException- if the operation fails or the value is not an integer- Since:
- Valkey 1.0.0
- See Also:
- valkey.io for details.
-
decrBy
public long decrBy(java.lang.String key, long decrement)Decrement the integer value stored at a key by the specified amount. If the key does not exist, it is set to 0 before performing the decrement operation. The value must be representable as a 64-bit signed integer.- Parameters:
key- the key whose value to decrement (must not be null)decrement- the amount to decrement by (must be positive)- Returns:
- the value of the key after decrementing
- Throws:
JedisException- if the operation fails or the value is not an integer- Since:
- Valkey 1.0.0
- See Also:
- valkey.io for details.
-
getrange
public java.lang.String getrange(java.lang.String key, long startOffset, long endOffset)Get a substring of the string stored at a key. Both start and end offsets are inclusive. Negative offsets can be used to specify positions from the end of the string.- Parameters:
key- the key containing the string (must not be null)startOffset- the start position (inclusive, can be negative)endOffset- the end position (inclusive, can be negative)- Returns:
- the substring, or empty string if the key does not exist
- Throws:
JedisException- if the operation fails or the key contains a non-string value- Since:
- Valkey 2.4.0
-
setrange
public long setrange(java.lang.String key, long offset, java.lang.String value)SETRANGE Command Overwrite part of the string stored at a key, starting at the specified offset. If the offset is larger than the current string length, the string is padded with zero-bytes. If the key does not exist, it is created with an empty string before performing the operation.Time complexity: O(1), not counting the time taken to copy the new string in place. Usually, this string is very small so the amortized complexity is O(1). Otherwise, complexity is O(M) with M being the length of the value argument.
- Parameters:
key- the key containing the string to modify (must not be null)offset- the position to start overwriting from (must be non-negative)value- the string to write at the specified offset (must not be null)- Returns:
- the length of the string after the operation
- Throws:
JedisException- if the operation fails or the key contains a non-string value- Since:
- Valkey 2.2.0
-
substr
public java.lang.String substr(java.lang.String key, int start, int end)Deprecated.Usegetrange(String, long, long)insteadGet a substring of the string stored at a key. This method is deprecated in favor ofgetrange(String, long, long)which provides the same functionality.- Parameters:
key- the key containing the string (must not be null)start- the start position (inclusive)end- the end position (inclusive)- Returns:
- the substring, or empty string if the key does not exist
-
exists
public boolean exists(java.lang.String key)
Check if a key exists in the database. This is a fast operation that only checks for the existence of the key without retrieving its value.- Parameters:
key- the key to check for existence (must not be null)- Returns:
- true if the key exists, false otherwise
- Throws:
JedisException- if the operation fails- Since:
- Valkey 1.0.0
- See Also:
- valkey.io for details.
-
exists
public long exists(java.lang.String... keys)
Check how many of the specified keys exist in the database. This operation is more efficient than multiple individual EXISTS calls when checking multiple keys.- Parameters:
keys- the keys to check for existence (must not be null, can be empty)- Returns:
- the number of keys that exist (0 to keys.length)
- Throws:
JedisException- if the operation fails- Since:
- Valkey 3.0.3
-
unlink
public long unlink(java.lang.String key)
Asynchronously delete a key from the database. Unlike DEL, this command performs the deletion in the background, making it non-blocking for large objects. The key is immediately removed from the keyspace but the memory is reclaimed asynchronously.- Parameters:
key- the key to delete asynchronously (must not be null)- Returns:
- the number of keys that were deleted (0 or 1)
- Throws:
JedisException- if the operation fails- Since:
- Valkey 4.0.0
- See Also:
- valkey.io for details.
-
unlink
public long unlink(java.lang.String... keys)
Asynchronously delete multiple keys from the database. Unlike DEL, this command performs the deletion in the background, making it non-blocking for large objects. The keys are immediately removed from the keyspace but the memory is reclaimed asynchronously.- Parameters:
keys- the keys to delete asynchronously (must not be null, can be empty)- Returns:
- the number of keys that were deleted
- Throws:
JedisException- if the operation fails- Since:
- Valkey 4.0.0
- See Also:
- valkey.io for details.
-
type
public java.lang.String type(java.lang.String key)
Get the data type of the value stored at a key. This command returns the string representation of the type, which can be used to determine how to handle the value.- Parameters:
key- the key to get the type for (must not be null)- Returns:
- the type of the value ("string", "list", "set", "zset", "hash", "stream", or "none" if key doesn't exist)
- Throws:
JedisException- if the operation fails- Since:
- Valkey 1.0.0
- See Also:
- valkey.io for details.
-
keys
public java.util.Set<java.lang.String> keys(java.lang.String pattern)
Find all keys matching a given pattern. This operation can be expensive on large databases as it scans all keys. Consider using SCAN for production environments with large datasets.Supported patterns:
- * - matches any number of characters
- ? - matches exactly one character
- [abc] - matches any one of the characters in brackets
- [a-z] - matches any character in the range
- Parameters:
pattern- the pattern to match keys against (must not be null)- Returns:
- a set of keys matching the pattern (never null, but can be empty)
- Throws:
JedisException- if the operation failsjava.lang.UnsupportedOperationException- if called in cluster mode (use SCAN instead)- Since:
- Valkey 1.0.0
-
randomKey
public java.lang.String randomKey()
Returns a random key from the currently selected database. This command is useful for sampling or implementing random selection algorithms.Time complexity: O(1)
- Returns:
- a random key from the database, or null if the database is empty
- Throws:
JedisException- if the operation fails- Since:
- Valkey 1.0.0
- See Also:
- valkey.io for details.
- API Note:
- In cluster mode, the command is routed to all primary nodes and returns the first successful result
-
rename
public java.lang.String rename(java.lang.String oldkey, java.lang.String newkey)Rename a key to a new name. If the destination key already exists, it will be overwritten. This operation is atomic - the key is renamed instantly without any intermediate state.- Parameters:
oldkey- the current name of the key (must not be null and must exist)newkey- the new name for the key (must not be null)- Returns:
- "OK" if successful
- Throws:
JedisException- if the operation fails or the source key does not exist- Since:
- Valkey 1.0.0
- See Also:
- valkey.io for details.
-
renamenx
public long renamenx(java.lang.String oldkey, java.lang.String newkey)Rename a key to a new name only if the destination key does not already exist. This is useful for atomic key renaming when you want to avoid overwriting existing data.- Parameters:
oldkey- the current name of the key (must not be null and must exist)newkey- the new name for the key (must not be null and must not exist)- Returns:
- 1 if the key was renamed, 0 if the destination key already exists
- Throws:
JedisException- if the operation fails or the source key does not exist- Since:
- Valkey 1.0.0
- See Also:
- valkey.io for details.
-
expire
public long expire(java.lang.String key, long seconds)Set an expiration timeout on a key in seconds. After the timeout expires, the key will be automatically deleted. This is useful for implementing TTL-based caching and automatic cleanup of temporary data.- Parameters:
key- the key to set expiration on (must not be null and should exist)seconds- the expiration timeout in seconds (must be positive)- Returns:
- 1 if the timeout was set, 0 if the key does not exist
- Throws:
JedisException- if the operation fails- Since:
- Valkey 1.0.0
-
expire
public long expire(java.lang.String key, long seconds, ExpiryOption expiryOption)Set an expiration timeout on a key in seconds with additional options. The ExpiryOption parameter allows for conditional expiration setting based on the current expiration state of the key.- Parameters:
key- the key to set expiration on (must not be null and should exist)seconds- the expiration timeout in seconds (must be positive)expiryOption- the condition for setting expiration (can be null for unconditional)- Returns:
- 1 if the timeout was set, 0 if the key does not exist or condition was not met
- Throws:
JedisException- if the operation fails- Since:
- Valkey 7.0.0
-
expireAt
public long expireAt(java.lang.String key, long unixTime)Set an expiration time for a key as a Unix timestamp in seconds. The key will be automatically deleted when the specified timestamp is reached.- Parameters:
key- the key to set expiration on (must not be null and should exist)unixTime- the expiration time as Unix timestamp in seconds- Returns:
- 1 if the timeout was set, 0 if the key does not exist
- Throws:
JedisException- if the operation fails- Since:
- Valkey 1.2.0
-
expireAt
public long expireAt(java.lang.String key, long unixTime, ExpiryOption expiryOption)Set the expiration time of a key to a specific Unix timestamp with expiry options.- Parameters:
key- the key to set expiration for (must not be null)unixTime- the Unix timestamp when the key should expireexpiryOption- the expiry option (NX, XX, GT, LT)- Returns:
- 1 if the expiration was set, 0 otherwise
- Throws:
JedisException- if the operation fails- Since:
- Valkey 7.0.0
- See Also:
- valkey.io for details.
-
pexpire
public long pexpire(java.lang.String key, long milliseconds)Set the expiration time of a key in milliseconds.- Parameters:
key- the key to set expiration for (must not be null)milliseconds- the expiration time in milliseconds- Returns:
- 1 if the expiration was set, 0 otherwise
- Throws:
JedisException- if the operation fails- Since:
- Valkey 2.6.0
- See Also:
- valkey.io for details.
-
pexpire
public long pexpire(java.lang.String key, long milliseconds, ExpiryOption expiryOption)Set the expiration time of a key in milliseconds with expiry options.- Parameters:
key- the key to set expiration for (must not be null)milliseconds- the expiration time in millisecondsexpiryOption- the expiry option (NX, XX, GT, LT)- Returns:
- 1 if the expiration was set, 0 otherwise
- Throws:
JedisException- if the operation fails- Since:
- Valkey 7.0.0
- See Also:
- valkey.io for details.
-
pexpireAt
public long pexpireAt(java.lang.String key, long millisecondsTimestamp)Set the expiration time of a key to a specific Unix timestamp in milliseconds.- Parameters:
key- the key to set expiration for (must not be null)millisecondsTimestamp- the Unix timestamp in milliseconds when the key should expire- Returns:
- 1 if the expiration was set, 0 otherwise
- Throws:
JedisException- if the operation fails- Since:
- Valkey 2.6.0
- See Also:
- valkey.io for details.
-
pexpireAt
public long pexpireAt(java.lang.String key, long millisecondsTimestamp, ExpiryOption expiryOption)Set the expiration time of a key to a specific Unix timestamp in milliseconds with expiry options.- Parameters:
key- the key to set expiration for (must not be null)millisecondsTimestamp- the Unix timestamp in milliseconds when the key should expireexpiryOption- the expiry option (NX, XX, GT, LT)- Returns:
- 1 if the expiration was set, 0 otherwise
- Throws:
JedisException- if the operation fails- Since:
- Valkey 7.0.0
- See Also:
- valkey.io for details.
-
expireTime
public long expireTime(java.lang.String key)
Get the absolute Unix timestamp at which the key will expire.- Parameters:
key- the key to get expiration time for (must not be null)- Returns:
- the Unix timestamp when the key expires, -1 if no expiration, -2 if key doesn't exist
- Throws:
JedisException- if the operation fails- Since:
- Valkey 7.0.0
- See Also:
- valkey.io for details.
-
pexpireTime
public long pexpireTime(java.lang.String key)
Get the absolute Unix timestamp in milliseconds at which the key will expire.- Parameters:
key- the key to get expiration time for (must not be null)- Returns:
- the Unix timestamp in milliseconds when the key expires, -1 if no expiration, -2 if key doesn't exist
- Throws:
JedisException- if the operation fails- Since:
- Valkey 7.0.0
- See Also:
- valkey.io for details.
-
ttl
public long ttl(java.lang.String key)
Get the remaining time to live of a key in seconds. This command returns the number of seconds until the key expires, or special values for keys without expiration.- Parameters:
key- the key to check TTL for (must not be null)- Returns:
- the TTL in seconds, -1 if the key exists but has no expiration, -2 if the key does not exist
- Throws:
JedisException- if the operation fails- Since:
- Valkey 1.0.0
- See Also:
- valkey.io for details.
-
pttl
public long pttl(java.lang.String key)
Get the remaining time to live of a key in milliseconds. This command provides more precise timing information than TTL, useful for fine-grained expiration monitoring.- Parameters:
key- the key to check TTL for (must not be null)- Returns:
- the TTL in milliseconds, -1 if the key exists but has no expiration, -2 if the key does not exist
- Throws:
JedisException- if the operation fails- Since:
- Valkey 2.6.0
- See Also:
- valkey.io for details.
-
persist
public long persist(java.lang.String key)
Remove the expiration from a key, making it persistent. After this operation, the key will not expire automatically and will remain in the database until explicitly deleted.- Parameters:
key- the key to make persistent (must not be null)- Returns:
- 1 if the expiration was removed, 0 if the key does not exist or has no expiration
- Throws:
JedisException- if the operation fails- Since:
- Valkey 2.2.0
- See Also:
- valkey.io for details.
-
sort
public java.util.List<java.lang.String> sort(java.lang.String key)
SORT Command Sort the elements in a list, set or sorted set. By default, sorting is numeric and elements are compared by their value interpreted as double precision floating point number.Time complexity: O(N+M*log(M)) where N is the number of elements in the list or set to sort, and M the number of returned elements. When the elements are not sorted, complexity is O(N).
- Parameters:
key- the key of the list, set or sorted set to sort- Returns:
- the sorted elements as a list
- Throws:
JedisException- if the operation fails- Since:
- Redis 1.0.0
-
sort
public java.util.List<java.lang.String> sort(java.lang.String key, SortingParams sortingParams)SORT Command Sort the elements in a list, set or sorted set with additional parameters for controlling the sorting behavior, including ordering, limiting results, and external key patterns.Time complexity: O(N+M*log(M)) where N is the number of elements in the list or set to sort, and M the number of returned elements. When the elements are not sorted, complexity is O(N).
- Parameters:
key- the key of the list, set or sorted set to sortsortingParams- the parameters controlling sort behavior (can be null for default sorting)- Returns:
- the sorted elements as a list
- Throws:
JedisException- if the operation fails- Since:
- Redis 1.0.0
-
sort
public long sort(java.lang.String key, java.lang.String dstkey)SORT Command Sort the elements and store the result in a destination key. This is useful when you want to sort elements and store the result for later use, rather than returning them immediately.Time complexity: O(N+M*log(M)) where N is the number of elements in the list or set to sort, and M the number of returned elements. When the elements are not sorted, complexity is O(N).
- Parameters:
key- the key of the list, set or sorted set to sortdstkey- the destination key where the sorted result will be stored- Returns:
- the number of elements in the sorted result
- Throws:
JedisException- if the operation fails- Since:
- Redis 1.0.0
-
sort
public long sort(java.lang.String key, SortingParams sortingParams, java.lang.String dstkey)SORT Command Sort the elements with parameters and store the result in a destination key. Combines the flexibility of parameterized sorting with result storage.Time complexity: O(N+M*log(M)) where N is the number of elements in the list or set to sort, and M the number of returned elements. When the elements are not sorted, complexity is O(N).
- Parameters:
key- the key of the list, set or sorted set to sortsortingParams- the parameters controlling sort behavior (can be null for default sorting)dstkey- the destination key where the sorted result will be stored- Returns:
- the number of elements in the sorted result
- Throws:
JedisException- if the operation fails- Since:
- Redis 1.0.0
-
sortReadonly
public java.util.List<java.lang.String> sortReadonly(java.lang.String key, SortingParams sortingParams)SORT_RO Command Read-only variant of the SORT command. This command is identical to SORT, but refuses to modify the database. This allows it to be used in read-only replicas and during multi/exec.Time complexity: O(N+M*log(M)) where N is the number of elements in the list or set to sort, and M the number of returned elements. When the elements are not sorted, complexity is O(N).
- Parameters:
key- the key of the list, set or sorted set to sortsortingParams- the parameters controlling sort behavior (can be null for default sorting)- Returns:
- the sorted elements as a list
- Throws:
JedisException- if the operation fails- Since:
- Redis 7.0.0
-
dump
public byte[] dump(java.lang.String key)
DUMP Command Serialize the value stored at key in a Redis-specific format and return it to the user. The returned value can be synthesized back into a Redis key using the RESTORE command.Time complexity: O(1) to access the key and additional O(N*M) to serialize it, where N is the number of Redis objects composing the value and M their average size. For small string values the time complexity is thus O(1)+O(1*M) where M is small, so simply O(1).
- Parameters:
key- the key to serialize- Returns:
- the serialized value as a byte array
- Throws:
JedisException- if the operation fails or the key does not exist- Since:
- Redis 2.6.0
-
restore
public java.lang.String restore(java.lang.String key, long ttl, byte[] serializedValue)RESTORE Command Create a key using the provided serialized value, previously obtained using DUMP. If ttl is 0 the key is created without any expire, otherwise the specified expire time (in milliseconds) is set.Time complexity: O(1) to create the new key and additional O(N*M) to reconstruct the serialized value, where N is the number of Redis objects composing the value and M their average size.
- Parameters:
key- the key to createttl- the time to live in milliseconds (0 for no expiration)serializedValue- the serialized value obtained from DUMP- Returns:
- "OK" if successful
- Throws:
JedisException- if the operation fails or the key already exists- Since:
- Redis 2.6.0
-
restore
public java.lang.String restore(java.lang.String key, long ttl, byte[] serializedValue, RestoreParams params)RESTORE Command Create a key using the provided serialized value with additional restore parameters. This variant allows for more control over the restore operation, including options like REPLACE.Time complexity: O(1) to create the new key and additional O(N*M) to reconstruct the serialized value, where N is the number of Redis objects composing the value and M their average size.
- Parameters:
key- the key to createttl- the time to live in milliseconds (0 for no expiration)serializedValue- the serialized value obtained from DUMPparams- additional restore parameters (can be null for default behavior)- Returns:
- "OK" if successful
- Throws:
JedisException- if the operation fails- Since:
- Redis 3.0.0
-
migrate
public java.lang.String migrate(java.lang.String host, int port, java.lang.String key, int timeout)MIGRATE Command Atomically transfer a key from a Redis instance to another one. On success the key is deleted from the original instance and is guaranteed to exist in the target instance.Time complexity: This command actually executes a DUMP+DEL in the source instance, and a RESTORE in the target instance.
- Parameters:
host- the target hostport- the target portkey- the key to migratetimeout- the timeout in milliseconds- Returns:
- "OK" if successful
- Throws:
JedisException- if the operation fails- Since:
- Redis 2.6.0
-
migrate
public java.lang.String migrate(java.lang.String host, int port, int timeout, MigrateParams params, java.lang.String... keys)MIGRATE Command Atomically transfer keys from a Redis instance to another one with additional parameters. This variant allows for more control over the migration process.Time complexity: This command actually executes a DUMP+DEL in the source instance, and a RESTORE in the target instance.
- Parameters:
host- the target hostport- the target porttimeout- the timeout in millisecondsparams- additional migration parameterskeys- the keys to migrate- Returns:
- "OK" if successful
- Throws:
JedisException- if the operation fails- Since:
- Redis 3.0.0
-
move
public long move(java.lang.String key, int dbIndex)MOVE Command Move key from the currently selected database to the specified destination database. When key already exists in the destination database, or it does not exist in the source database, it does nothing.Note: This command is only available in standalone mode, not in cluster mode.
Time complexity: O(1)
- Parameters:
key- the key to movedbIndex- the destination database index- Returns:
- 1 if key was moved, 0 if key was not moved
- Throws:
JedisException- if used in cluster mode or if the operation fails- Since:
- Redis 1.0.0
-
scan
public ScanResult<java.lang.String> scan(java.lang.String cursor)
Incrementally iterate over the keys in the database. SCAN is a cursor-based iterator that allows you to retrieve keys in small batches, making it suitable for large databases without blocking the server for extended periods.- Parameters:
cursor- the cursor value ("0" to start iteration, or value from previous SCAN)- Returns:
- a ScanResult containing the next cursor and a list of keys
- Throws:
JedisException- if the operation fails- Since:
- Valkey 2.8.0
-
scan
public ScanResult<java.lang.String> scan(java.lang.String cursor, ScanParams params)
Incrementally iterate over the keys in the database with additional parameters. This version allows you to specify patterns, count hints, and other options to control the iteration behavior.- Parameters:
cursor- the cursor value ("0" to start iteration, or value from previous SCAN)params- the scan parameters for filtering and controlling iteration (can be null)- Returns:
- a ScanResult containing the next cursor and a list of keys
- Throws:
JedisException- if the operation fails- Since:
- Valkey 2.8.0
-
scan
public ScanResult<java.lang.String> scan(java.lang.String cursor, ScanParams params, java.lang.String type)
SCAN Command Incrementally iterate over the keys in the database with additional parameters and type filtering. This version allows you to specify patterns, count hints, and filter by key type.Time complexity: O(1) for every call. O(N) for a complete iteration, including enough command calls for the cursor to return back to 0. N is the number of elements inside the collection.
- Parameters:
cursor- the cursor value ("0" to start iteration, or value from previous SCAN)params- the scan parameters for filtering and controlling iteration (can be null)type- the type of keys to return (e.g., "string", "list", "set", "zset", "hash", "stream")- Returns:
- a ScanResult containing the next cursor and a list of keys
- Throws:
JedisException- if the operation fails- Since:
- Redis 2.8.0
-
touch
public long touch(java.lang.String key)
TOUCH Command Alters the last access time of a key. A key is ignored if it does not exist.Time complexity: O(N) where N is the number of keys that will be touched.
- Parameters:
key- the key to touch- Returns:
- 1 if the key was touched, 0 if the key does not exist
- Throws:
JedisException- if the operation fails- Since:
- Redis 3.2.1
-
touch
public long touch(java.lang.String... keys)
TOUCH Command Alters the last access time of multiple keys. Keys that do not exist are ignored.Time complexity: O(N) where N is the number of keys that will be touched.
- Parameters:
keys- the keys to touch- Returns:
- the number of keys that were touched
- Throws:
JedisException- if the operation fails- Since:
- Redis 3.2.1
-
copy
public boolean copy(java.lang.String srcKey, java.lang.String dstKey, boolean replace)COPY Command Copy the value stored at the source key to the destination key.Time complexity: O(N) worst case for collections, where N is the number of nested items. O(1) for string values.
- Parameters:
srcKey- the source keydstKey- the destination keyreplace- whether to replace the destination key if it already exists- Returns:
- true if the key was copied, false if the source key does not exist or destination exists and replace is false
- Throws:
JedisException- if the operation fails- Since:
- Redis 6.2.0
-
msetnx
public long msetnx(java.lang.String... keysvalues)
MSETNX Command Set multiple keys to multiple values, only if none of the keys exist. MSETNX is atomic, so either all the keys are set, or none are set.Time complexity: O(N) where N is the number of keys to set.
- Parameters:
keysvalues- alternating keys and values (key1, value1, key2, value2, ...)- Returns:
- 1 if all keys were set, 0 if no key was set (at least one key already existed)
- Throws:
JedisException- if the operation fails or if the number of arguments is not even- Since:
- Valkey 1.0.1
- API Note:
- In cluster mode, all keys must map to the same hash slot
-
setbit
public boolean setbit(java.lang.String key, long offset, boolean value)SETBIT Command Set the bit value at the specified offset in the string stored at key. The string is treated as a bit array, and individual bits can be set or cleared. If the key doesn't exist, a new string is created.Time complexity: O(1)
- Parameters:
key- the key containing the bitmap (must not be null)offset- the bit offset to set (must be non-negative)value- the bit value to set (true for 1, false for 0)- Returns:
- the original bit value at the offset before it was set
- Throws:
JedisException- if the operation fails- Since:
- Valkey 2.2.0
-
getbit
public boolean getbit(java.lang.String key, long offset)Get the bit value at the specified offset in the string stored at key. If the offset is beyond the string length, it is treated as 0.- Parameters:
key- the key containing the bitmap (must not be null)offset- the bit offset to get (must be non-negative)- Returns:
- the bit value at the offset (true for 1, false for 0)
- Throws:
JedisException- if the operation fails- Since:
- Valkey 2.2.0
- See Also:
- valkey.io for details.
-
bitcount
public long bitcount(java.lang.String key)
Count the number of set bits (bits with value 1) in the string stored at key. This operation is useful for implementing efficient counting and analytics on bitmap data.- Parameters:
key- the key containing the bitmap (must not be null)- Returns:
- the number of bits set to 1
- Throws:
JedisException- if the operation fails- Since:
- Valkey 2.6.0
- See Also:
- valkey.io for details.
-
bitcount
public long bitcount(java.lang.String key, long start, long end)Count the number of set bits in a specific range of the string stored at key. The range is specified by start and end byte positions (inclusive).- Parameters:
key- the key containing the bitmap (must not be null)start- the start byte position (inclusive, can be negative for end-relative)end- the end byte position (inclusive, can be negative for end-relative)- Returns:
- the number of bits set to 1 in the specified range
- Throws:
JedisException- if the operation fails- Since:
- Valkey 2.6.0
-
bitcount
public long bitcount(java.lang.String key, long start, long end, BitCountOption option)Count the number of set bits (population counting) in a string within a specified range with indexing option.- Parameters:
key- the key of the stringstart- the starting offset (inclusive)end- the ending offset (inclusive)option- the indexing option (BYTE or BIT)- Returns:
- the number of set bits in the specified range
- Throws:
JedisException- if the operation fails- Since:
- Redis 2.6.0
-
bitpos
public long bitpos(java.lang.String key, boolean value)BITPOS Command Return the position of the first bit set to 1 or 0 in a string. The position is returned, thinking of the string as an array of bits from left to right, where the first byte's most significant bit is at position 0.Time complexity: O(N)
- Parameters:
key- the key containing the bitmapvalue- the bit value to search for (true for 1, false for 0)- Returns:
- the position of the first bit set to the specified value, or -1 if not found
- Throws:
JedisException- if the operation fails- Since:
- Redis 2.8.7
-
bitpos
public long bitpos(java.lang.String key, boolean value, BitPosParams params)BITPOS Command Return the position of the first bit set to 1 or 0 in a string with additional parameters. This variant allows you to specify start and end positions to limit the search range.Time complexity: O(N)
- Parameters:
key- the key containing the bitmapvalue- the bit value to search for (true for 1, false for 0)params- additional parameters for controlling the search range (can be null)- Returns:
- the position of the first bit set to the specified value, or -1 if not found
- Throws:
JedisException- if the operation fails- Since:
- Redis 2.8.7
-
bitop
public long bitop(BitOP op, java.lang.String destKey, java.lang.String... srcKeys)
BITOP Command Perform a bitwise operation between multiple keys (containing string values) and store the result in the destination key. The BITOP command supports four bitwise operations: AND, OR, XOR and NOT.Time complexity: O(N)
- Parameters:
op- the bitwise operation to perform (AND, OR, XOR, NOT)destKey- the destination key where the result will be storedsrcKeys- the source keys to perform the operation on- Returns:
- the size of the string stored in the destination key
- Throws:
JedisException- if the operation fails- Since:
- Redis 2.6.0
-
bitfield
public java.util.List<java.lang.Long> bitfield(java.lang.String key, java.lang.String... arguments)BITFIELD Command Treat a Redis string as an array of bits and perform arbitrary bit field operations on it. The command can atomically get, set and increment bit field values using different integer types.Subcommand Format:
- GET <type> <offset> - Get the specified bit field
- SET <type> <offset> <value> - Set the specified bit field and return its old value
- INCRBY <type> <offset> <increment> - Increment the specified bit field and return the new value
Type Format: [u|i]<width> where u=unsigned, i=signed, width=1-64 bits
Examples: u8, i16, u32, i64Time complexity: O(1) for each subcommand specified
- Parameters:
key- the key containing the bitmaparguments- the bit field operations in the format: subcommand type offset [value]- Returns:
- a list of results for each subcommand (may contain null values for some operations)
- Throws:
JedisException- if the operation fails- Since:
- Redis 3.2.0
-
bitfieldReadonly
public java.util.List<java.lang.Long> bitfieldReadonly(java.lang.String key, java.lang.String... arguments)BITFIELD_RO Command Read-only variant of the BITFIELD command. It can only be used with GET subcommands. This command is useful when you want to perform read-only bit field operations without the risk of modifying the data.Subcommand Format:
- GET <type> <offset> - Get the specified bit field
Type Format: [u|i]<width> where u=unsigned, i=signed, width=1-64 bits
Examples: u8, i16, u32, i64Note: This is currently a placeholder implementation that does not parse the arguments. Full implementation requires proper parsing of bitfield GET subcommands.
Time complexity: O(1) for each subcommand specified
- Parameters:
key- the key containing the bitmaparguments- the bit field GET operations in the format: GET type offset- Returns:
- a list of results for each GET subcommand
- Throws:
JedisException- if the operation fails- Since:
- Redis 6.0.0
-
pfadd
public long pfadd(java.lang.String key, java.lang.String... elements)Add elements to a HyperLogLog data structure. HyperLogLog is a probabilistic data structure used for estimating the cardinality of large datasets with minimal memory usage.- Parameters:
key- the key of the HyperLogLog (must not be null)elements- the elements to add (must not be null, can be empty)- Returns:
- 1 if the HyperLogLog was modified, 0 if it was not modified
- Throws:
JedisException- if the operation fails- Since:
- Valkey 2.8.9
- See Also:
- valkey.io for details.
-
pfcount
public long pfcount(java.lang.String key)
Get the estimated cardinality of a HyperLogLog. This returns an approximation of the number of unique elements that have been added to the HyperLogLog.- Parameters:
key- the key of the HyperLogLog (must not be null)- Returns:
- the estimated cardinality
- Throws:
JedisException- if the operation fails- Since:
- Valkey 2.8.9
- See Also:
- valkey.io for details.
-
pfcount
public long pfcount(java.lang.String... keys)
Get the estimated cardinality of the union of multiple HyperLogLogs. This operation computes the estimated number of unique elements across all specified HyperLogLog keys without modifying the original structures.- Parameters:
keys- the keys of the HyperLogLogs to union (must not be null, should not be empty)- Returns:
- the estimated cardinality of the union
- Throws:
JedisException- if the operation fails- Since:
- Valkey 2.8.9
-
pfmerge
public java.lang.String pfmerge(java.lang.String destkey, java.lang.String... sourcekeys)Merge multiple HyperLogLog structures into a destination key. The destination HyperLogLog will contain the union of all unique elements from the source HyperLogLogs.- Parameters:
destkey- the destination key for the merged HyperLogLog (must not be null)sourcekeys- the source HyperLogLog keys to merge (must not be null, should not be empty)- Returns:
- "OK" if successful
- Throws:
JedisException- if the operation fails- Since:
- Valkey 2.8.9
-
append
public long append(byte[] key, byte[] value)APPEND Command Append a value to a key.- Parameters:
key- the key to append tovalue- the binary value to append- Returns:
- the length of the string after the append operation
- Throws:
JedisException- if the operation fails- Since:
- Valkey 2.0.0
-
bitcount
public long bitcount(byte[] key)
BITCOUNT Command Count set bits in a string.- Parameters:
key- the key containing the string- Returns:
- the number of bits set to 1
- Throws:
JedisException- if the operation fails- Since:
- Valkey 2.6.0
-
bitcount
public long bitcount(byte[] key, long start, long end)BITCOUNT Command Count set bits in a string within a range.- Parameters:
key- the key containing the stringstart- the start offsetend- the end offset- Returns:
- the number of bits set to 1 in the specified range
- Throws:
JedisException- if the operation fails- Since:
- Valkey 2.6.0
-
bitcount
public long bitcount(byte[] key, long start, long end, BitCountOption option)BITCOUNT Command Count set bits in a string within a range with bit count option.- Parameters:
key- the key containing the stringstart- the start offsetend- the end offsetoption- the bit count option (BYTE or BIT)- Returns:
- the number of bits set to 1 in the specified range
- Throws:
JedisException- if the operation fails- Since:
- Valkey 7.0.0
-
bitfield
public java.util.List<java.lang.Long> bitfield(byte[] key, byte[]... arguments)BITFIELD Command Perform arbitrary bitfield integer operations on strings.- Parameters:
key- the key containing the stringarguments- the bitfield operation arguments- Returns:
- a list of results for each subcommand
- Throws:
JedisException- if the operation fails- Since:
- Valkey 3.2.0
-
bitop
public long bitop(BitOP op, byte[] destKey, byte[]... srcKeys)
BITOP Command Perform bitwise operations between strings.- Parameters:
op- the bitwise operation (AND, OR, XOR, NOT)destKey- the destination key to store the resultsrcKeys- the source keys for the operation- Returns:
- the size of the string stored in the destination key
- Throws:
JedisException- if the operation fails- Since:
- Valkey 2.6.0
-
bitpos
public long bitpos(byte[] key, boolean value)BITPOS Command Return the position of the first bit set to 1 or 0 in a string.- Parameters:
key- the key containing the stringvalue- the bit value to search for (true for 1, false for 0)- Returns:
- the position of the first bit set to the specified value
- Throws:
JedisException- if the operation fails- Since:
- Valkey 2.8.7
-
bitpos
public long bitpos(byte[] key, boolean value, BitPosParams params)BITPOS Command Return the position of the first bit set to 1 or 0 in a string with additional parameters.- Parameters:
key- the key containing the stringvalue- the bit value to search for (true for 1, false for 0)params- additional parameters for the bitpos operation- Returns:
- the position of the first bit set to the specified value
- Throws:
JedisException- if the operation fails- Since:
- Valkey 2.8.7
-
copy
public boolean copy(byte[] srcKey, byte[] dstKey, boolean replace)COPY Command Copy a key to another key.- Parameters:
srcKey- the source key to copy fromdstKey- the destination key to copy toreplace- whether to replace the destination key if it exists- Returns:
- true if the key was copied, false otherwise
- Throws:
JedisException- if the operation fails- Since:
- Valkey 6.2.0
-
decr
public long decr(byte[] key)
DECR Command Decrement the integer value of a key by one.- Parameters:
key- the key to decrement- Returns:
- the value of key after the decrement
- Throws:
JedisException- if the operation fails- Since:
- Valkey 1.0.0
-
decrBy
public long decrBy(byte[] key, long decrement)DECRBY Command Decrement the integer value of a key by the given amount.- Parameters:
key- the key to decrementdecrement- the amount to decrement by- Returns:
- the value of key after the decrement
- Throws:
JedisException- if the operation fails- Since:
- Valkey 1.0.0
-
dump
public byte[] dump(byte[] key)
DUMP Command Serialize the value stored at key in a Redis-specific format.- Parameters:
key- the key to serialize- Returns:
- the serialized value as a byte array
- Throws:
JedisException- if the operation fails or the key does not exist- Since:
- Valkey 2.6.0
-
exists
public boolean exists(byte[] key)
EXISTS Command Returns if key exists.- Parameters:
key- the key to check- Returns:
- true if the key exists, false otherwise
- Throws:
JedisException- if the operation fails- Since:
- Valkey 1.0.0
-
exists
public long exists(byte[]... keys)
EXISTS Command Returns the number of keys existing among the ones specified as arguments.- Parameters:
keys- the keys to check- Returns:
- the number of keys existing among the specified arguments
- Throws:
JedisException- if the operation fails- Since:
- Valkey 3.0.3
-
expire
public long expire(byte[] key, long seconds)EXPIRE Command Set a timeout on key.- Parameters:
key- the key to set timeout onseconds- the timeout in seconds- Returns:
- 1 if the timeout was set, 0 if key does not exist
- Throws:
JedisException- if the operation fails- Since:
- Valkey 1.0.0
-
expire
public long expire(byte[] key, long seconds, ExpiryOption expiryOption)EXPIRE Command Set a timeout on key with expiry option.- Parameters:
key- the key to set timeout onseconds- the timeout in secondsexpiryOption- the expiry option (NX, XX, GT, LT)- Returns:
- 1 if the timeout was set, 0 if key does not exist or condition not met
- Throws:
JedisException- if the operation fails- Since:
- Valkey 7.0.0
-
expireAt
public long expireAt(byte[] key, long unixTime)EXPIREAT Command Set the expiration for a key as a UNIX timestamp.- Parameters:
key- the key to set expiration onunixTime- the UNIX timestamp when the key should expire- Returns:
- 1 if the timeout was set, 0 if key does not exist
- Throws:
JedisException- if the operation fails- Since:
- Valkey 1.2.0
-
expireAt
public long expireAt(byte[] key, long unixTime, ExpiryOption expiryOption)EXPIREAT Command Set the expiration for a key as a UNIX timestamp with expiry option.- Parameters:
key- the key to set expiration onunixTime- the UNIX timestamp when the key should expireexpiryOption- the expiry option (NX, XX, GT, LT)- Returns:
- 1 if the timeout was set, 0 if key does not exist or condition not met
- Throws:
JedisException- if the operation fails- Since:
- Valkey 7.0.0
-
expireTime
public long expireTime(byte[] key)
EXPIRETIME Command Returns the absolute Unix timestamp at which the given key will expire.- Parameters:
key- the key to check- Returns:
- the expiration Unix timestamp in seconds, or -1 if key exists but has no expiry, or -2 if key does not exist
- Throws:
JedisException- if the operation fails- Since:
- Valkey 7.0.0
-
get
public byte[] get(byte[] key)
GET Command Get the value of key.- Parameters:
key- the key to retrieve- Returns:
- the value of key, or null when key does not exist
- Throws:
JedisException- if the operation fails- Since:
- Valkey 1.0.0
-
getDel
public byte[] getDel(byte[] key)
GETDEL Command Get the value of key and delete the key.- Parameters:
key- the key to get and delete- Returns:
- the value of key, or null when key does not exist
- Throws:
JedisException- if the operation fails- Since:
- Valkey 6.2.0
-
getbit
public boolean getbit(byte[] key, long offset)GETBIT Command Returns the bit value at offset in the string value stored at key.- Parameters:
key- the key containing the stringoffset- the bit offset- Returns:
- the bit value stored at offset
- Throws:
JedisException- if the operation fails- Since:
- Valkey 2.2.0
-
getrange
public byte[] getrange(byte[] key, long startOffset, long endOffset)GETRANGE Command Returns the substring of the string value stored at key.- Parameters:
key- the key containing the stringstartOffset- the start offsetendOffset- the end offset- Returns:
- the substring as a byte array
- Throws:
JedisException- if the operation fails- Since:
- Valkey 2.4.0
-
incr
public long incr(byte[] key)
INCR Command Increment the integer value of a key by one.- Parameters:
key- the key to increment- Returns:
- the value of key after the increment
- Throws:
JedisException- if the operation fails- Since:
- Valkey 1.0.0
-
incrBy
public long incrBy(byte[] key, long increment)INCRBY Command Increment the integer value of a key by the given amount.- Parameters:
key- the key to incrementincrement- the amount to increment by- Returns:
- the value of key after the increment
- Throws:
JedisException- if the operation fails- Since:
- Valkey 1.0.0
-
incrByFloat
public double incrByFloat(byte[] key, double increment)INCRBYFLOAT Command Increment the float value of a key by the given amount.- Parameters:
key- the key to incrementincrement- the float amount to increment by- Returns:
- the value of key after the increment
- Throws:
JedisException- if the operation fails- Since:
- Valkey 2.6.0
-
mget
public java.util.List<byte[]> mget(byte[]... keys)
MGET Command Returns the values of all specified keys.- Parameters:
keys- the keys to retrieve- Returns:
- list of values at the specified keys
- Throws:
JedisException- if the operation fails- Since:
- Valkey 1.0.0
-
mset
public java.lang.String mset(byte[]... keysvalues)
MSET Command Sets the given keys to their respective values.- Parameters:
keysvalues- alternating keys and values (key1, value1, key2, value2, ...)- Returns:
- Simple string reply: always OK
- Throws:
JedisException- if the operation fails- Since:
- Valkey 1.0.1
-
msetnx
public long msetnx(byte[]... keysvalues)
MSETNX Command Sets the given keys to their respective values, only if none of the keys exist.- Parameters:
keysvalues- alternating keys and values (key1, value1, key2, value2, ...)- Returns:
- 1 if all keys were set, 0 if no key was set
- Throws:
JedisException- if the operation fails- Since:
- Valkey 1.0.1
-
persist
public long persist(byte[] key)
PERSIST Command Remove the existing timeout on key.- Parameters:
key- the key to remove timeout from- Returns:
- 1 if the timeout was removed, 0 if key does not exist or does not have a timeout
- Throws:
JedisException- if the operation fails- Since:
- Valkey 2.2.0
-
pexpire
public long pexpire(byte[] key, long milliseconds)PEXPIRE Command Set a timeout on key in milliseconds.- Parameters:
key- the key to set timeout onmilliseconds- the timeout in milliseconds- Returns:
- 1 if the timeout was set, 0 if key does not exist
- Throws:
JedisException- if the operation fails- Since:
- Valkey 2.6.0
-
pexpire
public long pexpire(byte[] key, long milliseconds, ExpiryOption expiryOption)PEXPIRE Command Set a timeout on key in milliseconds with expiry option.- Parameters:
key- the key to set timeout onmilliseconds- the timeout in millisecondsexpiryOption- the expiry option (NX, XX, GT, LT)- Returns:
- 1 if the timeout was set, 0 if key does not exist or condition not met
- Throws:
JedisException- if the operation fails- Since:
- Valkey 7.0.0
-
pexpireAt
public long pexpireAt(byte[] key, long millisecondsTimestamp)PEXPIREAT Command Set the expiration for a key as a UNIX timestamp in milliseconds.- Parameters:
key- the key to set expiration onmillisecondsTimestamp- the UNIX timestamp in milliseconds when the key should expire- Returns:
- 1 if the timeout was set, 0 if key does not exist
- Throws:
JedisException- if the operation fails- Since:
- Valkey 2.6.0
-
pexpireAt
public long pexpireAt(byte[] key, long millisecondsTimestamp, ExpiryOption expiryOption)PEXPIREAT Command Set the expiration for a key as a UNIX timestamp in milliseconds with expiry option.- Parameters:
key- the key to set expiration onmillisecondsTimestamp- the UNIX timestamp in milliseconds when the key should expireexpiryOption- the expiry option (NX, XX, GT, LT)- Returns:
- 1 if the timeout was set, 0 if key does not exist or condition not met
- Throws:
JedisException- if the operation fails- Since:
- Valkey 7.0.0
-
pexpireTime
public long pexpireTime(byte[] key)
PEXPIRETIME Command Returns the absolute Unix timestamp in milliseconds at which the given key will expire.- Parameters:
key- the key to check- Returns:
- the expiration Unix timestamp in milliseconds, or -1 if key exists but has no expiry, or -2 if key does not exist
- Throws:
JedisException- if the operation fails- Since:
- Valkey 7.0.0
-
pfadd
public long pfadd(byte[] key, byte[]... elements)PFADD Command Adds elements to the HyperLogLog data structure.- Parameters:
key- the key of the HyperLogLogelements- the elements to add- Returns:
- 1 if at least one element was added, 0 otherwise
- Throws:
JedisException- if the operation fails- Since:
- Valkey 2.8.9
-
pfcount
public long pfcount(byte[] key)
PFCOUNT Command Returns the approximated cardinality of the HyperLogLog.- Parameters:
key- the key of the HyperLogLog- Returns:
- the approximated cardinality
- Throws:
JedisException- if the operation fails- Since:
- Valkey 2.8.9
-
pfcount
public long pfcount(byte[]... keys)
PFCOUNT Command Returns the approximated cardinality of the union of multiple HyperLogLogs.- Parameters:
keys- the keys of the HyperLogLogs- Returns:
- the approximated cardinality of the union
- Throws:
JedisException- if the operation fails- Since:
- Valkey 2.8.9
-
pfmerge
public java.lang.String pfmerge(byte[] destkey, byte[]... sourcekeys)PFMERGE Command Merge multiple HyperLogLog values into a unique value.- Parameters:
destkey- the destination key for the merged HyperLogLogsourcekeys- the source keys to merge- Returns:
- Simple string reply: OK
- Throws:
JedisException- if the operation fails- Since:
- Valkey 2.8.9
-
psetex
public java.lang.String psetex(byte[] key, long milliseconds, byte[] value)PSETEX Command Set key to hold the binary value and set key to timeout after a given number of milliseconds.- Parameters:
key- the key to setmilliseconds- the expiry time in millisecondsvalue- the binary value to set- Returns:
- Simple string reply: OK
- Throws:
JedisException- if the operation fails- Since:
- Valkey 2.6.0
-
pttl
public long pttl(byte[] key)
PTTL Command Returns the remaining time to live of a key in milliseconds.- Parameters:
key- the key to check- Returns:
- TTL in milliseconds, or -1 if key exists but has no expiry, or -2 if key does not exist
- Throws:
JedisException- if the operation fails- Since:
- Valkey 2.6.0
-
rename
public java.lang.String rename(byte[] oldkey, byte[] newkey)RENAME Command Rename a key.- Parameters:
oldkey- the current key namenewkey- the new key name- Returns:
- Simple string reply: OK
- Throws:
JedisException- if the operation fails or oldkey does not exist- Since:
- Valkey 1.0.0
-
renamenx
public long renamenx(byte[] oldkey, byte[] newkey)RENAMENX Command Rename a key, only if the new key does not exist.- Parameters:
oldkey- the current key namenewkey- the new key name- Returns:
- 1 if key was renamed, 0 if newkey already exists
- Throws:
JedisException- if the operation fails or oldkey does not exist- Since:
- Valkey 1.0.0
-
restore
public java.lang.String restore(byte[] key, long ttl, byte[] serializedValue)RESTORE Command Create a key using the provided serialized value.- Parameters:
key- the key to createttl- the time to live in milliseconds (0 for no expiry)serializedValue- the serialized value from DUMP- Returns:
- Simple string reply: OK
- Throws:
JedisException- if the operation fails- Since:
- Valkey 2.6.0
-
restore
public java.lang.String restore(byte[] key, long ttl, byte[] serializedValue, RestoreParams params)RESTORE Command Create a key using the provided serialized value with additional parameters.- Parameters:
key- the key to createttl- the time to live in milliseconds (0 for no expiry)serializedValue- the serialized value from DUMPparams- additional restore parameters- Returns:
- Simple string reply: OK
- Throws:
JedisException- if the operation fails- Since:
- Valkey 3.0.0
-
set
public java.lang.String set(byte[] key, byte[] value)SET Command Set key to hold the binary value.- Parameters:
key- the key to setvalue- the binary value to set- Returns:
- Simple string reply: OK if SET was executed correctly
- Throws:
JedisException- if the operation fails- Since:
- Valkey 1.0.0
-
set
public java.lang.String set(byte[] key, byte[] value, SetParams params)SET Command Set key to hold the binary value with additional parameters.- Parameters:
key- the key to setvalue- the binary value to setparams- additional set parameters (EX, PX, NX, XX, etc.)- Returns:
- Simple string reply: OK if SET was executed correctly, or null if condition not met
- Throws:
JedisException- if the operation fails- Since:
- Valkey 2.6.12
-
setGet
public byte[] setGet(byte[] key, byte[] value)SET Command Set key to hold the binary value and return the old value.- Parameters:
key- the key to setvalue- the binary value to set- Returns:
- the old value stored at key, or null when key did not exist
- Throws:
JedisException- if the operation fails- Since:
- Valkey 6.2.0
-
setGet
public byte[] setGet(byte[] key, byte[] value, SetParams params)SET Command Set key to hold the binary value with parameters and return the old value.- Parameters:
key- the key to setvalue- the binary value to setparams- additional set parameters (EX, PX, NX, XX, etc.)- Returns:
- the old value stored at key, or null when key did not exist or condition not met
- Throws:
JedisException- if the operation fails- Since:
- Valkey 6.2.0
-
setbit
public boolean setbit(byte[] key, long offset, boolean value)SETBIT Command Sets or clears the bit at offset in the string value stored at key.- Parameters:
key- the key containing the stringoffset- the bit offsetvalue- the bit value to set (true for 1, false for 0)- Returns:
- the original bit value stored at offset
- Throws:
JedisException- if the operation fails- Since:
- Valkey 2.2.0
-
setex
public java.lang.String setex(byte[] key, long seconds, byte[] value)SETEX Command Set key to hold the binary value and set key to timeout after a given number of seconds.- Parameters:
key- the key to setseconds- the expiry time in secondsvalue- the binary value to set- Returns:
- Simple string reply: OK
- Throws:
JedisException- if the operation fails- Since:
- Valkey 2.0.0
-
setnx
public long setnx(byte[] key, byte[] value)SETNX Command Set key to hold binary value if key does not exist.- Parameters:
key- the key to setvalue- the binary value to set- Returns:
- 1 if the key was set, 0 if the key was not set
- Throws:
JedisException- if the operation fails- Since:
- Valkey 1.0.0
-
setrange
public long setrange(byte[] key, long offset, byte[] value)SETRANGE Command Overwrites part of the string stored at key, starting at the specified offset.- Parameters:
key- the key containing the stringoffset- the offset to start overwritingvalue- the binary value to write- Returns:
- the length of the string after it was modified
- Throws:
JedisException- if the operation fails- Since:
- Valkey 2.2.0
-
sort
public java.util.List<byte[]> sort(byte[] key)
SORT Command Sort the elements in a list, set or sorted set.- Parameters:
key- the key of the list, set or sorted set to sort- Returns:
- the sorted elements as a list of byte arrays
- Throws:
JedisException- if the operation fails- Since:
- Valkey 1.0.0
-
sort
public java.util.List<byte[]> sort(byte[] key, SortingParams sortingParams)SORT Command Sort the elements in a list, set or sorted set with additional parameters.- Parameters:
key- the key of the list, set or sorted set to sortsortingParams- the parameters controlling sort behavior- Returns:
- the sorted elements as a list of byte arrays
- Throws:
JedisException- if the operation fails- Since:
- Valkey 1.0.0
-
sort
public long sort(byte[] key, byte[] dstkey)SORT Command Sort the elements and store the result in a destination key.- Parameters:
key- the key of the list, set or sorted set to sortdstkey- the destination key to store the sorted result- Returns:
- the number of elements in the sorted list
- Throws:
JedisException- if the operation fails- Since:
- Valkey 1.0.0
-
sort
public long sort(byte[] key, SortingParams sortingParams, byte[] dstkey)SORT Command Sort the elements with parameters and store the result in a destination key.- Parameters:
key- the key of the list, set or sorted set to sortsortingParams- the parameters controlling sort behaviordstkey- the destination key to store the sorted result- Returns:
- the number of elements in the sorted list
- Throws:
JedisException- if the operation fails- Since:
- Valkey 1.0.0
-
sortReadonly
public java.util.List<byte[]> sortReadonly(byte[] key, SortingParams sortingParams)SORT_RO Command Read-only variant of the SORT command.- Parameters:
key- the key of the list, set or sorted set to sortsortingParams- the parameters controlling sort behavior- Returns:
- the sorted elements as a list of byte arrays
- Throws:
JedisException- if the operation fails- Since:
- Valkey 7.0.0
-
strlen
public long strlen(byte[] key)
STRLEN Command Returns the length of the string value stored at key.- Parameters:
key- the key containing the string- Returns:
- the length of the string at key, or 0 when key does not exist
- Throws:
JedisException- if the operation fails- Since:
- Valkey 2.2.0
-
substr
public byte[] substr(byte[] key, int start, int end)SUBSTR Command Returns a substring of the string value stored at key.- Parameters:
key- the key containing the stringstart- the start offsetend- the end offset- Returns:
- the substring as a byte array
- Throws:
JedisException- if the operation fails- Since:
- Valkey 1.0.0
-
touch
public long touch(byte[] key)
TOUCH Command Alters the last access time of a key.- Parameters:
key- the key to touch- Returns:
- 1 if the key was touched, 0 if the key does not exist
- Throws:
JedisException- if the operation fails- Since:
- Valkey 3.2.1
-
touch
public long touch(byte[]... keys)
TOUCH Command Alters the last access time of multiple keys.- Parameters:
keys- the keys to touch- Returns:
- the number of keys that were touched
- Throws:
JedisException- if the operation fails- Since:
- Valkey 3.2.1
-
ttl
public long ttl(byte[] key)
TTL Command Returns the remaining time to live of a key.- Parameters:
key- the key to check- Returns:
- TTL in seconds, or -1 if key exists but has no expiry, or -2 if key does not exist
- Throws:
JedisException- if the operation fails- Since:
- Valkey 1.0.0
-
type
public java.lang.String type(byte[] key)
TYPE Command Returns the string representation of the type of the value stored at key.- Parameters:
key- the key to check- Returns:
- type of key, or "none" when key does not exist
- Throws:
JedisException- if the operation fails- Since:
- Valkey 1.0.0
-
unlink
public long unlink(byte[] key)
UNLINK Command Delete a key asynchronously in another thread.- Parameters:
key- the key to unlink- Returns:
- 1 if the key was unlinked, 0 if the key does not exist
- Throws:
JedisException- if the operation fails- Since:
- Valkey 4.0.0
-
unlink
public long unlink(byte[]... keys)
UNLINK Command Delete multiple keys asynchronously in another thread.- Parameters:
keys- the keys to unlink- Returns:
- the number of keys that were unlinked
- Throws:
JedisException- if the operation fails- Since:
- Valkey 4.0.0
-
bitfieldReadonly
public java.util.List<java.lang.Long> bitfieldReadonly(byte[] key, byte[]... arguments)BITFIELD_RO Command Read-only variant of the BITFIELD command.- Parameters:
key- the key containing the stringarguments- the bitfield operation arguments- Returns:
- a list of results for each subcommand
- Throws:
JedisException- if the operation fails- Since:
- Valkey 6.0.0
-
getEx
public byte[] getEx(byte[] key, GetExParams params)GETEX Command Get the value of key and optionally set its expiration.- Parameters:
key- the key to retrieveparams- expiration parameters- Returns:
- the value of key, or null when key does not exist
- Throws:
JedisException- if the operation fails- Since:
- Valkey 6.2.0
-
getSet
public byte[] getSet(byte[] key, byte[] value)GETSET Command Atomically set key to value and return the old value stored at key.- Parameters:
key- the key to setvalue- the new binary value to set- Returns:
- the old value stored at key, or null when key did not exist
- Throws:
JedisException- if the operation fails- Since:
- Valkey 1.0.0
-
keys
public java.util.Set<byte[]> keys(byte[] pattern)
KEYS Command Find all keys matching the given pattern.- Parameters:
pattern- the pattern to match keys against- Returns:
- set of keys matching the pattern
- Throws:
JedisException- if the operation fails- Since:
- Valkey 1.0.0
-
migrate
public java.lang.String migrate(java.lang.String host, int port, byte[] key, int timeout)MIGRATE Command Atomically transfer a key from a Redis instance to another one.- Parameters:
host- destination hostport- destination portkey- the key to migratetimeout- timeout in milliseconds- Returns:
- Simple string reply: OK on success
- Throws:
JedisException- if the operation fails- Since:
- Redis 2.6.0
-
migrate
public java.lang.String migrate(java.lang.String host, int port, int timeout, MigrateParams params, byte[]... keys)MIGRATE Command Atomically transfer keys from a Redis instance to another one with additional parameters.- Parameters:
host- destination hostport- destination porttimeout- timeout in millisecondsparams- additional migration parameterskeys- the keys to migrate- Returns:
- Simple string reply: OK on success
- Throws:
JedisException- if the operation fails- Since:
- Redis 3.0.0
-
scan
public ScanResult<byte[]> scan(byte[] cursor)
SCAN Command Incrementally iterate over the key space.- Parameters:
cursor- the cursor for iteration- Returns:
- scan result containing next cursor and keys
- Throws:
JedisException- if the operation fails- Since:
- Valkey 2.8.0
-
scan
public ScanResult<byte[]> scan(byte[] cursor, ScanParams params)
SCAN Command Incrementally iterate over the key space with additional parameters.- Parameters:
cursor- the cursor for iterationparams- scan parameters (MATCH, COUNT, etc.)- Returns:
- scan result containing next cursor and keys
- Throws:
JedisException- if the operation fails- Since:
- Valkey 2.8.0
-
scan
public ScanResult<byte[]> scan(byte[] cursor, ScanParams params, byte[] type)
SCAN Command Incrementally iterate over the key space with parameters and type filtering.- Parameters:
cursor- the cursor for iterationparams- scan parameters (MATCH, COUNT, etc.)type- the type of keys to return- Returns:
- scan result containing next cursor and keys
- Throws:
JedisException- if the operation fails- Since:
- Redis 2.8.0
-
select
public java.lang.String select(int database)
Select the database to use for subsequent operations. This command is only available in standalone mode and allows switching between different logical databases (0-15 by default). In cluster mode, this operation is not supported as all operations use database 0.- Parameters:
database- the database index to select (typically 0-15, must be non-negative)- Returns:
- "OK" if successful
- Throws:
JedisException- if the operation fails or the database index is invalidjava.lang.UnsupportedOperationException- if called in cluster mode- Since:
- Valkey 1.0.0
-
-