12345678910111213141516171819202122232425262728293031323334 |
- package repositories
- import (
- "context"
- "fmt"
- "github.com/redis/go-redis/v9"
- "sikey.com/websocket/models"
- )
- var _ OnlineRepository = (*onlineRepository)(nil)
- type OnlineRepository interface {
- SetOnline(ctx context.Context, o *models.Online) error
- Offline(ctx context.Context, o *models.Online) error
- }
- type onlineRepository struct {
- rdb *redis.Client
- }
- // Offline implements OnlineRepository.
- func (repo *onlineRepository) Offline(ctx context.Context, o *models.Online) error {
- return repo.rdb.Del(ctx, fmt.Sprintf("clients.%s.%s", o.ServerId, o.UserId)).Err()
- }
- // SetOnline implements OnlineRepository.
- func (repo *onlineRepository) SetOnline(ctx context.Context, o *models.Online) error {
- return repo.rdb.Set(ctx, fmt.Sprintf("clients.%s.%s", o.ServerId, o.UserId), o, 0).Err()
- }
- func NewOnlineRepository(rdb *redis.Client) OnlineRepository {
- return &onlineRepository{rdb: rdb}
- }
|