Beispiel #1
0
func (r *RedisClient) IsUserOnline(u user.User) bool {
	key := genUserOnlineKey(u.GetUserInfo())
	isExits, err := r.client.Exists(key).Result()
	if err != nil {
		return false
	}
	return isExits
}
Beispiel #2
0
func (r *RedisClient) GetUserInfo(u user.User) (user.UserInfo, error) {
	var user user.UserInfo
	val, err := r.client.Get(genUserInfoKey(u.GetUserInfo())).Result()
	if err != nil {
		return user, err
	}
	err = json.Unmarshal([]byte(val), &user)
	return user, err
}
Beispiel #3
0
func (r *RedisClient) GetSize(u user.User) (int64, error) {
	key := genUserFlowKey(u.GetUserInfo())
	isExits, err := r.client.Exists(key).Result()
	if err != nil {
		return 0, err
	}
	if !isExits {
		return 0, nil
	}
	return r.client.Get(key).Int64()
}
Beispiel #4
0
// traffic
func (r *RedisClient) IncrSize(u user.User, size int) error {
	key := genUserFlowKey(u.GetUserInfo())
	incrSize := int(float32(size))
	isExits, err := r.client.Exists(key).Result()
	if err != nil {
		return err
	}
	if !isExits {
		return r.client.Set(key, incrSize, DefaultExpireTime).Err()
	}
	return r.client.IncrBy(key, int64(incrSize)).Err()
}
Beispiel #5
0
func (r *RedisClient) MarkUserOnline(u user.User) error {
	key := genUserOnlineKey(u.GetUserInfo())
	return r.client.Set(key, "1", DefaultOnlineKeyExpireTime).Err()
}
Beispiel #6
0
func (r *RedisClient) SetSize(u user.User, size int) error {
	key := genUserFlowKey(u.GetUserInfo())
	return r.client.Set(key, size, DefaultExpireTime).Err()
}
Beispiel #7
0
func (r *RedisClient) Del(u user.User) error {
	return r.client.Del(genUserInfoKey(u.GetUserInfo())).Err()
}
Beispiel #8
0
func (r *RedisClient) Exists(u user.User) (bool, error) {
	return r.client.Exists(genUserInfoKey(u.GetUserInfo())).Result()
}