Redis-compatible core data structures with String, List, Hash, and Set operations
Kora provides a rich set of Redis-compatible data structures designed for high-performance caching and in-memory storage. The key-value store is sharded across multiple threads for parallel execution and implements lazy TTL expiration.
# Store a simple stringSET user:1000:name "Alice"# Retrieve itGET user:1000:name# => "Alice"# Store with expiration (10 seconds)SET session:abc123 "user_data" EX 10# Store only if key doesn't existSET counter:visitors 0 NX
# Push to the head (left)LPUSH queue:tasks "task1" "task2" "task3"# => 3# Push to the tail (right)RPUSH queue:tasks "task4"# => 4# Pop from the headLPOP queue:tasks# => "task3"# Pop from the tailRPOP queue:tasks# => "task4"
# Get list lengthLLEN queue:tasks# => 2# Get range of elements (0-based, inclusive)LRANGE queue:tasks 0 -1# => ["task2", "task1"]# Get element at indexLINDEX queue:tasks 0# => "task2"
# Set element at indexLSET queue:tasks 0 "updated_task"# Insert before/after pivotLINSERT queue:tasks BEFORE "task1" "new_task"# Remove elementsLREM queue:tasks 1 "task1" # remove 1 occurrence# Trim list to rangeLTRIM queue:tasks 0 99 # keep first 100 items
# Set single fieldHSET user:1000 name "Alice" age "30" city "NYC"# => 3# Get single fieldHGET user:1000 name# => "Alice"# Get all fields and valuesHGETALL user:1000# => ["name", "Alice", "age", "30", "city", "NYC"]
# Get multiple fieldsHMGET user:1000 name age# => ["Alice", "30"]# Get all field namesHKEYS user:1000# => ["name", "age", "city"]# Get all valuesHVALS user:1000# => ["Alice", "30", "NYC"]
# Get cardinalitySCARD tags:post1# => 3# Remove membersSREM tags:post1 "database"# => 1# Pop random memberSPOP tags:post1# => "performance"# Get random member without removingSRANDMEMBER tags:post1# => "rust"
# Set expiration in secondsEXPIRE session:abc 3600# Set expiration in millisecondsPEXPIRE cache:user:1000 60000# Get remaining TTLTTL session:abc# => 3599# Remove expirationPERSIST session:abc
# Count keys in databaseDBSIZE# => 42# Scan keys with patternSCAN 0 MATCH user:* COUNT 100# List keys (use with caution in production)KEYS user:*# Flush databaseFLUSHDB
/// Per-shard key-value store with full command execution.////// `ShardStore` is the workhorse of the Kōra engine. Each shard worker thread/// owns exactly one instance, so every operation runs single-threaded with no/// locking. The store handles:////// - String, list, hash, set, sorted set, stream, HyperLogLog, bitmap, and/// geo commands./// - Lazy TTL expiration on access plus periodic bounded-sample sweeps./// - LFU-based eviction when a memory limit is configured.