Interface PluginKeyValueStore


public interface PluginKeyValueStore
Simple key-value store for plugin configuration and small data.

This provides a simpler alternative to defining schemas for plugins that just need to store configuration values or small pieces of data.

All keys are namespaced to the plugin automatically.

Example:


PluginKeyValueStore store = db.getKeyValueStore();

// Store values
store.set("api_key", "abc123");
store.set("max_retries", 5);
store.set("features_enabled", true);

// Retrieve values
String apiKey = store.getString("api_key").orElse("default");
int maxRetries = store.getInt("max_retries").orElse(3);
boolean enabled = store.getBoolean("features_enabled").orElse(false);

// Guild/User scoped values
store.set("guild:123456:prefix", "!");
store.set("user:789:theme", "dark");

  • Method Details

    • set

      void set(String key, String value)
      Set a string value.
      Parameters:
      key - the key
      value - the value
    • set

      void set(String key, int value)
      Set an integer value.
      Parameters:
      key - the key
      value - the value
    • set

      void set(String key, long value)
      Set a long value.
      Parameters:
      key - the key
      value - the value
    • set

      void set(String key, boolean value)
      Set a boolean value.
      Parameters:
      key - the key
      value - the value
    • set

      void set(String key, double value)
      Set a double value.
      Parameters:
      key - the key
      value - the value
    • getString

      Optional<String> getString(String key)
      Get a string value.
      Parameters:
      key - the key
      Returns:
      the value if present
    • getString

      default String getString(String key, String defaultValue)
      Get a string value with a default.
      Parameters:
      key - the key
      defaultValue - default if not present
      Returns:
      the value or default
    • getInt

      Optional<Integer> getInt(String key)
      Get an integer value.
      Parameters:
      key - the key
      Returns:
      the value if present and valid
    • getInt

      default int getInt(String key, int defaultValue)
      Get an integer value with a default.
      Parameters:
      key - the key
      defaultValue - default if not present
      Returns:
      the value or default
    • getLong

      Optional<Long> getLong(String key)
      Get a long value.
      Parameters:
      key - the key
      Returns:
      the value if present and valid
    • getLong

      default long getLong(String key, long defaultValue)
      Get a long value with a default.
      Parameters:
      key - the key
      defaultValue - default if not present
      Returns:
      the value or default
    • getBoolean

      Optional<Boolean> getBoolean(String key)
      Get a boolean value.
      Parameters:
      key - the key
      Returns:
      the value if present
    • getBoolean

      default boolean getBoolean(String key, boolean defaultValue)
      Get a boolean value with a default.
      Parameters:
      key - the key
      defaultValue - default if not present
      Returns:
      the value or default
    • getDouble

      Optional<Double> getDouble(String key)
      Get a double value.
      Parameters:
      key - the key
      Returns:
      the value if present and valid
    • getDouble

      default double getDouble(String key, double defaultValue)
      Get a double value with a default.
      Parameters:
      key - the key
      defaultValue - default if not present
      Returns:
      the value or default
    • exists

      boolean exists(String key)
      Check if a key exists.
      Parameters:
      key - the key
      Returns:
      true if exists
    • delete

      boolean delete(String key)
      Delete a key.
      Parameters:
      key - the key
      Returns:
      true if deleted, false if didn't exist
    • deleteByPrefix

      int deleteByPrefix(String prefix)
      Delete multiple keys by prefix.
      Parameters:
      prefix - the key prefix
      Returns:
      number of keys deleted
    • keys

      Set<String> keys()
      Get all keys.
      Returns:
      set of all keys
    • keys

      Set<String> keys(String prefix)
      Get all keys matching a prefix.
      Parameters:
      prefix - the key prefix
      Returns:
      matching keys
    • getAll

      Map<String,String> getAll()
      Get all key-value pairs.
      Returns:
      map of all key-value pairs
    • getAll

      Map<String,String> getAll(String prefix)
      Get all key-value pairs matching a prefix.
      Parameters:
      prefix - the key prefix
      Returns:
      matching key-value pairs
    • setAll

      void setAll(Map<String,String> values)
      Set multiple values at once.
      Parameters:
      values - map of key -> value
    • count

      long count()
      Count the number of stored key-value pairs.
      Returns:
      count of entries