Skip to content

Commit ec2ce39

Browse files
committed
wip: initial functionality
1 parent b24982b commit ec2ce39

File tree

5 files changed

+79
-0
lines changed

5 files changed

+79
-0
lines changed

cmd/mercury/main.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
// "log"
6+
// "net/http"
7+
)
8+
9+
func main() {
10+
fmt.Println("Starting Mercury Core...")
11+
}

go.mod

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module github.com/syntaxsdev/mercury
2+
3+
go 1.22.7
4+
5+
require (
6+
github.com/cespare/xxhash/v2 v2.2.0 // indirect
7+
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
8+
github.com/go-chi/chi/v5 v5.2.0 // indirect
9+
github.com/redis/go-redis/v9 v9.7.0 // indirect
10+
)

go.sum

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
2+
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
3+
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
4+
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
5+
github.com/go-chi/chi/v5 v5.2.0 h1:Aj1EtB0qR2Rdo2dG4O94RIU35w2lvQSj6BRA4+qwFL0=
6+
github.com/go-chi/chi/v5 v5.2.0/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
7+
github.com/redis/go-redis/v9 v9.7.0 h1:HhLSs+B6O021gwzl+locl0zEDnyNkxMtf/Z3NNBMa9E=
8+
github.com/redis/go-redis/v9 v9.7.0/go.mod h1:f6zhXITC7JUJIlPEiBOTXxJgPLdZcA93GewI7inzyWw=

internal/repositories/redis.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package repositories
2+
3+
import (
4+
"github.com/redis/go-redis/v9"
5+
)
6+
7+
type RedisClient struct {
8+
Client *redis.Client
9+
}
10+
11+
func NewRedisClient(addr, password string) *RedisClient {
12+
return &RedisClient{
13+
Client: redis.NewClient(&redis.Options{
14+
Addr: addr,
15+
Password: password,
16+
DB: 0,
17+
}),
18+
}
19+
}

internal/services/redis.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package services
2+
3+
import (
4+
"context"
5+
6+
"github.com/syntaxsdev/mercury/internal/repositories"
7+
)
8+
9+
type RedisService struct {
10+
Repo *repositories.RedisClient
11+
}
12+
13+
func (s *RedisService) Set(ctx context.Context, key string, value interface{}) error {
14+
return s.Repo.Client.Set(ctx, key, value, 0).Err()
15+
}
16+
17+
func (s *RedisService) Get(ctx context.Context, key string) (string, error) {
18+
return s.Repo.Client.Get(ctx, key).Result()
19+
}
20+
21+
func (s *RedisService) Add(ctx context.Context, key string, value interface{}) error {
22+
return s.Repo.Client.RPush(ctx, key, value, 0).Err()
23+
}
24+
25+
func (s *RedisService) GetList(ctx context.Context, key string) ([]string, error) {
26+
return s.Repo.Client.LRange(ctx, key, 0, -1).Result()
27+
}
28+
29+
func (s *RedisService) Pop(ctx context.Context, key string) (string, error) {
30+
return s.Repo.Client.RPop(ctx, key).Result()
31+
}

0 commit comments

Comments
 (0)