Configuration

This page covers all configuration options for session clustering.

ClusterConfig Properties

Property
Type
Default
Description

enabled

Bool

false

Enable/disable clustering

node_id

String

Random UUID

Unique identifier for this node

channel

String

"session:cluster:invalidate"

Redis Pub/Sub channel name

local_cache_enabled

Bool

true

Enable local caching

local_cache_ttl

Time::Span

30.seconds

Cache entry time-to-live

local_cache_max_size

Int32

10_000

Maximum cache entries

subscribe_timeout

Time::Span

5.seconds

Pub/Sub subscription timeout

Basic Configuration

Minimal Setup

Session.configure do |config|
  config.secret = ENV["SESSION_SECRET"]

  # Enable clustering with defaults
  config.cluster.enabled = true

  config.provider = Session::ClusteredRedisStore(UserSession).new(
    client: Redis.new
  )
end

Full Configuration

Configuration Options Explained

enabled

Controls whether clustering features are active.

When disabled:

  • Local caching still works (if local_cache_enabled is true)

  • No Pub/Sub subscription is created

  • No invalidation messages are broadcast

node_id

A unique identifier for this application instance. Used to:

  • Identify the source of invalidation messages

  • Filter out self-generated messages (nodes ignore their own broadcasts)

channel

The Redis Pub/Sub channel for invalidation messages.

Use different channels for:

  • Different environments (staging vs production)

  • Different applications sharing the same Redis instance

  • Different session types within the same application

local_cache_enabled

Controls whether sessions are cached locally in memory.

Disable local caching when:

  • Memory is constrained

  • Sessions change frequently

  • You need real-time consistency

local_cache_ttl

How long cached sessions remain valid before being evicted.

Considerations:

  • Shorter TTL = more Redis reads, fresher data

  • Longer TTL = fewer Redis reads, potentially stale data

  • TTL should be shorter than your session timeout

local_cache_max_size

Maximum number of sessions to keep in local cache.

When the cache reaches max size:

  1. Expired entries are removed first

  2. If still full, LRU (least recently used) entries are evicted

Memory estimation:

  • Each cached session uses approximately 1-5 KB depending on data size

  • 10,000 sessions ≈ 10-50 MB memory usage

Passing Config to ClusteredRedisStore

You can pass configuration directly to the store:

Environment-Based Configuration

Combining with Other Features

With Circuit Breaker

With Encryption

With Compression

Last updated

Was this helpful?