Redis application of e-commerce system system notes

1. Product details page

A large amount of information on the product details page is read for the first time and placed in the cache, and then read from the cache first. However, the product information is set with a timeout, because for some unpopular products, it is not read often, which can save redis space

If the data is put into redis and modified, the timeout period will be extended. If it has not been modified, the data will be deleted by redis.

Redis expiration mechanism
In Redis, you can use the EXPIRE command to set the survival time of a key (ttl: time to live). After this time, the key will be automatically deleted. The usage of the EXPIRE command is as follows:
EXPIRE key ttl (unit seconds)
command returns 1 to indicate that the setting of ttl is successful, and returns to 0 to indicate that the key does not exist or the setting fails.

For example:
127.0.0.1:6379> set session 100
OK
127.0.0.1:6379> EXPIRE session 5
(integer) 1
127.0.0.1:6379> get session
"100"
127.0.0.1:6379> get session
"100"
127.0 .0.1:6379> get session
(nil)
127.0.0.1:6379>
The above example can be seen, first set the session value to 100, then set his ttl to 5s, then use the get command several times to obtain the session, after 5s, the session will be obtained If the session is not available, because the ttl time has expired, the session is deleted.

If you want to know how long a key has been deleted, you can use the TTL command to check, the usage is as follows:

TTL key

2. Shopping cart implementation

After adding products and saving them to the database, use redis to share the reading and reading pressure.



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325402258&siteId=291194637