API ReferenceHashes
Overview
Hashes are maps between string field names and string values. They are perfect for representing objects with multiple attributes, such as user profiles, game entities, or configuration settings. Hashes are more memory-efficient than storing each field as a separate key.
Available Operations
Basic Operations
- HSet - Set a single field in a hash
- HSetMultiple - Set multiple fields at once
- HGet - Get a single field value
- HGetMultiple - Get multiple field values
- HGetAll - Get all fields and values
- HDelete - Delete one or more fields
- HExists - Check if a field exists
- HKeys - Get all field names
- HValues - Get all values
- HLength - Get number of fields
Numeric Operations
- HIncrementBy - Increment an integer field
- HIncrementByFloat - Increment a float field
Use Cases
- Player profiles with multiple attributes
- Vehicle data storage
- Configuration per entity
- Statistics tracking
- Object properties with many fields
Quick Example
local Redix = exports.redix:GetInterface()
-- Set player profile
Redix.HSetMultiple('player:123', {
name = 'John',
level = 50,
money = 10000
})
-- Get all data
Redix.HGetAll('player:123', function(err, data)
print('Name:', data.name, 'Level:', data.level)
end)
-- Increment field
Redix.HIncrementBy('player:123', 'money', 500)