Class QueryExecutor

java.lang.Object
com.github.darksoulq.abyssallib.common.database.nosql.redis.QueryExecutor

public class QueryExecutor extends Object
Provides a high-level API for executing standard Redis commands.

This class handles resource management (try-with-resources) for every call and provides both synchronous and asynchronous variants of common commands.

  • Constructor Details

    • QueryExecutor

      public QueryExecutor(Database database)
      Constructs a new QueryExecutor.
      Parameters:
      database - The target Database.
  • Method Details

    • set

      public void set(String key, String value)
      Sets a key to a specific value.
      Parameters:
      key - The key name.
      value - The string value.
    • setex

      public void setex(String key, int seconds, String value)
      Sets a key with an expiration time.
      Parameters:
      key - The key name.
      seconds - TTL in seconds.
      value - The string value.
    • get

      public String get(String key)
      Retrieves the value of a key.
      Parameters:
      key - The key name.
      Returns:
      The string value, or null if not found.
    • del

      public void del(String... keys)
      Deletes one or more keys.
      Parameters:
      keys - The keys to remove.
    • hset

      public void hset(String key, String field, String value)
      Sets a field in a Redis hash.
      Parameters:
      key - The hash key.
      field - The field name.
      value - The value.
    • hset

      public void hset(String key, Map<String,String> hash)
      Sets multiple fields in a Redis hash using a map.
      Parameters:
      key - The hash key.
      hash - The map of fields and values.
    • hget

      public String hget(String key, String field)
      Gets a field value from a hash.
      Parameters:
      key - The hash key.
      field - The field name.
      Returns:
      The value, or null.
    • hgetAll

      public Map<String,String> hgetAll(String key)
      Retrieves all fields and values from a hash.
      Parameters:
      key - The hash key.
      Returns:
      A map of all entries in the hash.
    • hdel

      public void hdel(String key, String... fields)
      Deletes fields from a hash.
      Parameters:
      key - The hash key.
      fields - The fields to delete.
    • lpush

      public void lpush(String key, String... values)
      Pushes values to the front (left) of a list.
      Parameters:
      key - The list key.
      values - The values to push.
    • rpush

      public void rpush(String key, String... values)
      Pushes values to the end (right) of a list.
      Parameters:
      key - The list key.
      values - The values to push.
    • lrange

      public List<String> lrange(String key, long start, long stop)
      Retrieves a range of elements from a list.
      Parameters:
      key - The list key.
      start - The start index (0-based).
      stop - The end index.
      Returns:
      A list of strings within the range.
    • sadd

      public void sadd(String key, String... members)
      Adds members to a set.
      Parameters:
      key - The set key.
      members - The members to add.
    • smembers

      public Set<String> smembers(String key)
      Retrieves all members of a set.
      Parameters:
      key - The set key.
      Returns:
      A set of members.
    • sismember

      public boolean sismember(String key, String member)
      Checks if a value is a member of a set.
      Parameters:
      key - The set key.
      member - The value to check.
      Returns:
      True if the member exists in the set.
    • exists

      public boolean exists(String key)
      Checks if a key exists in the database.
      Parameters:
      key - The key to check.
      Returns:
      True if it exists.
    • expire

      public void expire(String key, int seconds)
      Sets a timeout on a key.
      Parameters:
      key - The key.
      seconds - Timeout in seconds.
    • setAsync

      public CompletableFuture<Void> setAsync(String key, String value)
      Sets a key value asynchronously.
      Returns:
      A future.
    • getAsync

      public CompletableFuture<String> getAsync(String key)
      Gets a key value asynchronously.
      Returns:
      A future containing the string.
    • hsetAsync

      public CompletableFuture<Void> hsetAsync(String key, String field, String value)
      Sets a hash field asynchronously.
      Returns:
      A future.
    • hgetAsync

      public CompletableFuture<String> hgetAsync(String key, String field)
      Gets a hash field value asynchronously.
      Returns:
      A future containing the string.
    • hgetAllAsync

      public CompletableFuture<Map<String,String>> hgetAllAsync(String key)
      Gets all fields from a hash asynchronously.
      Returns:
      A future containing the map.
    • delAsync

      public CompletableFuture<Void> delAsync(String... keys)
      Deletes keys asynchronously.
      Returns:
      A future.
    • pipeline

      public PipelineExecutor pipeline()
      Creates a new PipelineExecutor for batching operations starting from this executor.
      Returns:
      A new PipelineExecutor.