withRedis

fun <T> withRedis(redisUrl: String = defaultRedisUrl, printStackTrace: Boolean = false, block: (RedisClient?) -> T): T

Creates a short-lived RedisClient connection, executes block, and closes the client.

The connection is verified with a ping before block runs, so an unreachable server, a pool that cannot lend a connection, or an authentication failure all pass null to block instead of failing on the first command.

Return

the result of block

Parameters

redisUrl

the Redis connection URL

printStackTrace

if true, logs the full stack trace on connection failure

block

the operation to execute; receives null on connection failure

Type Parameters

T

the return type of the block

Throws

if redisUrl is invalid (see RedisUtils); block is not run