-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
11 changed files
with
172 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
SERVER_PORT= | ||
SERVER_HOST= | ||
SERVER_UPDATES_INTERVAL= | ||
SERVER_UPDATES_INTERVAL= | ||
SERVER_LOG_LEVEL= | ||
REDIS_PORT= | ||
REDIS_HOST= | ||
REDIS_PASSWORD= |
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
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 @@ | ||
package controller |
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
File renamed without changes.
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,30 @@ | ||
package redis | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/google/uuid" | ||
"github.com/redis/go-redis/v9" | ||
) | ||
|
||
type CreateRoomSessionRepo struct { | ||
rc *redis.Client | ||
expireTime time.Duration | ||
} | ||
|
||
const ( | ||
createRoomSessionPrefix = "create-room-session" | ||
) | ||
|
||
func NewCreateRoomSessionRepo(rc *redis.Client, expireTime time.Duration) *CreateRoomSessionRepo { | ||
return &CreateRoomSessionRepo{ | ||
rc: rc, | ||
expireTime: expireTime, | ||
} | ||
} | ||
|
||
func (r CreateRoomSessionRepo) Set(ctx context.Context, value string) (string, error) { | ||
key := uuid.NewString() | ||
return key, r.rc.Set(ctx, createRoomSessionPrefix+key, value, r.expireTime).Err() | ||
} |
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,28 @@ | ||
package redisclient | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/redis/go-redis/v9" | ||
) | ||
|
||
type Config struct { | ||
Host string | ||
Port int | ||
Password string | ||
} | ||
|
||
func NewRedisClient(cfg *Config) (*redis.Client, error) { | ||
r := redis.NewClient(&redis.Options{ | ||
Addr: fmt.Sprintf("%s:%d", cfg.Host, cfg.Port), | ||
Password: cfg.Password, | ||
}) | ||
|
||
if err := r.Set(context.Background(), "key", "value", time.Second).Err(); err != nil { | ||
return nil, err | ||
} | ||
|
||
return r, nil | ||
} |