Tokey.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package Account
  2. //
  3. //import (
  4. // "ColdP_server/conf"
  5. // "fmt"
  6. // "github.com/astaxie/beego/cache"
  7. // _ "github.com/astaxie/beego/cache/redis"
  8. // uuid "github.com/satori/go.uuid"
  9. // "time"
  10. //)
  11. //
  12. //var redisCache_Tokey cache.Cache
  13. //
  14. //func init() {
  15. // //注册模型
  16. // //orm.RegisterModel(new(Tokey))
  17. //
  18. // config := fmt.Sprintf(`{"key":"%s","conn":"%s","dbNum":"%s","password":"%s"}`,
  19. // "redis_Cold_User_Tokey", conf.Redis_address, conf.Redis_dbNum, conf.Redis_password)
  20. // fmt.Println(config)
  21. // var err error
  22. // redisCache_Tokey, err = cache.NewCache("redis", config)
  23. // if err != nil || redisCache_Tokey == nil {
  24. // errMsg := "failed to init redis"
  25. // fmt.Println(errMsg, err)
  26. // }
  27. //}
  28. //
  29. //// ---------------- Redis -------------------
  30. //// Redis_Set(m.T_sn,m) // Redis 更新缓存
  31. //func Add_Tokey_Set(Uuid, Pid string) string {
  32. // var Tokey string
  33. // for true {
  34. // Tokey = uuid.NewV4().String()
  35. // if !redisCache_Tokey.IsExist(Tokey) {
  36. // break
  37. // }
  38. // fmt.Print("申请 TOKEY 重复!重新生成。", Tokey)
  39. // }
  40. // userLoginInfo := fmt.Sprintf("%s|%s", Uuid, Pid)
  41. // redisCache_Tokey.Put(Tokey, userLoginInfo, 2*time.Hour)
  42. //
  43. // return Tokey
  44. //}
  45. //
  46. //// if r,is :=Redis_Get(T_sn);is{
  47. //// return r,nil
  48. //// }
  49. //func Redis_Tokey_Get(Tokey string) (string, bool) {
  50. // if len(Tokey) < 10 {
  51. // return "", false
  52. // }
  53. // if redisCache_Tokey.IsExist(Tokey) {
  54. // //println("找到key:",key)
  55. // v := redisCache_Tokey.Get(Tokey)
  56. // value := string(v.([]byte)) //这里的转换很重要,Get返回的是interface
  57. //
  58. // redisCache_Tokey.Put(Tokey, value, 2*time.Hour) // 重新计次
  59. // return value, true
  60. // }
  61. // //println("没有 找到key:",key)
  62. // return "", false
  63. //}