-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Your Name
committed
Nov 23, 2023
1 parent
6a23303
commit be99290
Showing
4 changed files
with
60 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package token | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/gomodule/redigo/redis" | ||
"github.com/yzimhao/trading_engine/utils" | ||
"github.com/yzimhao/trading_engine/utils/app" | ||
) | ||
|
||
func Set(token string, user_id string, ttl int) { | ||
rdc := app.RedisPool().Get() | ||
defer rdc.Close() | ||
|
||
topic := tokenRedisTopic(token) | ||
rdc.Do("set", topic, user_id) | ||
rdc.Do("expire", topic, ttl) | ||
} | ||
|
||
func Get(original_token string) string { | ||
rdc := app.RedisPool().Get() | ||
defer rdc.Close() | ||
|
||
topic := tokenRedisTopic(original_token) | ||
user_id, err := redis.String(rdc.Do("get", topic)) | ||
if err != nil { | ||
app.Logger.Errorf("从redis获取token信息出错 %s", err.Error()) | ||
} | ||
return user_id | ||
} | ||
|
||
func tokenRedisTopic(token string) string { | ||
return fmt.Sprintf("user.token.%s", utils.Hash256(token)) | ||
} |