SlideShare a Scribd company logo
1 of 61
Download to read offline
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

Similar to Florida Man Uses Cache as Database.pdf

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

No SQL : Which way to go? Presented at DDDMelbourne 2015
No SQL : Which way to go?  Presented at DDDMelbourne 2015No SQL : Which way to go?  Presented at DDDMelbourne 2015
No SQL : Which way to go? Presented at DDDMelbourne 2015
 
NoSQL, which way to go?
NoSQL, which way to go?NoSQL, which way to go?
NoSQL, which way to go?
 
Mongodb intro
Mongodb introMongodb intro
Mongodb intro
 
Dragon: A Distributed Object Storage at Yahoo! JAPAN (WebDB Forum 2017 / E...
   Dragon: A Distributed Object Storage at Yahoo! JAPAN (WebDB Forum 2017 / E...   Dragon: A Distributed Object Storage at Yahoo! JAPAN (WebDB Forum 2017 / E...
Dragon: A Distributed Object Storage at Yahoo! JAPAN (WebDB Forum 2017 / E...
 
Back to Basics Webinar 1: Introduction to NoSQL
Back to Basics Webinar 1: Introduction to NoSQLBack to Basics Webinar 1: Introduction to NoSQL
Back to Basics Webinar 1: Introduction to NoSQL
 
Back to Basics Webinar 1 - Introduction to NoSQL
Back to Basics Webinar 1 - Introduction to NoSQLBack to Basics Webinar 1 - Introduction to NoSQL
Back to Basics Webinar 1 - Introduction to NoSQL
 
The power of datomic
The power of datomicThe power of datomic
The power of datomic
 
Using Spring with NoSQL databases (SpringOne China 2012)
Using Spring with NoSQL databases (SpringOne China 2012)Using Spring with NoSQL databases (SpringOne China 2012)
Using Spring with NoSQL databases (SpringOne China 2012)
 
MongoDB: Comparing WiredTiger In-Memory Engine to Redis
MongoDB: Comparing WiredTiger In-Memory Engine to RedisMongoDB: Comparing WiredTiger In-Memory Engine to Redis
MongoDB: Comparing WiredTiger In-Memory Engine to Redis
 
This is redis - feature and usecase
This is redis - feature and usecaseThis is redis - feature and usecase
This is redis - feature and usecase
 
ElasticSearch AJUG 2013
ElasticSearch AJUG 2013ElasticSearch AJUG 2013
ElasticSearch AJUG 2013
 
2019.06.27 Intro to Ceph
2019.06.27 Intro to Ceph2019.06.27 Intro to Ceph
2019.06.27 Intro to Ceph
 
Elasticsearch - DevNexus 2015
Elasticsearch - DevNexus 2015Elasticsearch - DevNexus 2015
Elasticsearch - DevNexus 2015
 
Mongo db japan
Mongo db japanMongo db japan
Mongo db japan
 
ElasticSearch - DevNexus Atlanta - 2014
ElasticSearch - DevNexus Atlanta - 2014ElasticSearch - DevNexus Atlanta - 2014
ElasticSearch - DevNexus Atlanta - 2014
 
MongoDB FabLab León
MongoDB FabLab LeónMongoDB FabLab León
MongoDB FabLab León
 
Cloud arch patterns
Cloud arch patternsCloud arch patterns
Cloud arch patterns
 
Redis — memcached on steroids
Redis — memcached on steroidsRedis — memcached on steroids
Redis — memcached on steroids
 
Designate - Operators Deep Dive
Designate - Operators Deep DiveDesignate - Operators Deep Dive
Designate - Operators Deep Dive
 
NOSQL Overview
NOSQL OverviewNOSQL Overview
NOSQL Overview
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 

Florida Man Uses Cache as Database.pdf