For the complete documentation index, see llms.txt. This page is also available as Markdown.

API Usage

Comprehensive guide to using the BoxLang Redis Module API for advanced caching and data management in BoxLang applications.

🔌 Overview

If you need more power or are familiar with the Redis Java API and want to use features beyond the standard cache interface, the bx-redis module provides direct access to the underlying Redis connections and providers. Behind the scenes, the module leverages the Jedis library for Redis connectivity.

This page documents the low-level API functions available for advanced Redis operations.

🛠️ Available Functions

The module provides several global BoxLang functions to access the underlying Redis infrastructure:

Function
Purpose
Returns

redisGetProvider()

Get the cache provider implementation

IRedisCache interface

redisGetConnectionPool()

Get the Jedis connection pool (non-clustered)

JedisPool

redisGetCluster()

Get the Redis cluster connection

JedisCluster

redisGetClusterNodes()

Get map of cluster node connections

Map<String, JedisPool>

📋 Function Reference

redisGetProvider()

Returns the BoxLang Redis cache provider implementation. This gives you access to the IRedisCache interface, which extends BoxLang's standard ICacheProvider with Redis-specific functionality.

Syntax:

provider = redisGetProvider( [ cacheName ] )

Parameters:

Parameter
Type
Required
Default
Description

cacheName

string

No

"default"

The name of the configured Redis cache

Returns: ortus.boxlang.modules.redis.cache.IRedisCache

Throws: InvalidCacheType if the specified cache is not a Redis cache

Example:

Use Cases:

  • Accessing Redis-specific cache operations

  • Getting cache statistics and metadata

  • Performing bulk operations

  • Direct cache provider manipulation

redisGetConnectionPool()

Returns the Jedis connection pool for non-clustered Redis caches. This provides direct access to the redis.clients.jedis.JedisPool for low-level Redis operations.

Syntax:

Parameters:

Parameter
Type
Required
Default
Description

cacheName

string

No

"default"

The name of the configured Redis cache (must be non-clustered)

Returns: redis.clients.jedis.JedisPool

Throws:

  • InvalidCacheType if the cache is not a Redis cache

  • Exception if called on a clustered cache

Example:

Use Cases:

  • Direct Jedis API access

  • Redis commands not exposed through cache interface

  • Performance-critical operations requiring connection pooling

  • Custom Redis operations

redisGetCluster()

Returns the Redis cluster connection for clustered deployments. Provides access to redis.clients.jedis.JedisCluster for cluster-specific operations.

Syntax:

Parameters:

Parameter
Type
Required
Default
Description

cacheName

string

No

"default"

The name of the configured Redis cache (must be clustered)

Returns: redis.clients.jedis.JedisCluster

Throws:

  • InvalidCacheType if the cache is not a Redis cache

  • Exception if called on a non-clustered cache

Example:

Use Cases:

  • Cluster-specific Redis commands

  • Cluster topology inspection

  • Slot management

  • Multi-key operations across cluster

redisGetClusterNodes()

Returns a map of all cluster node connections. Each entry provides a JedisPool for a specific cluster node.

Syntax:

Parameters:

Parameter
Type
Required
Default
Description

cacheName

string

No

"default"

The name of the configured Redis cache (must be clustered)

Returns: Map<String, redis.clients.jedis.JedisPool>

Throws:

  • InvalidCacheType if the cache is not a Redis cache

  • Exception if called on a non-clustered cache

Example:

Use Cases:

  • Node-specific operations

  • Health checking individual nodes

  • Gathering per-node statistics

  • Debugging cluster issues

💡 Advanced Usage Examples

Custom Redis Command Execution

Pipeline Operations

Transaction Support

Cluster Slot Information

Monitoring and Statistics

⚠️ Best Practices

Connection Management

  • Always close Jedis resources - Use try/finally blocks or BoxLang's try-with-resources

  • Don't hold connections - Get, use, and return connections quickly

  • Pool size configuration - Configure appropriate connection pool sizes in your cache settings

Error Handling

  • Catch Redis-specific exceptions - Handle JedisException and connection errors

  • Implement retry logic - For transient network failures

  • Validate cache type - Check cache is Redis before calling these functions

Performance Considerations

  • Use pipelining - For bulk operations to reduce round trips

  • Avoid KEYS command - Use SCAN in production environments

  • Connection pooling - Reuse connections via the pool

  • Cluster awareness - Use cluster-aware operations for distributed caches

Security

  • Protect credentials - Use environment variables for Redis passwords

  • Limit command access - Use Redis ACLs if available

  • Network security - Use SSL/TLS for production deployments

  • Connection validation - Enable pool validation to detect stale connections

🔍 Debugging

Enable Debug Logging

Test Connectivity

Monitor Commands

Last updated

Was this helpful?