Skip to content

Commit 602deaf

Browse files
authored
Merge pull request #1047 from Chris-Basson-Grundling/main
New Storage Driver: ScyllaDb
2 parents 07fab67 + af89d59 commit 602deaf

13 files changed

+803
-0
lines changed

.github/dependabot.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,9 @@ updates:
140140
- "🤖 Dependencies"
141141
schedule:
142142
interval: "daily"
143+
- package-ecosystem: "gomod"
144+
directory: "/scylladb/" # Location of package manifests
145+
labels:
146+
- "🤖 Dependencies"
147+
schedule:
148+
interval: "daily"

.github/release-drafter-scylladb.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name-template: 'ScyllaDb - v$RESOLVED_VERSION'
2+
tag-template: 'scylladb/v$RESOLVED_VERSION'
3+
tag-prefix: scylladb/v
4+
include-paths:
5+
- scylladb
6+
categories:
7+
- title: '🚀 New'
8+
labels:
9+
- '✏️ Feature'
10+
- title: '🧹 Updates'
11+
labels:
12+
- '🧹 Updates'
13+
- '🤖 Dependencies'
14+
- title: '🐛 Fixes'
15+
labels:
16+
- '☢️ Bug'
17+
- title: '📚 Documentation'
18+
labels:
19+
- '📒 Documentation'
20+
change-template: '- $TITLE (#$NUMBER)'
21+
change-title-escapes: '\<*_&' # You can add # and @ to disable mentions, and add ` to disable code blocks.
22+
version-resolver:
23+
major:
24+
labels:
25+
- 'major'
26+
minor:
27+
labels:
28+
- 'minor'
29+
- '✏️ Feature'
30+
patch:
31+
labels:
32+
- 'patch'
33+
- '📒 Documentation'
34+
- '☢️ Bug'
35+
- '🤖 Dependencies'
36+
- '🧹 Updates'
37+
default: patch
38+
template: |
39+
$CHANGES
40+
**Full Changelog**: https://github.com/$OWNER/$REPOSITORY/compare/$PREVIOUS_TAG...scylladb/v$RESOLVED_VERSION
41+
Thank you $CONTRIBUTORS for making this update possible.

.github/workflows/benchmark.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ jobs:
117117
run: |
118118
docker run -d --restart always -p 9000:9000 --name storage-minio -e MINIO_ROOT_USER='minio-user' -e MINIO_ROOT_PASSWORD='minio-password' minio/minio server /data
119119
120+
- name: Install ScyllaDb
121+
run: |
122+
docker run --name scylladb -p 9042:9042 -p 19042:19042 -p 9160:9160 -p 7000:7000 -p 7001:7001 -p 7199:7199 -p 9180:9180 -d scylladb/scylla:latest --broadcast-address 127.0.0.1 --listen-address 0.0.0.0 --broadcast-rpc-address 127.0.0.1
123+
sleep 15 # Wait for ScyllaDb to initialize
124+
120125
- name: Setup Redis
121126
uses: shogo82148/actions-setup-redis@v1
122127
with:

.github/workflows/gosec.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,7 @@ jobs:
124124
working-directory: ./rueidis
125125
run: gosec ./...
126126
# -----
127+
- name: Run Gosec (scylladb)
128+
working-directory: ./scylladb
129+
run: gosec ./...
130+
# -----
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Release Drafter ScyllaDb
2+
on:
3+
push:
4+
# branches to consider in the event; optional, defaults to all
5+
branches:
6+
- master
7+
- main
8+
paths:
9+
- 'scylladb/**'
10+
jobs:
11+
draft_release_scylladb:
12+
runs-on: ubuntu-latest
13+
timeout-minutes: 30
14+
steps:
15+
- uses: release-drafter/release-drafter@v5
16+
with:
17+
config-name: release-drafter-scylladb.yml
18+
env:
19+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/test-scylladb.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
on:
2+
push:
3+
branches:
4+
- master
5+
- main
6+
paths:
7+
- 'scylladb/**'
8+
pull_request:
9+
paths:
10+
- 'scylladb/**'
11+
12+
name: "Tests ScyllaDb"
13+
14+
jobs:
15+
Tests:
16+
runs-on: ubuntu-latest
17+
18+
strategy:
19+
matrix:
20+
go-version:
21+
- 1.20.x
22+
- 1.21.x
23+
24+
steps:
25+
- name: Fetch Repository
26+
uses: actions/checkout@v3
27+
28+
- name: Run ScyllaDb
29+
run: |
30+
docker run --name scylladb -p 9042:9042 -p 19042:19042 -p 9160:9160 -p 10000:10000 -p 7000:7000 -p 7001:7001 -p 7199:7199 -p 9180:9180 -d scylladb/scylla:latest --broadcast-address 127.0.0.1 --listen-address 0.0.0.0 --broadcast-rpc-address 127.0.0.1
31+
sleep 30 # Wait for ScyllaDb to initialize
32+
33+
- name: Install Go
34+
uses: actions/setup-go@v4
35+
with:
36+
go-version: '${{ matrix.go-version }}'
37+
38+
- name: Run Test
39+
run: cd ./scylladb && go test ./... -v -race

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,6 @@ type Storage interface {
6969
- [Redis](./redis/README.md) <a href="https://github.com/gofiber/storage/actions?query=workflow%3A%22Tests+Redis%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-redis.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a>
7070
- [Rueidis](./rueidis/README.md) <a href="https://github.com/gofiber/storage/actions?query=workflow%3A%22Tests+rueidis%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-rueidis.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a>
7171
- [S3](./s3/README.md) <a href="https://github.com/gofiber/storage/actions?query=workflow%3A%22Tests+S3%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-s3.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a>
72+
- [ScyllaDB](./scylladb/README.md) <a href="https://github.com/gofiber/storage/actions?query=workflow%3A%22Tests+scylladb%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-scylladb.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a>
7273
- [SQLite3](./sqlite3/README.md) <a href="https://github.com/gofiber/storage/actions?query=workflow%3A%22Tests+Sqlite3%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-sqlite3.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a>
7374

scylladb/README.md

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
---
2+
id: scylladb
3+
title: ScyllaDb
4+
---
5+
6+
![Release](https://img.shields.io/github/v/tag/gofiber/storage?filter=scylladb*)
7+
[![Discord](https://img.shields.io/discord/704680098577514527?style=flat&label=%F0%9F%92%AC%20discord&color=00ACD7)](https://gofiber.io/discord)
8+
![Test](https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-scylladb.yml?label=Tests)
9+
![Security](https://img.shields.io/github/actions/workflow/status/gofiber/storage/gosec.yml?label=Security)
10+
![Linter](https://img.shields.io/github/actions/workflow/status/gofiber/storage/linter.yml?label=Linter)
11+
12+
# ScyllaDb
13+
14+
A ScyllaDb storage engine for [Fiber](github.com/gofiber/fiber) using [gocql](github.com/scylladb/gocql).
15+
16+
### Table of Contents
17+
- [Signatures](#signatures)
18+
- [Installation](#installation)
19+
- [Examples](#examples)
20+
- [Config](#config)
21+
- [Default Config](#default-config)
22+
23+
### Signatures
24+
```go
25+
func New(config ...Config) Storage
26+
func (s *Storage) Get(key string) ([]byte, error)
27+
func (s *Storage) Set(key string, value []byte, expire time.Duration) error
28+
func (s *Storage) Delete(key string) error
29+
func (s *Storage) Reset() error
30+
func (s *Storage) Close() error
31+
func (s *Storage) Conn() *gocql.Session
32+
```
33+
34+
### Installation
35+
ScyllaDb is tested on the 2 last [Go versions](https://golang.org/dl/) with support for modules. So make sure to initialize one first if you didn't do that yet:
36+
```bash
37+
go mod init github.com/<user>/<repo>
38+
```
39+
And then install the scylladb implementation:
40+
```bash
41+
go get github.com/gofiber/storage/scylladb
42+
```
43+
44+
### Examples
45+
Import the storage package.
46+
```go
47+
import "github.com/gofiber/storage/scylladb"
48+
```
49+
50+
You can use the following possibilities to create a storage:
51+
```go
52+
// Initialize default config
53+
store := scylladb.New()
54+
55+
// Initialize custom config
56+
store := scylladb.New(scylladb.Config{
57+
Keyspace: "fiber",
58+
Hosts: []string{"127.0.0.1"},
59+
Port: 9042,
60+
Table: "fiber_storage",
61+
Consistency: "ONE",
62+
Reset: false,
63+
})
64+
65+
// Initialize with support for TLS (SslOptions configures TLS use)
66+
//
67+
// InsecureSkipVerify and EnableHostVerification interact as follows:
68+
//
69+
// |Config.InsecureSkipVerify | EnableHostVerification | Result |
70+
// |--------------------------|------------------------|--------------------|
71+
// |Config is nil | false | do not verify host |
72+
// |Config is nil | true | verify host |
73+
// |false | false | verify host |
74+
// |true | false | do not verify host |
75+
// |false | true | verify host |
76+
// |true | true | verify host |
77+
store := New(
78+
Config{
79+
Keyspace: "fiber",
80+
Hosts: []string{"127.0.0.1"},
81+
Port: 9042,
82+
Table: "fiber_storage",
83+
Consistency: "ONE",
84+
SslOpts: &gocql.SslOptions{
85+
Config: &tls.Config{
86+
InsecureSkipVerify: false, // Set this too false to enable certificate verification
87+
},
88+
CertPath: "/path/to/client_cert.pem", // Path to the client certificate
89+
KeyPath: "/path/to/client_key.pem", // Path to the client certificate's private key
90+
CaPath: "/path/to/ca_cert.pem", // Path to the CA certificate
91+
EnableHostVerification: true, // Enable hostname verification
92+
},
93+
Reset: false,
94+
},
95+
)
96+
97+
// Initialize custom config using scylladb connection
98+
cluster, _ := gocql.NewCluster("127.0.0.1")
99+
cluster.Keyspace = "fiber"
100+
cluster.Port = 9042
101+
102+
session, _ := cluster.CreateSession()
103+
store := scylladb.New(scylladb.Config{
104+
Session: session,
105+
Keyspace: "fiber",
106+
Table: "fiber_storage",
107+
Reset: false,
108+
})
109+
```
110+
111+
### Config
112+
```go
113+
type Config struct {
114+
// Session is provided by the user to use an existing ScyllaDb session
115+
// Session Will override Keyspace and all other authentication values if used
116+
//
117+
// Optional. Default is nil
118+
Session *gocql.Session
119+
120+
// Keyspace name
121+
//
122+
// Optional. Default is "fiber"
123+
Keyspace string
124+
125+
// Hosts are an array of network addresses for establishing initial connections
126+
// You have the flexibility to specify one or multiple addresses as needed
127+
//
128+
// Optional. Default is "127.0.0.1"
129+
Hosts []string
130+
131+
// Port where the ScyllaDb cluster is listening on
132+
//
133+
// Optional. Default is 9042
134+
Port int
135+
136+
// Username for ScyllaDb cluster
137+
//
138+
// Optional. Default is ""
139+
Username string
140+
141+
// Password for ScyllaDb cluster
142+
//
143+
// Optional. Default is ""
144+
Password string
145+
146+
// Table name
147+
//
148+
// Optional. Default is "fiber_storage"
149+
Table string
150+
151+
// Level of the consistency
152+
//
153+
// Optional. Default is "LOCAL_ONE"
154+
Consistency string
155+
156+
// SslOpts configures TLS use.
157+
//
158+
// Optional. Default is nil
159+
SslOpts *gocql.SslOptions
160+
161+
// Reset clears any existing keys in existing Table
162+
//
163+
// Optional. Default is false
164+
Reset bool
165+
}
166+
```
167+
168+
### Default Config
169+
```go
170+
// ConfigDefault is the default config
171+
var ConfigDefault = Config{
172+
Session: nil,
173+
Keyspace: "fiber",
174+
Hosts: []string{"127.0.0.1"},
175+
Username: "",
176+
Password: "",
177+
Port: 9042,
178+
Table: "fiber_storage",
179+
Consistency: "LOCAL_ONE",
180+
SslOpts: nil,
181+
Reset: false,
182+
}
183+
```

0 commit comments

Comments
 (0)