示例#1
0
func saveSessionInCache(appSession string, s Session) {
	c := cache.RedisFromConfig("session")
	key := "APPSESSION-" + appSession

	//create json compatible with php session
	sc := SessionInCache{}
	sc.CustomerId = strconv.Itoa(s.CustomerId)
	sc.CustomerType = s.CustomerType
	sc.ExpiryDate = s.ExpiryDate.Format(DB_DATE_FORMAT)

	val, _ := json.Marshal(sc)
	ttl := s.ExpiryDate.Sub(time.Now())
	c.Set(key, val, ttl)
}
示例#2
0
func getSessionDetailsFromCache(appSession string) (s Session, ok bool) {
	c := cache.RedisFromConfig("session")
	key := "APPSESSION-" + appSession
	val, err := c.Get(key)
	if err == nil {
		sc := SessionInCache{}
		err := json.Unmarshal(val, &sc)
		if err == nil {
			s.CustomerId, err = strconv.Atoi(sc.CustomerId)
			s.CustomerType = sc.CustomerType
			t, err := time.Parse(DB_DATE_FORMAT, sc.ExpiryDate)
			if err == nil {
				s.ExpiryDate = t
			}
			return s, true
		}
	}
	return s, false
}