Skip to content

assignment 2, learning about redis#21

Open
baotyphu wants to merge 1 commit intoEngineerProOrg:scott/sample-gormfrom
baotyphu:scott/sample-gorm
Open

assignment 2, learning about redis#21
baotyphu wants to merge 1 commit intoEngineerProOrg:scott/sample-gormfrom
baotyphu:scott/sample-gorm

Conversation

@baotyphu
Copy link

@baotyphu baotyphu commented Jun 3, 2023

No description provided.

@baotyphu baotyphu force-pushed the scott/sample-gorm branch from eddc942 to 4945752 Compare June 3, 2023 23:51

func tryLockRedisForKey(key string, value string, expireTime time.Duration) {
for {
result := redisClient.SetNX(redisClient.Context(), key, value, expireTime)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should sleep for a while after a loop , if not then redis will send a lot of request when trying

sleep(sleepTime)
// doSomething

if strings.Compare(redisClient.Get(c, key).Val(), newUUID) == 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one should be called in a defer after line 71, to make sure it will be called

func rateLimiterHandler(c *gin.Context) {
username := c.Params.ByName("username")
redisClient.Incr(redisClient.Context(), username)
requestNumberOfUser, _ := redisClient.Get(redisClient.Context(), username).Int64()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the number should be from incr command instead, because if we call like this, the number can be wrong

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants