All Downloads are FREE. Search and download functionalities are using the official Maven repository.

redis.clients.jedis.params.HSetExParams Maven / Gradle / Ivy

There is a newer version: 6.0.0-beta2
Show newest version
package redis.clients.jedis.params;

import java.util.Objects;

import redis.clients.jedis.CommandArguments;
import redis.clients.jedis.Protocol.Keyword;

/**
 * HSetExParams is a parameter class used when setting key-value pairs of hash data with 
 * optional expiry and existance conditions in Redis.
 * It provides methods to specify whether the key should be set
 * only if it already exists or only if it does not already exist.
 * It can also be used to set the expiry time of the key in seconds or milliseconds.
 * 
 * 

This class includes the following methods:

*
    *
  • {@link #hSetExParams()} - Static factory method to create a new instance of HSetExParams.
  • *
  • {@link #fnx()} - Sets the condition to only set the key if it does not already exist.
  • *
  • {@link #fxx()} - Sets the condition to only set the key if it already exists.
  • *
  • {@link #ex(long)} - Set the specified expire time, in seconds.
  • *
  • {@link #px(long)} - Set the specified expire time, in milliseconds.
  • *
  • {@link #exAt(long)} - Set the specified Unix(epoch) time at which the key will expire, in seconds.
  • *
  • {@link #pxAt(long)} - Set the specified Unix(epoch) time at which the key will expire, in milliseconds.
  • *
  • {@link #keepTtl()} - Retain the time to live associated with the key.
  • *
* *

Example usage:

*
 * {@code
 * HSetExParams params = HSetExParams.hSetExParams().fnx();
 * }
 * 
* * @see BaseSetExParams */ public class HSetExParams extends BaseSetExParams { private Keyword existance; public static HSetExParams hSetExParams() { return new HSetExParams(); } /** * Only set the key if it does not already exist. * @return HSetExParams */ public HSetExParams fnx() { this.existance = Keyword.FNX; return this; } /** * Only set the key if it already exist. * @return HSetExParams */ public HSetExParams fxx() { this.existance = Keyword.FXX; return this; } @Override public void addParams(CommandArguments args) { if (existance != null) { args.add(existance); } super.addParams(args); } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; HSetExParams setParams = (HSetExParams) o; return Objects.equals(existance, setParams.existance) && super.equals((BaseSetExParams) o); } @Override public int hashCode() { return Objects.hash(existance, super.hashCode()); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy