App Logo
Plugins

Secondary Storage Plugin

Secondary storage allows you to use various key-value store options such as in-memory, database and custom implementations (e.g. Redis) for rate limiting counters, and other high-frequency records. This is useful for offloading intensive operations from your main database to a fast storage layer.

Why Use Secondary Storage?

  • Performance: Store rate limit data in RAM or fast key-value stores.
  • Scalability: Offload high-churn data from your main database.
  • Flexibility: Implement your own storage adapter for Redis, Valkey or any key-value store.

Standalone Mode

Configure the plugin in your config.toml:

[plugins.secondary_storage]
enabled = true
provider = "memory" # Options: "memory", "database", "redis"

[plugins.secondary_storage.memory]
cleanup_interval = "1m"

# [plugins.secondary_storage.database]
# cleanup_interval = "1m"

# [plugins.secondary_storage.redis]
# SECURITY NOTE: It is recommended to set the 'url' via the
# REDIS_URL environment variable rather than hardcoding it here.
# url = ""
# max_retries = 3
# pool_size = 10
# pool_timeout = "30s"

Library Mode

To use the plugin programmatically, instantiate and register it in your Authula instance. Note that the secondary storage plugin must be registered before the rate-limit plugin to enable distributed rate limiting.

import (
  "os"

  authula "github.com/Authula/authula"
  authulaenv "github.com/Authula/authula/env"
  authulamodels "github.com/Authula/authula/models"
  secondarystorageplugin "github.com/Authula/authula/plugins/secondary-storage"
)

auth := authula.New(&authula.AuthConfig{
  Config: config,
  Plugins: []authulamodels.Plugin{
    // Secondary storage plugin MUST be registered before rate-limit plugin
    // This allows rate-limit to optionally use Redis/database for distributed rate limiting
    secondarystorageplugin.New(secondarystorageplugin.SecondaryStoragePluginConfig{
      Enabled:  true,
      Provider: secondarystorageplugin.SecondaryStorageProviderRedis,
      Redis: &secondarystorageplugin.RedisStorageConfig{
        URL: os.Getenv(authulaenv.EnvRedisURL),
      },
    }),
  },
})

Explanation

  • Enabled: A boolean to enable or disable the plugin.
  • Provider: The type of storage provider. Available options include:
    • SecondaryStorageProviderMemory: In-memory storage.
    • SecondaryStorageProviderDatabase: Database storage.
    • SecondaryStorageProviderRedis: Redis storage.
  • Redis: Specific configuration for Redis, such as the connection URL.

On this page