Interface RedisStringCommands

All Known Subinterfaces:
DefaultedRedisClusterConnection, DefaultedRedisConnection, RedisClusterConnection, RedisCommands, RedisConnection, RedisConnectionUtils.RedisConnectionProxy, StringRedisConnection
All Known Implementing Classes:
AbstractRedisConnection, DefaultStringRedisConnection, JedisClusterConnection, JedisConnection, LettuceClusterConnection, LettuceConnection

@NullUnmarked public interface RedisStringCommands
String/Value-specific commands supported by Redis.
Author:
Costin Leau, Christoph Strobl, Mark Paluch, Marcin Grzejszczak
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static enum 
     
    static enum 
    SET command arguments for NX, XX.
  • Method Summary

    Modifier and Type
    Method
    Description
    append(byte @NonNull [] key, byte[] value)
    Append a value to key.
    bitCount(byte @NonNull [] key)
    Count the number of set bits (population counting) in value stored at key.
    bitCount(byte @NonNull [] key, long start, long end)
    Count the number of set bits (population counting) of value stored at key between start and end.
    bitField(byte @NonNull [] key, @NonNull BitFieldSubCommands subCommands)
    Get / Manipulate specific integer fields of varying bit widths and arbitrary non (necessary) aligned offset stored at a given key.
    bitOp(@NonNull RedisStringCommands.BitOperation op, byte @NonNull [] destination, byte @NonNull [] @NonNull ... keys)
    Perform bitwise operations between strings.
    default Long
    bitPos(byte @NonNull [] key, boolean bit)
    Return the position of the first bit set to given bit in a string.
    bitPos(byte @NonNull [] key, boolean bit, @NonNull Range<@NonNull Long> range)
    Return the position of the first bit set to given bit in a string.
    decr(byte @NonNull [] key)
    Decrement an integer value stored as string value of key by 1.
    decrBy(byte @NonNull [] key, long value)
    Decrement an integer value stored as string value of key by value.
    byte[]
    get(byte @NonNull [] key)
    Get the value of key.
    getBit(byte @NonNull [] key, long offset)
    Get the bit value at offset of value at key.
    byte[]
    getDel(byte @NonNull [] key)
    Return the value at key and delete the key.
    byte[]
    getEx(byte @NonNull [] key, @NonNull Expiration expiration)
    Return the value at key and expire the key by applying Expiration.
    byte[]
    getRange(byte @NonNull [] key, long start, long end)
    Get a substring of value of key between start and end.
    byte[]
    getSet(byte @NonNull [] key, byte @NonNull [] value)
    Set value of key and return its old value.
    incr(byte @NonNull [] key)
    Increment an integer value stored as string value of key by 1.
    incrBy(byte @NonNull [] key, double value)
    Increment a floating point number value of key by delta.
    incrBy(byte @NonNull [] key, long value)
    Increment an integer value stored of key by delta.
    List<byte[]>
    mGet(byte @NonNull [] @NonNull ... keys)
    Get multiple keys.
    mSet(@NonNull Map<byte @NonNull [], byte @NonNull []> tuple)
    Set multiple keys to multiple values using key-value pairs provided in tuple.
    mSetNX(@NonNull Map<byte @NonNull [], byte @NonNull []> tuple)
    Set multiple keys to multiple values using key-value pairs provided in tuple only if the provided key does not exist.
    pSetEx(byte @NonNull [] key, long milliseconds, byte @NonNull [] value)
    Set the value and expiration in milliseconds for key.
    set(byte @NonNull [] key, byte @NonNull [] value)
    Set value for key.
    set(byte @NonNull [] key, byte @NonNull [] value, @NonNull Expiration expiration, @NonNull RedisStringCommands.SetOption option)
    Set value for key applying timeouts from expiration if set and inserting/updating values depending on option.
    setBit(byte @NonNull [] key, long offset, boolean value)
    Sets the bit at offset in value stored at key.
    setEx(byte @NonNull [] key, long seconds, byte @NonNull [] value)
    Set the value and expiration in seconds for key.
    byte[]
    setGet(byte @NonNull [] key, byte @NonNull [] value, @NonNull Expiration expiration, @NonNull RedisStringCommands.SetOption option)
    Set value for key.
    setNX(byte @NonNull [] key, byte @NonNull [] value)
    Set value for key, only if key does not exist.
    void
    setRange(byte @NonNull [] key, byte @NonNull [] value, long offset)
    Overwrite parts of key starting at the specified offset with given value.
    strLen(byte @NonNull [] key)
    Get the length of the value stored at key.
  • Method Details

    • get

      byte[] get(byte @NonNull [] key)
      Get the value of key.
      Parameters:
      key - must not be null.
      Returns:
      null when key does not exist or used in pipeline / transaction.
      See Also:
    • getDel

      byte[] getDel(byte @NonNull [] key)
      Return the value at key and delete the key.
      Parameters:
      key - must not be null.
      Returns:
      null when key does not exist or used in pipeline / transaction.
      Since:
      2.6
      See Also:
    • getEx

      byte[] getEx(byte @NonNull [] key, @NonNull Expiration expiration)
      Return the value at key and expire the key by applying Expiration.

      Use Expiration.seconds(long) for EX.
      Use Expiration.milliseconds(long) for PX.
      Use Expiration.unixTimestamp(long, TimeUnit) for EXAT | PXAT.

      Parameters:
      key - must not be null.
      expiration - must not be null.
      Returns:
      null when key does not exist or used in pipeline / transaction.
      Since:
      2.6
      See Also:
    • getSet

      byte[] getSet(byte @NonNull [] key, byte @NonNull [] value)
      Set value of key and return its old value.
      Parameters:
      key - must not be null.
      value - must not be null.
      Returns:
      null if key did not exist before or when used in pipeline / transaction.
      See Also:
    • mGet

      List<byte[]> mGet(byte @NonNull [] @NonNull ... keys)
      Get multiple keys. Values are in the order of the requested keys Absent field values are represented using null in the resulting List.
      Parameters:
      keys - must not be null.
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • set

      Boolean set(byte @NonNull [] key, byte @NonNull [] value)
      Set value for key.
      Parameters:
      key - must not be null.
      value - must not be null.
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • set

      Boolean set(byte @NonNull [] key, byte @NonNull [] value, @NonNull Expiration expiration, @NonNull RedisStringCommands.SetOption option)
      Set value for key applying timeouts from expiration if set and inserting/updating values depending on option.
      Parameters:
      key - must not be null.
      value - must not be null.
      expiration - must not be null. Use Expiration.persistent() to not set any ttl or Expiration.keepTtl() to keep the existing expiration.
      option - must not be null. Use RedisStringCommands.SetOption.upsert() to add non existing.
      Returns:
      null when used in pipeline / transaction.
      Since:
      1.7
      See Also:
    • setGet

      byte[] setGet(byte @NonNull [] key, byte @NonNull [] value, @NonNull Expiration expiration, @NonNull RedisStringCommands.SetOption option)
      Set value for key. Return the old string stored at key, or null if key did not exist. An error is returned and SET aborted if the value stored at key is not a string.
      Parameters:
      key - must not be null.
      value - must not be null.
      expiration - must not be null. Use Expiration.persistent() to not set any ttl or Expiration.keepTtl() to keep the existing expiration.
      option - must not be null. Use RedisStringCommands.SetOption.upsert() to add non-existing.
      Returns:
      null when used in pipeline / transaction.
      Since:
      3.5
      See Also:
    • setNX

      Boolean setNX(byte @NonNull [] key, byte @NonNull [] value)
      Set value for key, only if key does not exist.
      Parameters:
      key - must not be null.
      value - must not be null.
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • setEx

      Boolean setEx(byte @NonNull [] key, long seconds, byte @NonNull [] value)
      Set the value and expiration in seconds for key.
      Parameters:
      key - must not be null.
      seconds -
      value - must not be null.
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • pSetEx

      Boolean pSetEx(byte @NonNull [] key, long milliseconds, byte @NonNull [] value)
      Set the value and expiration in milliseconds for key.
      Parameters:
      key - must not be null.
      milliseconds -
      value - must not be null.
      Returns:
      null when used in pipeline / transaction.
      Since:
      1.3
      See Also:
    • mSet

      Boolean mSet(@NonNull Map<byte @NonNull [], byte @NonNull []> tuple)
      Set multiple keys to multiple values using key-value pairs provided in tuple.
      Parameters:
      tuple - must not be null.
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • mSetNX

      Boolean mSetNX(@NonNull Map<byte @NonNull [], byte @NonNull []> tuple)
      Set multiple keys to multiple values using key-value pairs provided in tuple only if the provided key does not exist.
      Parameters:
      tuple - must not be null.
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • incr

      Long incr(byte @NonNull [] key)
      Increment an integer value stored as string value of key by 1.
      Parameters:
      key - must not be null.
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • incrBy

      Long incrBy(byte @NonNull [] key, long value)
      Increment an integer value stored of key by delta.
      Parameters:
      key - must not be null.
      value -
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • incrBy

      Double incrBy(byte @NonNull [] key, double value)
      Increment a floating point number value of key by delta.
      Parameters:
      key - must not be null.
      value -
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • decr

      Long decr(byte @NonNull [] key)
      Decrement an integer value stored as string value of key by 1.
      Parameters:
      key - must not be null.
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • decrBy

      Long decrBy(byte @NonNull [] key, long value)
      Decrement an integer value stored as string value of key by value.
      Parameters:
      key - must not be null.
      value -
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • append

      Long append(byte @NonNull [] key, byte[] value)
      Append a value to key.
      Parameters:
      key - must not be null.
      value - must not be null.
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • getRange

      byte[] getRange(byte @NonNull [] key, long start, long end)
      Get a substring of value of key between start and end.
      Parameters:
      key - must not be null.
      start -
      end -
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • setRange

      void setRange(byte @NonNull [] key, byte @NonNull [] value, long offset)
      Overwrite parts of key starting at the specified offset with given value.
      Parameters:
      key - must not be null.
      value -
      offset -
      See Also:
    • getBit

      Boolean getBit(byte @NonNull [] key, long offset)
      Get the bit value at offset of value at key.
      Parameters:
      key - must not be null.
      offset -
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • setBit

      Boolean setBit(byte @NonNull [] key, long offset, boolean value)
      Sets the bit at offset in value stored at key.
      Parameters:
      key - must not be null.
      offset -
      value -
      Returns:
      the original bit value stored at offset or null when used in pipeline / transaction.
      See Also:
    • bitCount

      Long bitCount(byte @NonNull [] key)
      Count the number of set bits (population counting) in value stored at key.
      Parameters:
      key - must not be null.
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • bitCount

      Long bitCount(byte @NonNull [] key, long start, long end)
      Count the number of set bits (population counting) of value stored at key between start and end.
      Parameters:
      key - must not be null.
      start -
      end -
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • bitField

      List<Long> bitField(byte @NonNull [] key, @NonNull BitFieldSubCommands subCommands)
      Get / Manipulate specific integer fields of varying bit widths and arbitrary non (necessary) aligned offset stored at a given key.
      Parameters:
      key - must not be null.
      subCommands - must not be null.
      Returns:
      null when used in pipeline / transaction.
      Since:
      2.1
    • bitOp

      Long bitOp(@NonNull RedisStringCommands.BitOperation op, byte @NonNull [] destination, byte @NonNull [] @NonNull ... keys)
      Perform bitwise operations between strings.
      Parameters:
      op - must not be null.
      destination - must not be null.
      keys - must not be null.
      Returns:
      null when used in pipeline / transaction.
      See Also:
    • bitPos

      default Long bitPos(byte @NonNull [] key, boolean bit)
      Return the position of the first bit set to given bit in a string.
      Parameters:
      key - the key holding the actual String.
      bit - the bit value to look for.
      Returns:
      null when used in pipeline / transaction. The position of the first bit set to 1 or 0 according to the request.
      Since:
      2.1
      See Also:
    • bitPos

      Long bitPos(byte @NonNull [] key, boolean bit, @NonNull Range<@NonNull Long> range)
      Return the position of the first bit set to given bit in a string. Range start and end can contain negative values in order to index bytes starting from the end of the string, where -1 is the last byte, -2 is the penultimate.
      Parameters:
      key - the key holding the actual String.
      bit - the bit value to look for.
      range - must not be null. Use Range.unbounded() to not limit search.
      Returns:
      null when used in pipeline / transaction. The position of the first bit set to 1 or 0 according to the request.
      Since:
      2.1
      See Also:
    • strLen

      Long strLen(byte @NonNull [] key)
      Get the length of the value stored at key.
      Parameters:
      key - must not be null.
      Returns:
      null when used in pipeline / transaction.
      See Also: