Interface RedisStringCommands

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

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

    • get

      @Nullable byte[] get(byte[] 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

      @Nullable byte[] getDel(byte[] 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

      @Nullable byte[] getEx(byte[] key, 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

      @Nullable byte[] getSet(byte[] key, byte[] 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

      @Nullable List<byte[]> mGet(byte[]... 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

      @Nullable Boolean set(byte[] key, byte[] 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

      @Nullable Boolean set(byte[] key, byte[] value, Expiration expiration, 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:
    • setNX

      @Nullable Boolean setNX(byte[] key, byte[] 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

      @Nullable Boolean setEx(byte[] key, long seconds, byte[] 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

      @Nullable Boolean pSetEx(byte[] key, long milliseconds, byte[] 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

      @Nullable Boolean mSet(Map<byte[],byte[]> 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

      @Nullable Boolean mSetNX(Map<byte[],byte[]> 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

      @Nullable Long incr(byte[] 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

      @Nullable Long incrBy(byte[] 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

      @Nullable Double incrBy(byte[] 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

      @Nullable Long decr(byte[] 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

      @Nullable Long decrBy(byte[] 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

      @Nullable Long append(byte[] 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

      @Nullable byte[] getRange(byte[] 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[] key, byte[] 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

      @Nullable Boolean getBit(byte[] 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

      @Nullable Boolean setBit(byte[] 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

      @Nullable Long bitCount(byte[] 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

      @Nullable Long bitCount(byte[] 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

      @Nullable List<Long> bitField(byte[] key, 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

      @Nullable Long bitOp(RedisStringCommands.BitOperation op, byte[] destination, byte[]... 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

      @Nullable default Long bitPos(byte[] 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

      @Nullable Long bitPos(byte[] key, boolean bit, Range<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

      @Nullable Long strLen(byte[] 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: