This is a Jupyter notebook that loads a Kaggle dataset into Redis in two manners: string and JSON. Comparisons of string and JSON operations are made for three scenarios.
- Loads Kaggle restaurant data
- Executes Redis operations on that data to solve various hypothetical business problems
- Redis Enterprise database with Search and JSON enabled
- Kaggle account
- Python
- Jupyter
- Clone this repo.
- Edit the .env_template file with your credentials.
- Copy or rename that file to .env
- Follow notebook steps
Given a known restaurant ID and a menu item name, find its price.
restaurant_str = client.get(f'restaurant_str:{restaurant_id}')
restaurant_json = json.loads(restaurant_str)
menu = restaurant_json['menu']
for item in menu:
if item['name'] == menu_item:
price = item['price']
breakquery = Query(f'@id:[{restaurant_id}, {restaurant_id}]')\
.return_field(f'$.menu[?(@.name=="{menu_item}")].price', as_field='price')
result = client.ft('restaurant_idx').search(query)Find the number of Papa Johns restaurants within a 100 mi radius of Madison WI
- Loop thru the Redis key space
- Deserialize each string to JSON
- Perform a string comparison on the restaurant name element, covering letter case variations
- For restaurant name string matches, perform a Haversine calculation
- Update local counter for Haversine matches
query = Query(f'@name:"Papa Johns" @coords:[{madison} 100 mi]').paging(0, 0)
count = client.ft('restaurant_idx').search(query).total Find the Top 3 menu items by count in the State of Texas
- Loop thru the Redis key space
- Deserialize each string to JSON
- Perform a string comparison on the restaurant address element
- For restaurant address string matches, initiate a inner loop on the menu elements - cover letter case + stem variations
- Maintain counters for every possible menu item. Increment applicable counter per menu element
- Sort counters, display Top 3 items
request = AggregateRequest('@address:TX')\
.group_by('@menu_item_name', reducers.count().alias('item_count'))\
.sort_by(Desc('@item_count'))\
.limit(0,3)
result = client.ft('restaurant_idx').aggregate(request)