Skip to content

Commit 694c4e2

Browse files
committed
Add images for shopping cart
1 parent 99696c7 commit 694c4e2

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

docs/howtos/shoppingcart/index-shoppingcart.mdx

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import useBaseUrl from '@docusaurus/useBaseUrl';
1010
import RedisCard from '@site/src/theme/RedisCard';
1111

1212
![My Image](shoppingcart.png)
13-
## 1. Install the below software in your local system:
13+
## 1. Install the required software
1414

1515
- Express 4 backend
1616
- Node 15.5.0 (at least v12.9.0+)
@@ -145,6 +145,26 @@ $ npm run serve
145145
146146
```
147147

148+
![My Image](shoppingcart2.png)
148149

149-
150+
## How it works
151+
152+
### How the data is stored:
153+
* The products data is stored in external json file. After first request this data is saved in a JSON data type in Redis like: `JSON.SET product:{productId} . {product data in json format}`.
154+
* The cart data is stored in a hash like: `HSET cart:{cartId} product:{productId} {productQuantity}`, where cartId is random generated value and stored in user session.
155+
156+
### How the data is modified:
157+
* The product data is modified like `JSON.SET product:{productId} . {new product data in json format}`.
158+
* The cart data is modified like `HSET cart:{cartId} product:{productId} {newProductQuantity}` or `HINCRBY cart:{cartId} product:{productId} {incrementBy}`.
159+
* Product can be removed from cart like `HDEL cart:{cartId} product:{productId}`
160+
* Cart can be cleared using `HGETALL cart:{cartId}` and then `HDEL cart:{cartId} {productKey}`.
161+
* All carts can be deleted when reset data is requested like: `DEL cart:{cartId}`.
162+
163+
### How the data is accessed:
164+
* Products: `SCAN {cursor} MATCH product:*` to get all product keys and then `JSON.GET {productKey}`.
165+
* Cart: `HGETALL cart:{cartId}`to get quantity of products and `JSON.GET product:{productId}` to get products data.
166+
167+
168+
References:
150169

170+
- [Source code](https://github.com/redis-developer/basic-redis-shopping-chart-nodejs)
264 KB
Loading

0 commit comments

Comments
 (0)