The Redis module allows services to write to a Redis store or retrieve data from there.
Client
The redisClient can be used to load or store data directly within a message handler function.
Application.create()
// ...
.services()
.add("redis", redisClient({ /* configuration */ }))
.done()
.dispatch({
onIMyObject: async (msg: IMyObject, ctx: IDispatchContext): Promise<void> => {
const redis = ctx.services.get<IRedisClient>("redis");
// write/overwrite the object associated with a keyawait redis.putObject(ctx.trace.context, IMyObject, msg, "some-key");
// retrieve the object associated with a key (returns undefined if no such key)const msg = await redis.getObject(ctx.trace.context, IMyObject, "some-key");
},
})
.run();
Configuration
Name
Description
host
the HTTP endpoint to connect to
port
the port to connect to. Default is 6379
db
index of the database to connect to. Default is 0
password
the password to use to connect to Redis. Default is no password
encoder
the encoder to use when converting the payload to a byte array. This defaults to the NullMessageEncoder which only supports Buffers (=byte arrays) being published
typeMapper
only required if correct type information needs to be emitted
base64Encode
determines if buffers should be stored in base64 encoding. Default is true
Metrics
Name
Description
Type
Tags
cookie_cutter.redis_client.get
A call to get a value
increment
type, db, result
cookie_cutter.redis_client.set
A call to set a value
increment
type, db, result
cookie_cutter.redis_client.xadd
A call to add a value to a stream
increment
type, db, result
cookie_cutter.redis_client.xread
A call to read from a stream
increment
type, db, result
cookie_cutter.redis_client.xreadgroup
A call to read from a a stream as part of a consumer group
increment
type, db, result
cookie_cutter.redis_client.xgroup
A call to create a consumer group
increment
type, db, result
cookie_cutter.redis_client.xack
A call to acknowledge a message in a stream
increment
type, db, result
cookie_cutter.redis_client.xpending
A call to query pending messages list of a stream
increment
type, db, result
cookie_cutter.redis_client.xclaim
A call to claim a pending message of a stream
increment
type, db, result
redisStreamSource
The redisStreamSource function creates a new input source that receives messages from Redis. The example below joins the consumer group consumer-group-1 and receives JSON encoded messages from streams stream1, stream2 and stream3.