API ReferenceKeys
Overview
Key-value operations are the foundation of Redix. These operations allow you to save, retrieve, and manage simple or complex data associated with keys with automatic JSON serialization.
Available Operations
Basic Operations
- Save - Save data to a key with optional expiration
- Get - Retrieve data from a key
- GetMultiple - Retrieve multiple keys at once
- SetMultiple - Set multiple key-value pairs at once
Key Management
- Exists - Check if a key exists
- GetKeys - Get all keys matching a pattern
- Invalidate - Delete a single key
- InvalidateMultiple - Delete multiple keys
- InvalidatePrefix - Delete keys by prefix
- Rename - Rename a key
- Type - Get the data type of a key
Expiration Management
- Expire - Set expiration time on a key
- TTL - Get time-to-live of a key
- Persist - Remove expiration from a key
Use Cases
Key-value operations are perfect for:
- Player data storage with automatic JSON serialization
- Session management with automatic expiration
- Caching expensive database queries
- Temporary data that needs TTL
- Configuration storage
Quick Example
local Redix = exports.redix:GetInterface()
-- Save player data with 1-hour expiration
Redix.Save('player:123', {
name = 'John',
level = 50
}, 3600)
-- Retrieve player data
Redix.Get('player:123', function(err, data)
print('Player:', data.name, 'Level:', data.level)
end)
-- Check if exists
Redix.Exists('player:123', function(err, exists)
if exists then
print('Player exists')
end
end)