Skip to content
Merged
Show file tree
Hide file tree
Changes from 49 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
e5059da
arangodb: add support for context management
efectn Feb 9, 2025
58bbe46
clickhouse: add support for context management
efectn Feb 9, 2025
9d7368c
dynamodb: add support for context management
efectn Feb 9, 2025
a01135d
etcd: add support for context management
efectn Feb 9, 2025
134e774
minio: add support for context management
efectn Feb 9, 2025
c1e526d
mongodb: add support for context management
efectn Feb 9, 2025
17ab512
mssql: add support for context management
efectn Feb 9, 2025
3242f93
mysql: add support for context management
efectn Feb 9, 2025
a422c89
nats: add support for context management
efectn Feb 10, 2025
a5ea1ad
postgres: add support for context management
efectn Feb 10, 2025
245dce0
redis: add support for context management
efectn Feb 10, 2025
d6fb931
rueidis: add support for context management
efectn Feb 10, 2025
486941c
s3: add support for context management
efectn Feb 10, 2025
ce31f76
scylladb: add support for context management
efectn Feb 10, 2025
75f5216
sqlite3: add support for context management
efectn Feb 10, 2025
1b443d0
valkey: add support for context management
efectn Feb 11, 2025
2192ac6
azureblob: add support for context management
efectn Feb 11, 2025
f03ca4e
cloudflarekv: add support for context management
efectn Feb 11, 2025
634695c
cloudflarekv: make context functional for test_module
efectn Feb 11, 2025
58388d3
couchbase: add support for context management
efectn Mar 4, 2025
d7bbc22
chore: use testcontainers properly in nats
mdelapenya Mar 28, 2025
f3bdd25
chore: use testcontainers properly in dynamodb
mdelapenya Mar 28, 2025
d1893c2
chore: use testcontainers properly in mysql
mdelapenya Mar 28, 2025
371611b
chore: use testcontainers properly in postgres
mdelapenya Mar 28, 2025
53b2205
chore: use testcontainers properly in mongodb
mdelapenya Mar 28, 2025
0a9e0ef
neo4j: add support for context management
efectn Apr 22, 2025
8dcdba4
coherence: add support for context management
efectn Apr 22, 2025
ba32290
fix tests
efectn Apr 22, 2025
0f13ff4
Merge branch 'main' into add-withcontext
mdelapenya May 23, 2025
74b3bd3
chore(minio): defer closing the store in test
mdelapenya May 23, 2025
85ffd9d
Merge branch 'main' into add-withcontext
efectn Jun 25, 2025
75b43b2
add context support to more storages
efectn Jun 25, 2025
2841c64
add context support to more storages
efectn Jun 25, 2025
d95247b
update go version matrix for some storage workflows
efectn Jun 25, 2025
cf36990
update tests
efectn Jun 25, 2025
5b0ff18
fix tests
efectn Jun 25, 2025
6411177
Add WithContext methods to storage.go
efectn Jun 25, 2025
46bf456
Update mockstorage module dependencies
ReneWerner87 Jul 2, 2025
73af914
Merge branch 'add-withcontext' into codex/2025-07-02-11-22-48
ReneWerner87 Jul 2, 2025
085b336
Merge pull request #1809 from gofiber/codex/2025-07-02-11-22-48
ReneWerner87 Jul 2, 2025
c32a7ae
fix mssql benchmarks
efectn Jul 3, 2025
b6563da
Merge branch 'add-withcontext' of https://github.com/gofiber/storage …
efectn Jul 3, 2025
92bf276
update docs
efectn Jul 3, 2025
8139126
add dummy ctx to leveldb
efectn Jul 3, 2025
b65f330
Merge branch 'main' into add-withcontext
efectn Jul 4, 2025
4c92ab4
update nodejs version from 18 to 20
ReneWerner87 Jul 4, 2025
0feb2ba
apply some ai reviews
efectn Jul 4, 2025
1389ad7
Merge branch 'add-withcontext' of https://github.com/gofiber/storage …
efectn Jul 4, 2025
896938e
update release policy
efectn Jul 6, 2025
0c8e92a
Update README.md
ReneWerner87 Jul 7, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
node-version: '20'

- name: Install Cloudflare Worker
if: ${{ matrix.package == 'cloudflarekv' }}
Expand All @@ -83,6 +83,23 @@ jobs:
--env ETCD_ADVERTISE_CLIENT_URLS=http://etcd-server:2379 \
bitnami/etcd:latest

- name: Install MSSQL
if: ${{ matrix.package == 'mssql' }}
run: |
docker run -d --name mssql-server \
--publish 1433:1433 \
--env ACCEPT_EULA=Y \
--env SA_PASSWORD=MsSql!1234 \
--env MSSQL_DB=master \
--env MSSQL_USER=sa \
--env MSSQL_PASSWORD=MsSql!1234 \
--health-cmd "/opt/mssql-tools/bin/sqlcmd -U sa -P MsSql!1234 -Q 'select 1' -b -o /dev/null" \
--health-interval 1s \
--health-timeout 30s \
--health-start-period 10s \
--health-retries 20 \
mcmoe/mssqldocker:latest

- name: Run Benchmarks
working-directory: ${{ matrix.package }}
run: |
Expand Down Expand Up @@ -134,4 +151,4 @@ jobs:
auto-push: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' }}
save-data-file: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' }}


2 changes: 1 addition & 1 deletion .github/workflows/sync-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Setup Node.js environment
uses: actions/setup-node@v4
with:
node-version: '18'
node-version: '20'

- name: Install JQ
run: sudo apt-get install jq
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/test-badger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ jobs:
strategy:
matrix:
go-version:
- 1.19.x
- 1.20.x
- 1.21.x
- 1.23.x
- 1.24.x
runs-on: ubuntu-latest
steps:
- name: Fetch Repository
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/test-bbolt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ jobs:
strategy:
matrix:
go-version:
- 1.19.x
- 1.20.x
- 1.21.x
- 1.23.x
- 1.24.x
steps:
- name: Fetch Repository
uses: actions/checkout@v4
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test-cloudflarekv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ jobs:
strategy:
matrix:
go-version:
- 1.21.x
- 1.22.x
- 1.23.x
- 1.24.x
steps:
- name: Checkout Repository
uses: actions/checkout@v4
Expand All @@ -31,7 +31,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
node-version: '20'

- name: Start Wrangler Dev
run: |
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/test-etcd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ jobs:
strategy:
matrix:
go-version:
- 1.19.x
- 1.20.x
- 1.21.x
- 1.23.x
- 1.24.x
steps:
- name: Fetch Repository
uses: actions/checkout@v4
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/test-memory.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ jobs:
strategy:
matrix:
go-version:
- 1.19.x
- 1.20.x
- 1.21.x
- 1.23.x
- 1.24.x
runs-on: ubuntu-latest
steps:
- name: Fetch Repository
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test-mockstorage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ jobs:
strategy:
matrix:
go-version:
- 1.21.x
- 1.22.x
- 1.23.x
- 1.24.x
runs-on: ubuntu-latest
steps:
- name: Fetch Repository
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/test-mssql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ jobs:
strategy:
matrix:
go-version:
- 1.19.x
- 1.20.x
- 1.21.x
- 1.23.x
- 1.24.x
steps:
- name: Fetch Repository
uses: actions/checkout@v4
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test-neo4j.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
matrix:
go-version:
- 1.23.x
- 1.24.x
steps:
- name: Fetch Repository
uses: actions/checkout@v4
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/test-pebble.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ jobs:
strategy:
matrix:
go-version:
- 1.19.x
- 1.20.x
- 1.21.x
- 1.23.x
- 1.24.x
runs-on: ubuntu-latest
steps:
- name: Fetch Repository
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/test-ristretto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ jobs:
strategy:
matrix:
go-version:
- 1.19.x
- 1.20.x
- 1.21.x
- 1.23.x
- 1.24.x
steps:
- name: Fetch Repository
uses: actions/checkout@v4
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/test-sqlite3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ jobs:
strategy:
matrix:
go-version:
- 1.19.x
- 1.20.x
- 1.21.x
- 1.23.x
- 1.24.x
runs-on: ubuntu-latest
steps:
- name: Fetch Repository
Expand Down
22 changes: 0 additions & 22 deletions MIGRATE.md

This file was deleted.

18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,30 +22,48 @@ sidebar_position: 1

Premade storage drivers that implement the [`Storage`](https://github.com/gofiber/storage/blob/main/storage.go) interface, designed to be used with various [Fiber middlewares](https://github.com/gofiber/fiber/tree/master/middleware).

**Note:** All storages are tested with the latest two [Go version](https://go.dev/doc/devel/release#policy). Older Go versions may also work, but are not guaranteed to be supported.

```go
// Storage interface for communicating with different database/key-value
// providers. Visit https://github.com/gofiber/storage for more info.
type Storage interface {
// GetWithContext gets the value for the given key with a context.
// `nil, nil` is returned when the key does not exist
GetWithContext(ctx context.Context, key string) ([]byte, error)

// Get gets the value for the given key.
// `nil, nil` is returned when the key does not exist
Get(key string) ([]byte, error)

// SetWithContext stores the given value for the given key
// with an expiration value, 0 means no expiration.
SetWithContext(ctx context.Context, key string, val []byte, exp time.Duration) error

// Set stores the given value for the given key along
// with an expiration value, 0 means no expiration.
// Empty key or value will be ignored without an error.
Set(key string, val []byte, exp time.Duration) error

// DeleteWithContext deletes the value for the given key with a context.
// It returns no error if the storage does not contain the key,
DeleteWithContext(ctx context.Context, key string) error

// Delete deletes the value for the given key.
// It returns no error if the storage does not contain the key,
Delete(key string) error

// ResetWithContext resets the storage and deletes all keys with a context.
ResetWithContext(ctx context.Context) error

// Reset resets the storage and delete all keys.
Reset() error

// Close closes the storage and will stop any running garbage
// collectors and open connections.
Close() error
}

```

## 📑 Storage Implementations
Expand Down
8 changes: 6 additions & 2 deletions aerospike/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ title: Aerospike

An Aerospike client driver using `aerospike/aerospike-client-go` and [aerospike/aerospike-client-go](https://github.com/aerospike/aerospike-client-go).

**Note: Requires Go 1.23 and above**

### Table of Contents

- [Signatures](#signatures)
Expand All @@ -24,14 +22,20 @@ An Aerospike client driver using `aerospike/aerospike-client-go` and [aerospike/
```go
func New(config ...Config) Storage
func (s *Storage) Get(key string) ([]byte, error)
func (s *Storage) GetWithContext(ctx context.Context, key string) ([]byte, error)
func (s *Storage) Set(key string, val []byte, exp time.Duration) error
func (s *Storage) SetWithContext(ctx context.Context, key string, val []byte, exp time.Duration) error
func (s *Storage) Delete(key string) error
func (s *Storage) DeleteWithContext(ctx context.Context, key string) error
func (s *Storage) Reset() error
func (s *Storage) ResetWithContext(ctx context.Context) error
func (s *Storage) Close() error
func (s *Storage) Conn() driver.Client
func (s *Storage) GetSchemaInfo() *SchemaInfo
```

**Note:** The context methods are dummy methods and don't have any functionality, as Aerospike does not support context cancellation in its client library. They are provided for compliance with the Fiber storage interface.

### Installation

Aerospike 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:
Expand Down
21 changes: 21 additions & 0 deletions aerospike/aerospike.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package aerospike

import (
"context"
"log"
"time"

Expand Down Expand Up @@ -216,6 +217,11 @@ func (s *Storage) Get(key string) ([]byte, error) {
return data, nil
}

// GetWithContext gets value by key (dummy context support)
func (s *Storage) GetWithContext(ctx context.Context, key string) ([]byte, error) {
return s.Get(key)
}

// Set key with value
func (s *Storage) Set(key string, val []byte, exp time.Duration) error {
k, err := aerospike.NewKey(s.namespace, s.setName, key)
Expand All @@ -242,6 +248,11 @@ func (s *Storage) Set(key string, val []byte, exp time.Duration) error {
return s.client.Put(writePolicy, k, bins)
}

// SetWithContext sets value by key (dummy context support)
func (s *Storage) SetWithContext(ctx context.Context, key string, val []byte, exp time.Duration) error {
return s.Set(key, val, exp)
}

// Delete key
func (s *Storage) Delete(key string) error {
k, err := aerospike.NewKey(s.namespace, s.setName, key)
Expand All @@ -253,6 +264,11 @@ func (s *Storage) Delete(key string) error {
return err
}

// DeleteWithContext deletes key (dummy context support)
func (s *Storage) DeleteWithContext(ctx context.Context, key string) error {
return s.Delete(key)
}

// Reset all keys
func (s *Storage) Reset() error {
// Use ScanAll which returns a Recordset
Expand Down Expand Up @@ -293,6 +309,11 @@ func (s *Storage) Reset() error {
return nil
}

// ResetWithContext resets all keys (dummy context support)
func (s *Storage) ResetWithContext(ctx context.Context) error {
return s.Reset()
}

// Close the storage
func (s *Storage) Close() error {
s.client.Close()
Expand Down
6 changes: 4 additions & 2 deletions arangodb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ title: ArangoDB

A ArangoDB storage driver using `arangodb/go-driver` and [arangodb/go-driver](https://github.com/arangodb/go-driver).

**Note: Requires Go 1.19 and above**

### Table of Contents
- [Signatures](#signatures)
- [Installation](#installation)
Expand All @@ -21,9 +19,13 @@ A ArangoDB storage driver using `arangodb/go-driver` and [arangodb/go-driver](ht
### Signatures
```go
func New(config ...Config) Storage
func (s *Storage) GetWithContext(ctx context.Context, key string) ([]byte, error)
func (s *Storage) Get(key string) ([]byte, error)
func (s *Storage) SetWithContext(ctx context.Context, key string, val []byte, exp time.Duration) error
func (s *Storage) Set(key string, val []byte, exp time.Duration) error
func (s *Storage) DeleteWithContext(ctx context.Context, key string) error
func (s *Storage) Delete(key string) error
func (s *Storage) ResetWithContext(ctx context.Context) error
func (s *Storage) Reset() error
func (s *Storage) Close() error
func (s *Storage) Conn() driver.Client
Expand Down
Loading