Class RedisListHelper
java.lang.Object
net.bugreaper.modules.redis.helpers.RedisHelper<RedisListHelper>
net.bugreaper.modules.redis.helpers.RedisListHelper
- All Implemented Interfaces:
RedisHelperInt
Helper class for interacting with Redis LIST data types.
This class provides convenient methods for common Redis LIST operations, including adding records, reading records, counting records, checking TTL, and cleaning list data.
Redis LIST is an ordered collection of string values.
Example of stored records:
users:admins
├── 0 -> {"id":1,"name":"Alex"}
├── 1 -> {"id":2,"name":"John"}
└── 2 -> {"id":3,"name":"Michael"}
In this example:
users:adminsis the Redis LIST key0,1,2are LIST indexes- JSON objects are LIST elements stored as strings
- The order of records is preserved by insertion order
Notes:
- TTL is applied to the whole LIST key, not individual records.
- Records are stored as Redis strings inside the LIST. JSON values can be stored as plain strings.
- This helper uses
JedisPoolinternally to manage Redis connections.
- See Also:
-
JedisJedisPool
-
Field Summary
Fields inherited from class net.bugreaper.modules.redis.helpers.RedisHelper
awaitMs, jedisPool, SCAN_BATCH_SIZE -
Constructor Summary
ConstructorsConstructorDescriptionRedisListHelper(String host, int port, String username, String password) This constructor initializes client for interaction with Redis LIST data types -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a new record to the Redis LIST.voidAdds a new record to the Redis LIST and sets expiration time for the key.longReturns the number of records stored in the specified Redis LIST.net.bugreaper.core.assertable.AssertableStringListgrabRecordsByKey(String key) Returns all records stored in the specified Redis LIST.Methods inherited from class net.bugreaper.modules.redis.helpers.RedisHelper
attachAndLogList, checkKeyExists, checkKeyTypeIs, cleanAll, deleteKeysByPattern, execute, executeReturn, getConfigSummary, getKeyExistsStatus, getKeysCountByPattern, getKeyType, getPrefix, getTtlByKey, seeKeyExists, seeKeysCountByPatternIsExactly, seeKeysCountByPatternIsGreaterThan, seeKeysCountByPatternIsLessThan, seeKeyTypeIs, seeRecordsCountByKeyIsExactly, seeTtlIsGreaterThan, seeTtlIsLessThan, setAwaitMsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.bugreaper.modules.redis.interfaces.RedisHelperInt
cleanAll, deleteKeysByPattern, getKeyExistsStatus, getKeysCountByPattern, getKeyType, getTtlByKey, seeKeyExists, seeKeysCountByPatternIsExactly, seeKeysCountByPatternIsGreaterThan, seeKeysCountByPatternIsLessThan, seeKeyTypeIs, seeRecordsCountByKeyIsExactly, seeTtlIsGreaterThan, seeTtlIsLessThan
-
Constructor Details
-
RedisListHelper
This constructor initializes client for interaction with Redis LIST data types- Parameters:
host- host of Redis"localhost"port- port of Redisusername- admin usernamepassword- admin password
-
-
Method Details
-
addRecord
Adds a new record to the Redis LIST.Example:
users:admins ├── 0 -> Alex └── 1 -> John addRecord("users:admins", "Alex");- Specified by:
addRecordin interfaceRedisHelperInt- Parameters:
key- Redis LIST keyvalue- record value to add
-
addRecord
@Step("(Redis) Insert record into key <{key}> with ttl: <{ttlSeconds}>") public void addRecord(String key, String value, long ttlSeconds) Adds a new record to the Redis LIST and sets expiration time for the key.TTL is applied to the whole LIST, not to an individual record.
Example:
addRecord( "users:admins", "Alex", 300 );- Specified by:
addRecordin interfaceRedisHelperInt- Parameters:
key- Redis LIST keyvalue- record value to addttlSeconds- expiration time in seconds
-
grabRecordsByKey
@Step("(Redis) Grab records from key: {key}") public net.bugreaper.core.assertable.AssertableStringList grabRecordsByKey(String key) Returns all records stored in the specified Redis LIST.Uses await until the key exists.
The records are returned in insertion order (head to tail).
Examples:
users:admins ├── 0 -> "Alex" ├── 1 -> "John" grabRecordsByKey("users:admins") .seeListAnyEquals("John");- Specified by:
grabRecordsByKeyin interfaceRedisHelperInt- Parameters:
key- Redis LIST key- Returns:
AssertableStringListlist of stored records- Throws:
AssertionError- if the key does not exist or not a Redis LIST
-
getRecordsCountByKey
Returns the number of records stored in the specified Redis LIST.This method uses Redis
LLENcommand.Example:
users:admins ├── 0 -> record1 ├── 1 -> record2 getRecordsCountByKey("users:admins") returns 2- Specified by:
getRecordsCountByKeyin interfaceRedisHelperInt- Parameters:
key- Redis LIST key- Returns:
- number of records in the LIST
-