Getting Started
Complete reference for all Redix operations
Overview
Redix provides over 80 operations organized into logical categories. Each operation is designed to be simple, intuitive, and performant.
Operation Categories
Key-Value Operations
Basic Redis operations for storing and retrieving data with automatic JSON serialization.
Operations: Save, Get, GetMultiple, SetMultiple, Exists, GetKeys, Invalidate, InvalidateMultiple, InvalidatePrefix, Rename, Type, Expire, TTL, Persist
Counter Operations
Atomic operations for incrementing and decrementing numeric values.
Operations: Increment, Decrement, IncrementFloat
Hash Operations
Operations for managing Redis hashes, perfect for objects with multiple fields.
Operations: HSet, HSetMultiple, HGet, HGetMultiple, HGetAll, HDelete, HExists, HKeys, HValues, HLength, HIncrementBy, HIncrementByFloat
List Operations
Operations for ordered collections, queues, and stacks.
Operations: LPush, RPush, LPop, RPop, LRange, LLength, LIndex, LSet, LTrim, LRemove
Set Operations
Operations for unique collections and set mathematics.
Operations: SAdd, SRemove, SMembers, SIsMember, SCard, SPop, SRandMember, SUnion, SInter, SDiff
Sorted Set Operations
Operations for scored collections, perfect for leaderboards and rankings.
Operations: ZAdd, ZRange, ZRangeByScore, ZRevRange, ZRemove, ZCard, ZScore, ZRank, ZRevRank, ZIncrBy, ZCount, ZRemRangeByRank, ZRemRangeByScore
JSON Operations
Operations for complex JSON documents with RedisJSON.
Operations: JSONSet, JSONGet, JSONGetMultiple, JSONMGet, JSONDel, JSONType, JSONNumIncrBy, JSONNumMultBy, JSONArrAppend, JSONArrIndex, JSONArrInsert, JSONArrLen, JSONArrPop, JSONArrTrim, JSONStrAppend, JSONStrLen, JSONObjKeys, JSONObjLen, JSONToggle, JSONClear
Pub/Sub Operations
Publish/Subscribe operations for real-time messaging.
Operations: Subscribe, Unsubscribe, Publish, PSubscribe, PUnsubscribe
Utility Operations
System operations for management and monitoring.
Operations: Ping, Info, FlushDB, Execute, GetInstance, Test
Quick Reference
-- Get the Redix interface
local Redix = exports.redix:GetInterface()
-- Key-Value
Redix.Save('key', value, expires)
Redix.Get('key', callback)
-- Counters
Redix.Increment('counter', amount)
Redix.Decrement('counter', amount)
-- Hashes
Redix.HSet('hash', 'field', value)
Redix.HGetAll('hash', callback)
-- Lists
Redix.RPush('list', value)
Redix.LPop('list', callback)
-- Sets
Redix.SAdd('set', member)
Redix.SMembers('set', callback)
-- Sorted Sets
Redix.ZAdd('zset', score, member)
Redix.ZRevRange('zset', 0, 9, callback)
-- JSON
Redix.JSONSet('key', '$', jsonData)
Redix.JSONGet('key', '$', callback)
-- Pub/Sub
Redix.Subscribe('channel', callback)
Redix.Publish('channel', message)
-- Utilities
Redix.Ping(callback)
Redix.Info('stats', callback)Common Patterns
Caching
-- Try cache first
Redix.Get('cache:' .. id, function(err, cached)
if cached then
return cached
end
-- Fetch from database
local data = FetchFromDB(id)
-- Cache for 5 minutes
Redix.Save('cache:' .. id, data, 300)
return data
end)Leaderboards
-- Update score
Redix.ZAdd('leaderboard', score, playerName)
-- Get top 10
Redix.ZRevRange('leaderboard', 0, 9, 'WITHSCORES', callback)Real-Time Events
-- Subscribe to events
Redix.Subscribe('events', function(message)
local event = json.decode(message)
HandleEvent(event)
end)
-- Publish event
Redix.Publish('events', json.encode(eventData))