How to use the API
There are basically 4 ways to use this library. And each way has two or three ways of handling data (String vs ByteArray vs Streaming):
| String values | ByteArray values | Streaming | |
|---|---|---|---|
| 1) RedisConnectionPool | ✅ | ✅ | N/A |
| 2) RedisConnection | ✅ | ✅ | ✅ |
| 3) Pipeline | ✅ | ✅ | ✅ |
| 4) low-level API | N/A | N/A | ✅ |
1) Using the connection pool directly
For your convenience, all implemented commands also provide extension functions directly on the connection pool, such that you don't need to bother about checking out/in a connection first. Example:
import com.dehnes.kotlinredis.extentions.string.set
import com.dehnes.kotlinredis.extentions.string.getString
connPool.set("foo", "bar")
val fooValue = connPool.getString("foo")
2) Using the connection handle
The same extension functions are provided for use directly on the connection:
import com.dehnes.kotlinredis.extentions.string.set
import com.dehnes.kotlinredis.extentions.string.getString
connPool.withConnection { connection ->
connection.set("foo", "bar")
val fooValue = connection.getString("foo")
}
3) Pipeline builder
When you want to send several commands in one batch, you can use the pipeline builder on the connection:
Theresults returned from the pipeline contains all collected results,
which in this case is a Boolean and a String?:
4) Using the low level API
See here.