RedisUtils
Factory methods and extension functions for creating and using Redis connections via Jedis.
Pool sizing and wait time can be configured via system properties or method parameters. The default Redis URL is read from the REDIS_URL environment variable.
Only the redis and rediss (TLS) schemes are accepted, in any case. Any other scheme, including TLS spellings such as tls or redis+tls, is rejected rather than connecting without TLS.
A URL without a port uses 6379. A URL that can never work (one that is malformed, has no host, has another scheme or a port that is not a number from 1 to 65535, has a path other than a database index such as /3, carries an unknown protocol, or has an @ in its query or fragment) is a configuration error: every function that takes a URL throws IllegalArgumentException for it, rather than treating it as a connection failure. No such message repeats any part of the URL, which may hold a password.
Percent-escapes in the user name and password are decoded after the user info is split at its first :, so an escaped %3A stays in the user name, and a literal + stays a +. A /, ?, # or @ in either must be percent-encoded (%2F, %3F, %23, %40): unescaped, an @ ends the user info too early, and each of the others ends the authority before the host. An unescaped / leaves a path that is not a database index, and an unescaped ? or # leaves the @ and the real host in the query or fragment, so each such URL is rejected rather than connecting to the user name as the host.
Properties
System property key for the maximum number of idle connections.
System property key for the maximum connection pool size.
System property key for the maximum wait time (in seconds) when borrowing a connection.
System property key for the minimum number of idle connections.
Pool size meaning "no limit", as defined by commons-pool2.
Functions
Escapes this string for use as literal text in a Redis glob pattern, such as a scanKeys pattern or the pattern of KEYS, SCAN ... MATCH, HSCAN, SSCAN or ZSCAN.
Creates a new pooled RedisClient with the given configuration.
Suspending variant of withNonNullRedis. Creates a short-lived connection, executes a suspending block, and closes it. Returns null if the connection fails. Connecting, pinging and closing run on Dispatchers.IO; block runs in the caller's context. Cancellation while connecting closes the client without running block, as in withSuspendingRedis.
Suspending variant of withNonNullRedisPool. Executes a suspending block with this RedisClient, returning null if the connection fails.
Suspending variant of withRedisPool. Executes a suspending block with this RedisClient, passing null if the connection fails.