Skip to content

Instantly share code, notes, and snippets.

@wilmoore
Last active November 28, 2024 06:58
Show Gist options
  • Save wilmoore/98f88b6bb1de2f200574bcd149ab802f to your computer and use it in GitHub Desktop.
Save wilmoore/98f88b6bb1de2f200574bcd149ab802f to your computer and use it in GitHub Desktop.
Software Engineering :: Database :: Redis :: Example :: Gist Auto-Complete Description

Software Engineering :: Database :: Redis :: Example :: Gist Auto-Complete Description

⪼ Made with 💜 by Polyglot.

ChatGPT
content
related
reference
research

Task List

  • Get a count of all gists (make that another social media post)
  • How many pages
  • Create a list of manual API calls to get each page of gists
  • Index those
  • Automate this process

Dynamically Build Equivalent of .html_url

"gist:wilmoore:7f6bf8ec3803420b5366f9be15f1c631".split(':').filter((_, idx) => idx > 0).reverse().concat('https://gist.github.com').reverse().join('/')

Connect to the Redis instance

podman machine start
podman stop redis-stack-server
podman rm redis-stack-server
podman run --name redis-stack-server -d redis-stack-server
podman start redis-stack-server
podman exec -it redis-stack-server redis-cli

Create a single index named "gists" for all users with fields for Gist ID, GitHub username, and description

FT.CREATE gist ON HASH PREFIX 1 "gist:" SCHEMA gist_id TEXT username TAG description TEXT
per user
FT.CREATE wilmoore ON HASH PREFIX 1 "wilmoore:" SCHEMA gist_id TEXT username TAG description TEXT

Add Documents with Distinct Prefixes

Add a document for "wilmoore"

HSET gist:wilmoore:e74fba0ee31ea5709f0894921640a834 gist_id "e74fba0ee31ea5709f0894921640a834" username "wilmoore" description "Travel :: Hot Springs :: USA"

HSET gist:wilmoore:c7b6eaa7c970ae7b49853ffb90eb6296 gist_id "c7b6eaa7c970ae7b49853ffb90eb6296" username "wilmoore" description "Travel :: Hot Springs :: USA :: Colorado"

HSET gist:wilmoore:7f6bf8ec3803420b5366f9be15f1c631 gist_id "7f6bf8ec3803420b5366f9be15f1c631" username "wilmoore" description "Travel :: Hot Springs :: USA :: Colorado :: Glenwood Springs"

HSET gist:wilmoore:44790399bdeb47f8384d35d785a671da gist_id "44790399bdeb47f8384d35d785a671da" username "wilmoore" description "Travel :: Hot Springs :: USA :: Colorado :: Desert Reef Hot Springs"

Search for USA (gist_id, username, description)

127.0.0.1:6379> FT.SEARCH gists "(@username: wilmoore) USA" RETURN 3 gist_id username description
1) (integer) 4
2) "gist:wilmoore:e74fba0ee31ea5709f0894921640a834"
3) 1) "gist_id"
   2) "e74fba0ee31ea5709f0894921640a834"
   3) "username"
   4) "wilmoore"
   5) "description"
   6) "Travel :: Hot Springs :: USA"
4) "gist:wilmoore:c7b6eaa7c970ae7b49853ffb90eb6296"
5) 1) "gist_id"
   2) "c7b6eaa7c970ae7b49853ffb90eb6296"
   3) "username"
   4) "wilmoore"
   5) "description"
   6) "Travel :: Hot Springs :: USA :: Colorado"
6) "gist:wilmoore:7f6bf8ec3803420b5366f9be15f1c631"
7) 1) "gist_id"
   2) "7f6bf8ec3803420b5366f9be15f1c631"
   3) "username"
   4) "wilmoore"
   5) "description"
   6) "Travel :: Hot Springs :: USA :: Colorado :: Glenwood Springs"
8) "gist:wilmoore:44790399bdeb47f8384d35d785a671da"
9) 1) "gist_id"
   2) "44790399bdeb47f8384d35d785a671da"
   3) "username"
   4) "wilmoore"
   5) "description"
   6) "Travel :: Hot Springs :: USA :: Colorado :: Desert Reef Hot Springs"

Search for "colorado" (gist_id, description)

127.0.0.1:6379> FT.SEARCH gists "(@username: wilmoore) colorado" RETURN 2 gist_id description
1) (integer) 3
2) "gist:wilmoore:c7b6eaa7c970ae7b49853ffb90eb6296"
3) 1) "gist_id"
   2) "c7b6eaa7c970ae7b49853ffb90eb6296"
   3) "description"
   4) "Travel :: Hot Springs :: USA :: Colorado"
4) "gist:wilmoore:7f6bf8ec3803420b5366f9be15f1c631"
5) 1) "gist_id"
   2) "7f6bf8ec3803420b5366f9be15f1c631"
   3) "description"
   4) "Travel :: Hot Springs :: USA :: Colorado :: Glenwood Springs"
6) "gist:wilmoore:44790399bdeb47f8384d35d785a671da"
7) 1) "gist_id"
   2) "44790399bdeb47f8384d35d785a671da"
   3) "description"
   4) "Travel :: Hot Springs :: USA :: Colorado :: Desert Reef Hot Springs"

FT.SEARCH gists '(@username: wilmoore) (@description:USA Colorado*)' RETURN 2 gist_id description
1) (integer) 3
2) "gist:wilmoore:c7b6eaa7c970ae7b49853ffb90eb6296"
3) 1) "gist_id"
   2) "c7b6eaa7c970ae7b49853ffb90eb6296"
   3) "description"
   4) "Travel :: Hot Springs :: USA :: Colorado"
4) "gist:wilmoore:7f6bf8ec3803420b5366f9be15f1c631"
5) 1) "gist_id"
   2) "7f6bf8ec3803420b5366f9be15f1c631"
   3) "description"
   4) "Travel :: Hot Springs :: USA :: Colorado :: Glenwood Springs"
6) "gist:wilmoore:44790399bdeb47f8384d35d785a671da"
7) 1) "gist_id"
   2) "44790399bdeb47f8384d35d785a671da"
   3) "description"
   4) "Travel :: Hot Springs :: USA :: Colorado :: Desert Reef Hot Springs"

Search for '@username:{wilmoore} @description:Travel Portal'

127.0.0.1:6379> FT.SEARCH gist '@username:{wilmoore} @description:Travel Portal'
 1) (integer) 7
 2) "gist:wilmoore:6668609c28a424a3f3be5ae9d87db72f"
 3) 1) "description"
    2) "Travel :: Portal :: Capital One :: About :: 2024 Chase vs Capital One TRAVEL PORTALS: hotel booking REVIEW"
    3) "username"
    4) "wilmoore"
    5) "gist_id"
    6) "6668609c28a424a3f3be5ae9d87db72f"
 4) "gist:wilmoore:6b19c9131a059b0a13d90bd30a9dc7cc"
 5) 1) "description"
    2) "Travel :: Portal :: Capital One :: About"
    3) "username"
    4) "wilmoore"
    5) "gist_id"
    6) "6b19c9131a059b0a13d90bd30a9dc7cc"
 6) "gist:wilmoore:d90e3e532a0ad236c29267e6c0828efa"
 7) 1) "description"
    2) "Travel :: Portal :: Capital One :: Training"
    3) "username"
    4) "wilmoore"
    5) "gist_id"
    6) "d90e3e532a0ad236c29267e6c0828efa"
 8) "gist:wilmoore:50e0754d059b9b0775d1cb4133866e5d"
 9) 1) "description"
    2) "Travel :: Portal :: Chase"
    3) "username"
    4) "wilmoore"
    5) "gist_id"
    6) "50e0754d059b9b0775d1cb4133866e5d"
10) "gist:wilmoore:fee95918e74d4f595348517656ba35fd"
11) 1) "description"
    2) "Travel :: Portal :: Capital One"
    3) "username"
    4) "wilmoore"
    5) "gist_id"
    6) "fee95918e74d4f595348517656ba35fd"
12) "gist:wilmoore:d865d6074b6ca130367a56e977578e50"
13) 1) "description"
    2) "Travel :: Portal"
    3) "username"
    4) "wilmoore"
    5) "gist_id"
    6) "d865d6074b6ca130367a56e977578e50"
14) "gist:wilmoore:6d242a188f2fe43e08a231e039ae696b"
15) 1) "description"
    2) "Travel :: Portal :: Capital One :: Training :: Capital One Travel Portal Tutorial + Miles Redemption Options!"
    3) "username"
    4) "wilmoore"
    5) "gist_id"
    6) "6d242a188f2fe43e08a231e039ae696b"

OAuth Authentication

We need an authentication token from the OAuth flow in order to retrive the user's Gists. We don't have to do this until we've figured out the entire process though and run through it with all of my gists.

  1. Users will login with their GitHub account; UI will be a single large toggle switch in the middle of the page. The toggle is either on or off. When the user toggles on indexing, they'll be invoking the oauth flow in a popup.
  2. If we get a token back, then, we'll allow the toggle to toggle to the on position. (make a figma mockup)
  3. show the scopes we are using
  4. show the progress of the index (total gists)
  5. Price (service): $3/mo
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment