Member Junction
    Preparing search index...

    Configuration options for the Redis local storage provider.

    Accepts either a Redis connection URL string or an ioredis options object, plus optional MemberJunction-specific settings.

    // Simple URL connection (works with Azure, AWS, self-hosted)
    const config: RedisProviderConfig = {
    url: 'rediss://default:password@my-redis.example.com:6380'
    };

    // Full options object with MJ settings
    const config: RedisProviderConfig = {
    options: {
    host: 'localhost',
    port: 6379,
    password: 'secret',
    tls: {},
    db: 0,
    },
    keyPrefix: 'myapp',
    defaultTTLSeconds: 600,
    };
    interface RedisProviderConfig {
        categoryTTLSeconds?: Readonly<Record<string, number>>;
        defaultPublishMode?: CachePublishMode;
        defaultTTLSeconds?: number;
        enableLogging?: boolean;
        enablePubSub?: boolean;
        keyPrefix?: string;
        maxRetries?: number;
        maxRetryDelayMs?: number;
        options?: RedisOptions;
        publishModes?: Readonly<Record<string, CachePublishMode>>;
        readTimeoutMs?: number;
        url?: string;
    }
    Index

    Properties

    categoryTTLSeconds?: Readonly<Record<string, number>>

    Expiry per category, overriding defaultTTLSeconds (0 = no expiry). Merged over the built-in { default: 0 } rather than replacing it, so setting one category never changes another; name default here to override even that.

    The default category holds proxy keys: entries that vouch for other entries. The metadata snapshot's timestamps key is written after the payload it describes, and a dataset's _date key after its blob — so under one blanket TTL the proxy outlives what it vouches for, and a reader finds a freshness claim with nothing behind it. A server booting into that window adopted the timestamps and served empty metadata as current; the dataset check threw.

    defaultPublishMode?: CachePublishMode

    Publish mode for categories not named in publishModes.

    'full' (every change carries its value — the behaviour before modes existed)
    
    defaultTTLSeconds?: number

    Default time-to-live in seconds applied to every SetItem call unless the call passes its own TTL.

    Event-driven invalidation stays the primary freshness mechanism; the TTL bounds how long an entry written by a process that never publishes (a direct SQL change, another application) can be served, and gives a volatile-* eviction policy something to evict — Redis never evicts a key without an expiry under those policies.

    Set to 0 to store keys without expiration (persistent).

    3600 (one hour)
    
    enableLogging?: boolean

    Whether to log connection events (connect, disconnect, error) via MemberJunction's LogStatus / LogError functions.

    true
    
    enablePubSub?: boolean

    Whether to enable Redis pub/sub for cross-server cache invalidation. When enabled, the provider will:

    • Publish a CacheChangedEvent on every SetItem, Remove, and ClearCategory call
    • Subscribe (via a dedicated second Redis connection) for events from other servers
    • Emit local events so consumers (like LocalCacheManager) can dispatch to registered callbacks

    Pub/sub is not started automatically — call RedisLocalStorageProvider.StartListening after construction to begin subscribing.

    false
    
    keyPrefix?: string

    Optional prefix prepended to all Redis keys. Useful for isolating MemberJunction data in a shared Redis instance.

    Keys are stored as {keyPrefix}:{category}:{key}.

    'mj'
    
    maxRetries?: number

    Caps reconnection attempts. Past the cap ioredis stops reconnecting for the life of the client, leaving the process cache-blind until it restarts.

    Omit it on a long-running process. Set it only for a short-lived script that should fail rather than wait out an outage.

    undefined — retry indefinitely, with each wait capped by maxRetryDelayMs

    maxRetryDelayMs?: number

    Ceiling on the wait between reconnection attempts, in milliseconds. The backoff doubles from 200ms up to this value and then holds there, so a long outage costs one attempt per ceiling.

    30000
    
    options?: RedisOptions

    Full ioredis options object for fine-grained connection control. Applied after the provider's defaults, with or without a url, so any ioredis option can be set.

    publishModes?: Readonly<Record<string, CachePublishMode>>

    What a set or removed publishes, per category (the category default covers writes without one). category_cleared is always published in full.

    • 'full' — the event carries the stored value in Data, so a subscriber can apply it without reading Redis. Right for categories whose values subscribers adopt (the RunView cache: engines apply the rows).
    • 'notice' — the event names the key but carries no value. Right for large values that subscribers only need to know changed (the metadata snapshot: a server that hears about it re-checks its metadata against the database).
    • 'none' — nothing is published.

    Categories not listed use defaultPublishMode.

    readTimeoutMs?: number

    Longest a cache read waits for Redis, in milliseconds. A read that takes longer is answered as a cache miss, so the caller reads the database instead of waiting.

    Applies to GetItem, GetItems, GetIndexGroupKeys and GetCategoryKeys. Writes, removals and invalidations have no timeout. GetIndexGroupKeys runs on the save path, so when it times out the slots it returns are removed once Redis answers: a stall delays the invalidation rather than dropping it. A command that fails outright still answers "none" and leaves peer slots to the TTL. A Redis that is connected but saturated otherwise leaves every cached read waiting with no bound; a lost connection is already answered as a miss without this setting.

    Set to 0 to wait without a limit.

    2000
    
    url?: string

    Redis connection URL (e.g., redis://localhost:6379, rediss://user:pass@host:6380). When options is also given, its values are applied on top of what the URL sets. The rediss:// scheme enables TLS, which is required for most cloud-hosted Redis services.