11. ACID in Redis - Atomicity
● Individual Redis commands are completely atomic
● ‘Transactions’ & Scripting for grouping commands
12. ACID in Redis - Consistency
● Depends on deployment and config
● Single instance always consistent
● Replication guarantees eventual consistency
○ Forced consistency with “WAIT” command
13. ACID in Redis - Isolation
● Single Threaded
● Isolated as there’s no concurrency
14. Myth 2: “If Redis dies I’ll
lose all my data!”
15. Redis IS Durable
● Two durability persistence models
● AOF - Append Only File
● RDB - Redis Database File
16. Durability - Append Only File (AOF)
● With each command Redis writes to AOF
● Reconstruct Redis from AOF
● AOF flush to disk is NOT necessarily synchronous
17. AOF FSYNC Policy
● FSYNC policy determines durability
● always - Synchronously flush
● everysec - Flush every second
● no - OS decides
18. Durability - Redis Database file (RDB)
● RDBs are snapshots of the database
● Taken in intervals, or by command
● More compact and faster to ingest than AOF
● Less strain on OS than AOF
● Comes at cost of higher potential data loss
20. 3 Modes of Document Storage
● Hashes
● Structured Blobs
● JSON Data Structure
21. Hashes
● Store a set of Field-Value pairs
● Appropriate for flat objects
● Fields Names and Values are Strings
22. CRUD with Hashes
● HSET (which is variadic) to create/update
● HGET/HMGET/HGETALL to get fields in the hash
● HDEL/UNLINK to delete fields/objects
23. HSET Article:1 Source CNN Title “Florida man …” Timestamp 1654122480
Article:1
Source CNN
Title Florida man watches
Spider-Man movie
292 times, setting
new world record
Timestamp 1654122480
25. Structured Blobs
● Store objects as JSON or some other type of blob string
● Simple pattern for storing objects in Redis
26. CRUD with Blobs
● SET to create
● GET to read
● GET then SET to update
● UNLINK to delete
27. SET Article:1 “{‘source’:‘cnn’,‘Title’: ‘Florida man watches. . .’,
‘Timestamp’:1654122480}”
“{‘source’:‘cnn’,‘Title’: ‘Florida man watches Spider-Man movie 292
times, setting new world record’, ‘Timestamp’:1654122480}”
29. JSON Data Structure
● Store JSON objects directly
● JSON stored as trie structure within Redis
● Get/Update using JSON paths
● Requires use of Redis Stack
30. CRUD with JSON Data Structure
● JSON.SET to create/update
● JSON.GET to read
● JSON.DEL to remove fields
● UNLINK to delete
31. JSON.SET Article:1 $ “{‘source’:‘cnn’,‘Title’: ‘Florida man watches. . .’,
‘Timestamp’:1654122480}”
“{‘source’:‘cnn’,‘Title’: ‘Florida man watches Spider-Man movie 292
times, setting new world record’, ‘Timestamp’:1654122480}”
32. Pros:
● All operations are fast
● Organized
retrieval/update of
data within object
● Works great with rich
objects
Cons:
● Needs a module
34. How to Find Objects by Value in Redis
● Build Secondary Indexes
● 2 ways
○ Manually with Sets / Sorted Sets
○ Automatically with RediSearch
35. Indexing With Sorted Sets
● User Sorted Sets as indexes
● E.g.
○ Article:Source:Fox {(0, Article:1), (0, Article:2)}
○ Article:Timestamp {(1654122480, Article:1), (1654133475, Article:2)}
● Query with ZRANGE Commands
● Complex queries run with SET Combination commands
36. Indexing with RediSearch
● Three step process
● Declare how your Documents will be indexed with
FT.CREATE
● Insert your Documents as either Hashes or JSON
● Query Your Documents with FT.SEARCH
37. Build the Index FT.CREATE
● Declare Prefix of keys within Index
● Declare Storage Type(Hash or JSON)
● Declare the Schema - five types of fields
○ TAG
○ TEXT
○ NUMERIC
○ GEO
○ VECTOR
45. Redis OM Highlights
● Declarative syntax for creating indexes
● LINQ Based API for searching for things in Redis
● LINQ Based API for aggregating things in Redis
58. Code PaLOUsa CoC
Code PaLOUsa is dedicated to providing a harassment-free
conference experience for everyone, regardless of gender,
sexual orientation, disability, physical appearance, body size,
race, or religion. We do not tolerate harassment of
conference participants in any form. Sexual language and
imagery is not appropriate for any conference venue,
including talks. Conference participants violating these rules
may be sanctioned or expelled from the conference without a
refund at the discretion of the conference organizers.