You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/howtos/shoppingcart/index-shoppingcart.mdx
+22-2Lines changed: 22 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@ import useBaseUrl from '@docusaurus/useBaseUrl';
10
10
importRedisCardfrom'@site/src/theme/RedisCard';
11
11
12
12

13
-
## 1. Install the below software in your local system:
13
+
## 1. Install the required software
14
14
15
15
- Express 4 backend
16
16
- Node 15.5.0 (at least v12.9.0+)
@@ -145,6 +145,26 @@ $ npm run serve
145
145
146
146
```
147
147
148
+

148
149
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.
0 commit comments