Skip to main content

Overview

The @atxp/redis package provides a Redis-based OAuth database implementation for the Authorization Token Exchange Protocol (ATXP). It offers distributed OAuth token storage using Redis, designed for scalable applications that need shared token storage across multiple server instances or require high-performance, in-memory token caching.
This package is designed to work seamlessly with @atxp/client and @atxp/express packages when you need distributed storage that can be shared across multiple application instances. For single-instance applications, consider using @atxp/sqlite instead.

Installation

The @atxp/redis package includes TypeScript definitions and requires Node.js 16 or higher. It automatically installs @atxp/common as a dependency and requires a Redis server to be running.

API Reference

Classes

RedisOAuthDatabase

The main class for managing OAuth tokens in a Redis database.
Constructor
options
RedisOAuthDatabaseOptions
required
Configuration options for the Redis database connection.
Methods
storeToken
Promise<void>
Stores an OAuth token in Redis with optional expiration.
key
string
required
Unique identifier for the token.
token
string
required
The OAuth token value to store.
expiresAt
Date
Optional expiration date for the token. If provided, Redis will automatically expire the key.
getToken
Promise<string | null>
Retrieves an OAuth token from Redis.
key
string
required
Unique identifier for the token to retrieve.
deleteToken
Promise<boolean>
Deletes an OAuth token from Redis.
key
string
required
Unique identifier for the token to delete.
hasToken
Promise<boolean>
Checks if a token exists in Redis.
key
string
required
Unique identifier for the token to check.
listTokens
Promise<string[]>
Lists all token keys stored in Redis with the configured prefix.
close
Promise<void>
Closes the Redis connection and releases resources.

Interfaces

RedisOAuthDatabaseOptions

Configuration options for the Redis OAuth database.
url
string
Complete Redis connection URL. Takes precedence over individual host/port/password/db options.
host
string
Redis server hostname. Defaults to ‘localhost’.
port
number
Redis server port. Defaults to 6379.
password
string
Redis server password for authentication.
db
number
Redis database number (0-15). Defaults to 0.
keyPrefix
string
Prefix for all Redis keys to avoid conflicts. Defaults to ‘atxp:oauth:’.
connectionTimeout
number
Connection timeout in milliseconds. Defaults to 10000.
retryDelayOnFailover
number
Delay between retry attempts in milliseconds. Defaults to 100.
maxRetriesPerRequest
number
Maximum number of retry attempts per request. Defaults to 3.

Usage Examples

Basic Setup

Create a Redis OAuth database instance:

Advanced Configuration

Configure Redis with authentication and custom settings:

Integration with ATXP Client

Use Redis storage with the ATXP client for distributed token management:

Integration with ATXP Server

Use Redis storage with the ATXP server for distributed session management:

Configuration

Connection Options

Redis supports multiple connection methods:

Environment Variables

Configure Redis connection using environment variables:

Key Management

Redis keys are automatically prefixed to avoid conflicts:

Troubleshooting

Common Issues

If you encounter connection refused errors:
  • Ensure Redis server is running
  • Check if the host and port are correct
  • Verify firewall settings allow Redis connections
  • Test connection with redis-cli
If you’re experiencing authentication failures:
  • Verify the password is correct
  • Check if Redis requires authentication
  • Ensure the username format is correct for Redis 6+
For applications with many tokens:
  • Monitor Redis memory usage
  • Configure appropriate eviction policies
  • Consider token cleanup for expired entries
  • Use Redis clustering for horizontal scaling
If you’re experiencing network timeouts:
  • Increase connection timeout values
  • Check network stability between application and Redis
  • Consider using connection pooling
  • Monitor Redis server performance

Performance Considerations

For optimal Redis performance:
  • Use Redis clustering for high availability and horizontal scaling
  • Configure appropriate memory eviction policies
  • Monitor Redis memory usage and implement cleanup strategies
  • Use connection pooling for high-concurrency applications
  • Consider Redis persistence settings based on your requirements

Migration from Other Storage

If you’re migrating from another OAuth storage solution:
  1. Export tokens from your current system
  2. Set up Redis server
  3. Import tokens using the storeToken method
  4. Update your application to use the Redis database

@atxp/client

Client-side integration for MCP clients with OAuth authentication.

@atxp/express

Server-side middleware for MCP servers with payment processing.

@atxp/sqlite

SQLite OAuth database for single-instance applications.

@atxp/common

Shared utilities and types used across ATXP packages.