Redis-lettuce plugin

The Redis-lettuce plugin connects QALIPSIS to Redis.

Technology addressed

Redis: https://redis.io/

Dependency

io.qalipsis.plugin:qalipsis-plugin-redis-lettuce

Namespace in scenario

redisLettuce()

Client library

Lettuce: refer to Lettuce.

Supported steps
  • poll: polls the newest data periodically.

  • save: saves a batch of records generated from the input and step context.

  • consume: consumes data from Redis streams.

  • produce: pushes messages to Redis streams.

Example scenarios using a combination of Redis supported steps are provided on Github.

Poll step

The poll step within the Redis-lettuce plugin polls the newest records from a Redis key, with a delay between each execution of polling.

Ancestor

Scenario

Functionality

The poll step is created only once in a scenario; it is then used throughout the scenario as called.

  • The KeyOrPattern to be used in the poll is set to one of the following valid values: scan, sscan, hscan, zscan.

  • The native Redis-lettuce command is called using the KeyOrPattern provided.

Example
it.redisLettuce()
  .pollSscan {
    connection {
      nodes = listOf("localhost:6379")
      database = 0
      redisConnectionType = RedisConnectionType.SINGLE
      authUser = "Celia45"
      authPassword = "Columbus1963"
    }
    keyOrPattern("battery_state_save_and_poll")
    pollDelay(Duration.ofSeconds(1))
  }
Notable parameters
  • Connection (required): specifies the connection parameters.

  • redisConnectionType (required): indicates the connection type as SINGLE, CLUSTER or SENTINEL.

  • KeyOrPattern (required): specifies the key or pattern that will be polled after each pollDelay.

  • pollDelay (required): specifies the delay between query executions.

  • broadcast (optional): specifies the broadcast parameters for the step.

Tips
  • Use the poll step with a join operator when you need to verify the values saved by your tested system in the database.

  • In addition to SSCAN (pollSscan in the example), the poll step also supports the following Redis commands: HSCAN (polllHscan) SCAN (pollScan), and ZSCAN (pollZscan).

Reference documentation

Save step

The save step within the Redis-lettuce plugin persists a batch of records into Redis.

Ancestor

Step

Functionality

The save step’s input and step context are used to generate a valid Redis command and the values to complete it; the batch of results is then forwarded to the next step(s). The records are saved individually.

Example
.redisLettuce()
.save {
  connection {
    nodes = listOf("localhost:6379")
    database = 0
    redisConnectionType = RedisConnectionType.SINGLE
      authUser = "Celia45"
      authPassword = "Columbus1963"
  }

  records { _, input ->
    listOf(
      SetRecord("battery_state_save_and_poll",
        objectMapper.writeValueAsString(input)
      )
    )
  }
}
Notable parameters
  • Connection (required): specifies the connection parameters.

  • redisConnectionType (required): indicates the connection type as SINGLE, CLUSTER or SENTINEL.

  • records (required): generates and configures a list of saved records.

Tip
  • The save step supports the following Redis commands: SET, SADD, HSET, ZADD. The provided command may depend on the context and input value received from the previous step.

  • If the redisConnectionType is set to SENTINEL, the parameter masterId is necessary.

Reference documentation

Consume step

The consume step within the Redis-lettuce plugin records data from Redis streams.

Ancestor

Scenario

Functionality

The consume step creates a consumer group in a Redis stream with the provided connection, consumer group name, and concurrency. If concurrency is set to 1, records are transmitted sequentially to the next step.

Example
redisLettuce()
.streamsConsume {
  connection {
    nodes = redis://localhost:6439
    database = 0
    redisConnectionType = RedisConnectionType.SINGLE
      authUser = "Celia45"
      authPassword = "Columbus1963"
  }
  streamKey("battery_state_produce_and_consume")
  offset(LettuceStreamsConsumerOffset.FROM_BEGINNING)
  group("consumer")
}
Notable parameters
  • connection (required): configures the connection to QALIPSIS.

  • redisConnectionType (required): indicates the connection type as SINGLE, CLUSTER or SENTINEL. The default is SINGLE.

  • offset (required): sets the offset value to FROM_BEGINNING, LAST_CONSUMED or LATEST for each topic and consumer group.

  • broadcast (optional): specifies the broadcast parameters for the step.

Tip

If redisConnectionType is set to SENTINEL, the parameter masterId is necessary.

Reference documentation

Produce step

The produce step within the Redis-lettuce plugin produces records into the Redis streams.

Ancestor

Step

Example
.redisLettuce()
.streamsProduce {
  connection {
    nodes = listOf("localhost:6379")
    database = 0
    redisConnectionType = RedisConnectionType.SINGLE
      authUser = "Celia45"
      authPassword = "Columbus1963"
  }

  records { _, input ->
    listOf(
      LettuceStreamsProduceRecord(
        key = "battery_state_produce_and_consume", value = mapOf(
        "device_id" to input.deviceId,
        "timestamp" to input.timestamp.epochSecond.toString(),
        "battery_level" to input.batteryLevel.toString()
        )
      )
    )
  }
}
Notable parameters
  • redisConnectionType (required): sets the connection type as SINGLE, CLUSTER or SENTINEL.

  • records (required): generates and configures a list of produced records.

Tip
  • If redisConnectionType is set to SENTINEL, the parameter masterId is necessary.

Reference documentation