SlideShare a Scribd company logo
Florida Man Uses Cache as Database.pdf
Steve Lorello
Developer Advocate
@Redis
@slorello
github.com/slorello89
twitch.tv/redisinc
● What is Redis?
● Dispelling Redis Myths
● RediSearch + JSON
● Redis OM
● Demo: FML API
Agenda
What is
?
What is Redis?
● Created by Antirez
● REmote DIctionary Server
What is Redis?
● Completely In Memory
● Key-Value Data Structure Store
What is Redis?
● Redis is Single Threaded
● Blazingly Fast NoSQL DB
● Easy to Use
● Beloved by Developers
What is Redis?
Dispelling Redis Myths
Myth 1:“Redis isn’t ACIDic”
ACID in Redis - Atomicity
● Individual Redis commands are completely atomic
● ‘Transactions’ & Scripting for grouping commands
ACID in Redis - Consistency
● Depends on deployment and config
● Single instance always consistent
● Replication guarantees eventual consistency
○ Forced consistency with “WAIT” command
ACID in Redis - Isolation
● Single Threaded
● Isolated as there’s no concurrency
Myth 2: “If Redis dies I’ll
lose all my data!”
Redis IS Durable
● Two durability persistence models
● AOF - Append Only File
● RDB - Redis Database File
Durability - Append Only File (AOF)
● With each command Redis writes to AOF
● Reconstruct Redis from AOF
● AOF flush to disk is NOT necessarily synchronous
AOF FSYNC Policy
● FSYNC policy determines durability
● always - Synchronously flush
● everysec - Flush every second
● no - OS decides
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
Myth 3: Redis cannot
store complex objects
3 Modes of Document Storage
● Hashes
● Structured Blobs
● JSON Data Structure
Hashes
● Store a set of Field-Value pairs
● Appropriate for flat objects
● Fields Names and Values are Strings
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
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
Pros:
● Native
● Performant
Cons:
● Breaks down on
more complicated
objects
● Collection storage
patterns are hard
Structured Blobs
● Store objects as JSON or some other type of blob string
● Simple pattern for storing objects in Redis
CRUD with Blobs
● SET to create
● GET to read
● GET then SET to update
● UNLINK to delete
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}”
Pros:
● Native
● Simple
Cons:
● Updates are
expensive—O(N)
● Reads are
expensive—O(N)
JSON Data Structure
● Store JSON objects directly
● JSON stored as trie structure within Redis
● Get/Update using JSON paths
● Requires use of Redis Stack
CRUD with JSON Data Structure
● JSON.SET to create/update
● JSON.GET to read
● JSON.DEL to remove fields
● UNLINK to delete
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}”
Pros:
● All operations are fast
● Organized
retrieval/update of
data within object
● Works great with rich
objects
Cons:
● Needs a module
Myth 4: Redis can’t be used for
value searches.
How to Find Objects by Value in Redis
● Build Secondary Indexes
● 2 ways
○ Manually with Sets / Sorted Sets
○ Automatically with RediSearch
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
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
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
FT.CREATE article-idx ON JSON PREFIX 1
Article: SCHEMA $.Source as source TAG
Querying Within Redis
● Use RediSearch Query Language
FT.SEARCH article-idx “@Source:{fox}”
Command Name
Index
Query
Exact Match Queries
Single - @Source:{fox}
OR - @Source:{fox|cnn}
Full Text Search
@Title:Goat
Range Queries
Inclusive - @Timestamp:[1660731559 1660731559]
Exclusive - @Timestamp:[(1660731559 (1660731559]
upper/lower bounds - @Timestamp:[-inf +inf]
redis ōM
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
Declaring Indexes in Redis OM
[Document(StorageType = StorageType.Json)]
public class Article
Declaring an Id field
[RedisIdField]
public Ulid Id { get; set; }
Field Decoration - Full Text Search
[Searchable]
public string Title { get; set; }
Field Decoration - Numerics
[Indexed]
public long Timestamp { get; set; }
Field Decoration - Exact Matches
[Indexed]
public string Source { get; set; }
Field Decoration - Embedded Objects
[Indexed(CascadeDepth = 1)]
public MetaData MetaData { get; set; }
Field Decoration - Embedded Objects
[Indexed(JsonPath = "$.Source")]
public MetaData MetaData { get; set; }
Querying with Redis OM .NET
Use the RedisCollection<T> and use LINQ
collection.Where(x => x.Title == title);
Demo
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.
Steve Lorello
Developer Advocate
@Redis
@slorello
github.com/slorello89
slorello.com
Resources
Redis
https://redis.io
Redis Search Docker Image
https://hub.docker.com/r/redislabs/redisearch/
Redis OM
https://github.com/redis/redis-om-dotnet
Slides
https://www.slideshare.net/StephenLorello/indexing-searching-and-aggregation-
with-redi-search-and-net
Come Check Us Out!
Redis University:
https://university.redis.com
Discord:
https://discord.gg/redis

More Related Content

PDF
An Introduction to Redis for .NET Developers.pdf
PDF
An Introduction to Redis for Developers.pdf
PPTX
Introduction to Redis
PPTX
Redis Modules - Redis India Tour - 2017
PPTX
PPTX
Redis data structure and Performance Optimization
PPTX
Introduction to Redis
PDF
Introduction to Redis
An Introduction to Redis for .NET Developers.pdf
An Introduction to Redis for Developers.pdf
Introduction to Redis
Redis Modules - Redis India Tour - 2017
Redis data structure and Performance Optimization
Introduction to Redis
Introduction to Redis

Similar to Florida Man Uses Cache as Database.pdf (20)

PDF
Indexing, searching, and aggregation with redi search and .net
PDF
mar07-redis.pdf
PPTX
Redis_Presentation.pptx ppt on redis and
PDF
Use Redis in Odd and Unusual Ways
PDF
#SydPHP - The Magic of Redis
PPTX
Get more than a cache back! - ConFoo Montreal
PPTX
REDIS327
PDF
Redis Workshop on Data Structures, Commands, Administration
PPTX
Redis database
PDF
Paris Redis Meetup Introduction
PDF
SDEC2011 NoSQL concepts and models
PDF
Introduction to Redis
ODP
Redis overview
PPTX
Redis Use Patterns (DevconTLV June 2014)
PDF
Redis overview
PDF
Introduction of Redis as NoSQL Database
PPTX
10 Ways to Scale with Redis - LA Redis Meetup 2019
PDF
Tuga IT 2017 - Redis
PDF
Redis basics
PPTX
redis-demo.pptx
Indexing, searching, and aggregation with redi search and .net
mar07-redis.pdf
Redis_Presentation.pptx ppt on redis and
Use Redis in Odd and Unusual Ways
#SydPHP - The Magic of Redis
Get more than a cache back! - ConFoo Montreal
REDIS327
Redis Workshop on Data Structures, Commands, Administration
Redis database
Paris Redis Meetup Introduction
SDEC2011 NoSQL concepts and models
Introduction to Redis
Redis overview
Redis Use Patterns (DevconTLV June 2014)
Redis overview
Introduction of Redis as NoSQL Database
10 Ways to Scale with Redis - LA Redis Meetup 2019
Tuga IT 2017 - Redis
Redis basics
redis-demo.pptx
Ad

Recently uploaded (20)

PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Machine learning based COVID-19 study performance prediction
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
Machine Learning_overview_presentation.pptx
PPTX
Cloud computing and distributed systems.
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
A Presentation on Artificial Intelligence
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
cuic standard and advanced reporting.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Electronic commerce courselecture one. Pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
sap open course for s4hana steps from ECC to s4
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Encapsulation_ Review paper, used for researhc scholars
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Machine learning based COVID-19 study performance prediction
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Programs and apps: productivity, graphics, security and other tools
Machine Learning_overview_presentation.pptx
Cloud computing and distributed systems.
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
A Presentation on Artificial Intelligence
Mobile App Security Testing_ A Comprehensive Guide.pdf
MIND Revenue Release Quarter 2 2025 Press Release
cuic standard and advanced reporting.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Electronic commerce courselecture one. Pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Chapter 3 Spatial Domain Image Processing.pdf
sap open course for s4hana steps from ECC to s4
gpt5_lecture_notes_comprehensive_20250812015547.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Ad

Florida Man Uses Cache as Database.pdf