Compare commits

...

57 Commits

Author SHA1 Message Date
RW
5b6559e084 Merge pull request #1073 from gofiber/dependabot/go_modules/postgres/github.com/jackc/pgx/v5-5.5.0
Bump github.com/jackc/pgx/v5 from 5.4.3 to 5.5.0 in /postgres
2023-11-06 08:09:45 +01:00
dependabot[bot]
32a3153566 Bump github.com/jackc/pgx/v5 from 5.4.3 to 5.5.0 in /postgres
Bumps [github.com/jackc/pgx/v5](https://github.com/jackc/pgx) from 5.4.3 to 5.5.0.
- [Changelog](https://github.com/jackc/pgx/blob/master/CHANGELOG.md)
- [Commits](https://github.com/jackc/pgx/compare/v5.4.3...v5.5.0)

---
updated-dependencies:
- dependency-name: github.com/jackc/pgx/v5
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-11-06 07:08:06 +00:00
RW
b6cf4057d0 Merge pull request #1053 from gofiber/memory-keys
Add support for Keys() to Memory Driver
2023-11-05 11:20:15 +01:00
RW
d5968313b3 Merge pull request #1052 from gofiber/redis-keys
Add support for Keys() to Redis Driver
2023-11-05 11:19:58 +01:00
RW
7638e00caa Update release-drafter-scylladb.yml 2023-11-03 12:11:19 +01:00
RW
25737614cf Merge pull request #1064 from gofiber/dependabot/go_modules/s3/github.com/aws/aws-sdk-go-v2/feature/s3/manager-1.13.1
Bump github.com/aws/aws-sdk-go-v2/feature/s3/manager from 1.11.91 to 1.13.1 in /s3
2023-11-03 09:00:36 +01:00
RW
ffe12feafa Merge pull request #1065 from gofiber/dependabot/go_modules/dynamodb/github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue-1.12.0
Bump github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue from 1.10.43 to 1.12.0 in /dynamodb
2023-11-03 08:53:59 +01:00
dependabot[bot]
71c101a0fa Bump github.com/aws/aws-sdk-go-v2/feature/s3/manager in /s3
Bumps [github.com/aws/aws-sdk-go-v2/feature/s3/manager](https://github.com/aws/aws-sdk-go-v2) from 1.11.91 to 1.13.1.
- [Release notes](https://github.com/aws/aws-sdk-go-v2/releases)
- [Changelog](https://github.com/aws/aws-sdk-go-v2/blob/config/v1.13.1/CHANGELOG.md)
- [Commits](https://github.com/aws/aws-sdk-go-v2/compare/feature/s3/manager/v1.11.91...config/v1.13.1)

---
updated-dependencies:
- dependency-name: github.com/aws/aws-sdk-go-v2/feature/s3/manager
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-11-03 07:49:19 +00:00
RW
a00477e510 Merge pull request #1063 from gofiber/dependabot/go_modules/s3/github.com/aws/aws-sdk-go-v2-1.22.1
Bump github.com/aws/aws-sdk-go-v2 from 1.21.2 to 1.22.1 in /s3
2023-11-03 08:48:45 +01:00
dependabot[bot]
c3b4b6e96c Bump github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue
Bumps [github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue](https://github.com/aws/aws-sdk-go-v2) from 1.10.43 to 1.12.0.
- [Release notes](https://github.com/aws/aws-sdk-go-v2/releases)
- [Changelog](https://github.com/aws/aws-sdk-go-v2/blob/v1.12.0/CHANGELOG.md)
- [Commits](https://github.com/aws/aws-sdk-go-v2/compare/feature/dynamodb/attributevalue/v1.10.43...v1.12.0)

---
updated-dependencies:
- dependency-name: github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-11-03 07:45:47 +00:00
RW
ae8f210306 Merge pull request #1067 from gofiber/dependabot/go_modules/dynamodb/github.com/aws/aws-sdk-go-v2/config-1.22.0
Bump github.com/aws/aws-sdk-go-v2/config from 1.19.1 to 1.22.0 in /dynamodb
2023-11-03 08:45:10 +01:00
dependabot[bot]
139b0f4870 Bump github.com/aws/aws-sdk-go-v2/config in /dynamodb
Bumps [github.com/aws/aws-sdk-go-v2/config](https://github.com/aws/aws-sdk-go-v2) from 1.19.1 to 1.22.0.
- [Release notes](https://github.com/aws/aws-sdk-go-v2/releases)
- [Commits](https://github.com/aws/aws-sdk-go-v2/compare/v1.19.1...v1.22.0)

---
updated-dependencies:
- dependency-name: github.com/aws/aws-sdk-go-v2/config
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-11-03 07:44:44 +00:00
RW
8749583563 Merge pull request #1070 from gofiber/dependabot/go_modules/dynamodb/github.com/aws/aws-sdk-go-v2/service/dynamodb-1.25.0
Bump github.com/aws/aws-sdk-go-v2/service/dynamodb from 1.23.0 to 1.25.0 in /dynamodb
2023-11-03 08:44:07 +01:00
dependabot[bot]
54fa28a305 Bump github.com/aws/aws-sdk-go-v2/service/dynamodb in /dynamodb
Bumps [github.com/aws/aws-sdk-go-v2/service/dynamodb](https://github.com/aws/aws-sdk-go-v2) from 1.23.0 to 1.25.0.
- [Release notes](https://github.com/aws/aws-sdk-go-v2/releases)
- [Changelog](https://github.com/aws/aws-sdk-go-v2/blob/service/s3/v1.25.0/CHANGELOG.md)
- [Commits](https://github.com/aws/aws-sdk-go-v2/compare/service/s3/v1.23.0...service/s3/v1.25.0)

---
updated-dependencies:
- dependency-name: github.com/aws/aws-sdk-go-v2/service/dynamodb
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-11-03 07:40:49 +00:00
RW
ca5ced95d7 Merge pull request #1068 from gofiber/dependabot/go_modules/dynamodb/github.com/aws/aws-sdk-go-v2/credentials-1.15.1
Bump github.com/aws/aws-sdk-go-v2/credentials from 1.13.43 to 1.15.1 in /dynamodb
2023-11-03 08:40:23 +01:00
dependabot[bot]
5c018e302d Bump github.com/aws/aws-sdk-go-v2/credentials in /dynamodb
Bumps [github.com/aws/aws-sdk-go-v2/credentials](https://github.com/aws/aws-sdk-go-v2) from 1.13.43 to 1.15.1.
- [Release notes](https://github.com/aws/aws-sdk-go-v2/releases)
- [Changelog](https://github.com/aws/aws-sdk-go-v2/blob/config/v1.15.1/CHANGELOG.md)
- [Commits](https://github.com/aws/aws-sdk-go-v2/compare/credentials/v1.13.43...config/v1.15.1)

---
updated-dependencies:
- dependency-name: github.com/aws/aws-sdk-go-v2/credentials
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-11-03 07:34:09 +00:00
RW
716f5a4878 Merge pull request #1062 from gofiber/dependabot/github_actions/actions/checkout-4
Bump actions/checkout from 3 to 4
2023-11-03 08:33:03 +01:00
RW
464c871e79 Merge pull request #1061 from gofiber/dependabot/go_modules/rueidis/github.com/redis/rueidis-1.0.21
Bump github.com/redis/rueidis from 1.0.20 to 1.0.21 in /rueidis
2023-11-03 08:31:34 +01:00
dependabot[bot]
56a8596fe9 Bump github.com/aws/aws-sdk-go-v2 from 1.21.2 to 1.22.1 in /s3
Bumps [github.com/aws/aws-sdk-go-v2](https://github.com/aws/aws-sdk-go-v2) from 1.21.2 to 1.22.1.
- [Release notes](https://github.com/aws/aws-sdk-go-v2/releases)
- [Commits](https://github.com/aws/aws-sdk-go-v2/compare/v1.21.2...v1.22.1)

---
updated-dependencies:
- dependency-name: github.com/aws/aws-sdk-go-v2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-11-03 07:30:22 +00:00
dependabot[bot]
8ba0110b24 Bump actions/checkout from 3 to 4
Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-11-03 07:29:30 +00:00
dependabot[bot]
75ce232c9c Bump github.com/redis/rueidis from 1.0.20 to 1.0.21 in /rueidis
Bumps [github.com/redis/rueidis](https://github.com/redis/rueidis) from 1.0.20 to 1.0.21.
- [Release notes](https://github.com/redis/rueidis/releases)
- [Commits](https://github.com/redis/rueidis/compare/v1.0.20...v1.0.21)

---
updated-dependencies:
- dependency-name: github.com/redis/rueidis
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-11-03 07:29:22 +00:00
RW
602deafe0a Merge pull request #1047 from Chris-Basson-Grundling/main
New Storage Driver: ScyllaDb
2023-11-03 08:28:44 +01:00
RW
07fab67bb1 Merge pull request #1060 from gofiber/dependabot/go_modules/arangodb/github.com/arangodb/go-driver-1.6.1
Bump github.com/arangodb/go-driver from 1.6.0 to 1.6.1 in /arangodb
2023-11-01 08:38:23 +01:00
dependabot[bot]
6b21d0af38 Bump github.com/arangodb/go-driver from 1.6.0 to 1.6.1 in /arangodb
Bumps [github.com/arangodb/go-driver](https://github.com/arangodb/go-driver) from 1.6.0 to 1.6.1.
- [Release notes](https://github.com/arangodb/go-driver/releases)
- [Changelog](https://github.com/arangodb/go-driver/blob/master/CHANGELOG.md)
- [Commits](https://github.com/arangodb/go-driver/compare/v1.6.0...v1.6.1)

---
updated-dependencies:
- dependency-name: github.com/arangodb/go-driver
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-11-01 07:37:03 +00:00
RW
9c99c74835 Merge pull request #1059 from gofiber/dependabot/go_modules/redis/github.com/redis/go-redis/v9-9.3.0
Bump github.com/redis/go-redis/v9 from 9.2.1 to 9.3.0 in /redis
2023-11-01 08:05:52 +01:00
dependabot[bot]
05c797f133 Bump github.com/redis/go-redis/v9 from 9.2.1 to 9.3.0 in /redis
Bumps [github.com/redis/go-redis/v9](https://github.com/redis/go-redis) from 9.2.1 to 9.3.0.
- [Release notes](https://github.com/redis/go-redis/releases)
- [Changelog](https://github.com/redis/go-redis/blob/master/CHANGELOG.md)
- [Commits](https://github.com/redis/go-redis/compare/v9.2.1...v9.3.0)

---
updated-dependencies:
- dependency-name: github.com/redis/go-redis/v9
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-11-01 07:03:58 +00:00
RW
894f364785 Merge pull request #1057 from gofiber/dependabot/go_modules/s3/github.com/aws/aws-sdk-go-v2/config-1.19.1
Bump github.com/aws/aws-sdk-go-v2/config from 1.19.0 to 1.19.1 in /s3
2023-10-30 08:57:34 +01:00
dependabot[bot]
b607828b9d Bump github.com/aws/aws-sdk-go-v2/config from 1.19.0 to 1.19.1 in /s3
Bumps [github.com/aws/aws-sdk-go-v2/config](https://github.com/aws/aws-sdk-go-v2) from 1.19.0 to 1.19.1.
- [Release notes](https://github.com/aws/aws-sdk-go-v2/releases)
- [Changelog](https://github.com/aws/aws-sdk-go-v2/blob/v1.19.1/CHANGELOG.md)
- [Commits](https://github.com/aws/aws-sdk-go-v2/compare/v1.19.0...v1.19.1)

---
updated-dependencies:
- dependency-name: github.com/aws/aws-sdk-go-v2/config
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-10-30 07:56:17 +00:00
RW
32c87e29aa Merge pull request #1056 from gofiber/dependabot/go_modules/dynamodb/github.com/aws/aws-sdk-go-v2/config-1.19.1
Bump github.com/aws/aws-sdk-go-v2/config from 1.19.0 to 1.19.1 in /dynamodb
2023-10-30 08:33:30 +01:00
dependabot[bot]
ee8aa518e5 Bump github.com/aws/aws-sdk-go-v2/config in /dynamodb
Bumps [github.com/aws/aws-sdk-go-v2/config](https://github.com/aws/aws-sdk-go-v2) from 1.19.0 to 1.19.1.
- [Release notes](https://github.com/aws/aws-sdk-go-v2/releases)
- [Changelog](https://github.com/aws/aws-sdk-go-v2/blob/v1.19.1/CHANGELOG.md)
- [Commits](https://github.com/aws/aws-sdk-go-v2/compare/v1.19.0...v1.19.1)

---
updated-dependencies:
- dependency-name: github.com/aws/aws-sdk-go-v2/config
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-10-30 07:32:12 +00:00
Juan Calderon-Perez
50bea20332 Update empty check, value should be Nil 2023-10-29 21:04:03 -04:00
Juan Calderon-Perez
22f4401661 Add fix to verify Keys are expired during Keys() call. 2023-10-29 21:00:43 -04:00
Juan Calderon-Perez
0e92f332da Fix check for no keys 2023-10-29 20:48:39 -04:00
Juan Calderon-Perez
7921dc7e37 Add support for Keys() to Memory Driver 2023-10-29 20:42:46 -04:00
Juan Calderon-Perez
0b9f4aebc8 Create a testStore per test 2023-10-29 20:24:11 -04:00
Juan Calderon-Perez
2143a67c8d Add sleep after creating Redis Cluster 2023-10-29 20:06:45 -04:00
Juan Calderon-Perez
3b5d81397c Add support for Keys() to Redis Driver 2023-10-29 20:01:23 -04:00
Chris Grundling
af89d59508 Merge branch 'main' into main 2023-10-27 11:42:14 +02:00
chris.grundling
74f7e9b4c9 Updated checks for empty string, updated error messages 2023-10-27 11:29:35 +02:00
chris.grundling
f602540e53 Updated set to use default scylladb ttl, updated tests 2023-10-26 18:03:26 +02:00
chris.grundling
05194dded6 Updated get expiration compare 2023-10-26 15:43:07 +02:00
chris.grundling
957cba4743 Merge branch 'main' of github.com:Chris-Basson-Grundling/ScyllaDB 2023-10-26 15:30:44 +02:00
chris.grundling
2a41f5c60f Updated replace in go mod, updated Expiration test 2023-10-26 15:26:18 +02:00
Juan Calderon-Perez
f6eab90d0b Merge branch 'main' into main 2023-10-25 22:07:01 -04:00
chris.grundling
ddb765f758 Updated Benchmarks to align with all. 2023-10-25 20:48:50 +02:00
chris.grundling
cd80e17ce8 Updated README 2023-10-25 20:34:43 +02:00
chris.grundling
edb77f865f Added TLS support, Updated README, Added Benchmark tests 2023-10-25 20:29:31 +02:00
chris.grundling
a2e3e4fced Updated benchmark 2023-10-25 06:41:06 +02:00
chris.grundling
c3431ff1af Updated main README, updated benchmark 2023-10-25 06:34:06 +02:00
chris.grundling
62ebac1d4f Updated test-scylladb, README and tests to use testify for Asserts 2023-10-25 06:06:04 +02:00
chris.grundling
3f4bff91cd ScyllaDb readme cleanup, added set port from config. 2023-10-24 23:46:44 +02:00
Chris Grundling
fc00b7501c Merge branch 'gofiber:main' into main 2023-10-24 23:32:57 +02:00
chris.grundling
2ba3adef60 Updated Scylladb 2023-10-24 23:21:12 +02:00
chris.grundling
f33ba7493c Updated test-scylladb 2023-10-24 22:03:17 +02:00
chris.grundling
1a9f3e144e Updated test-scylladb 2023-10-24 21:37:52 +02:00
chris.grundling
0732a00253 Updated tests-scylladb and readme 2023-10-24 21:34:03 +02:00
chris.grundling
2f5ae09380 New Storage Driver: ScyllaDb 2023-10-24 21:16:48 +02:00
34 changed files with 1173 additions and 159 deletions

View File

@@ -140,3 +140,9 @@ updates:
- "🤖 Dependencies"
schedule:
interval: "daily"
- package-ecosystem: "gomod"
directory: "/scylladb/" # Location of package manifests
labels:
- "🤖 Dependencies"
schedule:
interval: "daily"

43
.github/release-drafter-scylladb.yml vendored Normal file
View File

@@ -0,0 +1,43 @@
name-template: 'ScyllaDb - v$RESOLVED_VERSION'
tag-template: 'scylladb/v$RESOLVED_VERSION'
tag-prefix: scylladb/v
include-paths:
- scylladb
categories:
- title: '🚀 New'
labels:
- '✏️ Feature'
- title: '🧹 Updates'
labels:
- '🧹 Updates'
- '🤖 Dependencies'
- title: '🐛 Fixes'
labels:
- '☢️ Bug'
- title: '📚 Documentation'
labels:
- '📒 Documentation'
change-template: '- $TITLE (#$NUMBER)'
change-title-escapes: '\<*_&' # You can add # and @ to disable mentions, and add ` to disable code blocks.
version-resolver:
major:
labels:
- 'major'
minor:
labels:
- 'minor'
- '✏️ Feature'
patch:
labels:
- 'patch'
- '📒 Documentation'
- '☢️ Bug'
- '🤖 Dependencies'
- '🧹 Updates'
default: patch
template: |
$CHANGES
**Full Changelog**: https://github.com/$OWNER/$REPOSITORY/compare/$PREVIOUS_TAG...scylladb/v$RESOLVED_VERSION
Thank you $CONTRIBUTORS for making this update possible.

View File

@@ -117,6 +117,11 @@ jobs:
run: |
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
- name: Install ScyllaDb
run: |
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
sleep 15 # Wait for ScyllaDb to initialize
- name: Setup Redis
uses: shogo82148/actions-setup-redis@v1
with:

View File

@@ -124,3 +124,7 @@ jobs:
working-directory: ./rueidis
run: gosec ./...
# -----
- name: Run Gosec (scylladb)
working-directory: ./scylladb
run: gosec ./...
# -----

View File

@@ -0,0 +1,19 @@
name: Release Drafter ScyllaDb
on:
push:
# branches to consider in the event; optional, defaults to all
branches:
- master
- main
paths:
- 'scylladb/**'
jobs:
draft_release_scylladb:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: release-drafter/release-drafter@v5
with:
config-name: release-drafter-scylladb.yml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@@ -66,6 +66,9 @@ jobs:
slave3-port: 7005
sleep-duration: 10
- name: Wait for Redis to Start
run: sleep 15
- name: Install Go
uses: actions/setup-go@v4
with:

39
.github/workflows/test-scylladb.yml vendored Normal file
View File

@@ -0,0 +1,39 @@
on:
push:
branches:
- master
- main
paths:
- 'scylladb/**'
pull_request:
paths:
- 'scylladb/**'
name: "Tests ScyllaDb"
jobs:
Tests:
runs-on: ubuntu-latest
strategy:
matrix:
go-version:
- 1.20.x
- 1.21.x
steps:
- name: Fetch Repository
uses: actions/checkout@v4
- name: Run ScyllaDb
run: |
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
sleep 30 # Wait for ScyllaDb to initialize
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: '${{ matrix.go-version }}'
- name: Run Test
run: cd ./scylladb && go test ./... -v -race

View File

@@ -69,5 +69,6 @@ type Storage interface {
- [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>
- [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>
- [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>
- [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>
- [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>

View File

@@ -3,7 +3,7 @@ module github.com/gofiber/storage/arangodb/v2
go 1.19
require (
github.com/arangodb/go-driver v1.6.0
github.com/arangodb/go-driver v1.6.1
github.com/gofiber/utils/v2 v2.0.0-beta.3
github.com/stretchr/testify v1.8.4
)

View File

@@ -1,5 +1,5 @@
github.com/arangodb/go-driver v1.6.0 h1:NFWj/idqXZxhFVueihMSI2R9NotNIsgvNfM/xmpekb4=
github.com/arangodb/go-driver v1.6.0/go.mod h1:HQmdGkvNMVBTE3SIPSQ8T/ZddC6iwNsfMR+dDJQxIsI=
github.com/arangodb/go-driver v1.6.1 h1:bnhrpbA4U1NU13JOWs5sWWYMtQwdjKT0+jkl8dSndyY=
github.com/arangodb/go-driver v1.6.1/go.mod h1:ywucwwi34GBxxXFWw/ym+7/66//L4K9abxk/sFJro2k=
github.com/arangodb/go-velocypack v0.0.0-20200318135517-5af53c29c67e h1:Xg+hGrY2LcQBbxd0ZFdbGSyRKTYMZCfBbw/pMJFOk1g=
github.com/arangodb/go-velocypack v0.0.0-20200318135517-5af53c29c67e/go.mod h1:mq7Shfa/CaixoDxiyAAc5jZ6CVBAyPaNQCGS7mkj4Ho=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

View File

@@ -3,27 +3,27 @@ module github.com/gofiber/storage/dynamodb/v2
go 1.19
require (
github.com/aws/aws-sdk-go-v2 v1.21.2
github.com/aws/aws-sdk-go-v2/config v1.19.0
github.com/aws/aws-sdk-go-v2/credentials v1.13.43
github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.10.43
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.23.0
github.com/aws/aws-sdk-go-v2 v1.22.1
github.com/aws/aws-sdk-go-v2/config v1.22.0
github.com/aws/aws-sdk-go-v2/credentials v1.15.1
github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.12.0
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.25.0
github.com/stretchr/testify v1.8.4
)
require (
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 // indirect
github.com/aws/aws-sdk-go-v2/service/dynamodbstreams v1.15.7 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.15 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.7.37 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 // indirect
github.com/aws/smithy-go v1.15.0 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.2 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.1 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.1 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.5.0 // indirect
github.com/aws/aws-sdk-go-v2/service/dynamodbstreams v1.17.0 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.10.0 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.8.1 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.10.1 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.17.0 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.19.0 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.25.0 // indirect
github.com/aws/smithy-go v1.16.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect

View File

@@ -1,42 +1,41 @@
github.com/aws/aws-sdk-go-v2 v1.21.2 h1:+LXZ0sgo8quN9UOKXXzAWRT3FWd4NxeXWOZom9pE7GA=
github.com/aws/aws-sdk-go-v2 v1.21.2/go.mod h1:ErQhvNuEMhJjweavOYhxVkn2RUx7kQXVATHrjKtxIpM=
github.com/aws/aws-sdk-go-v2/config v1.19.0 h1:AdzDvwH6dWuVARCl3RTLGRc4Ogy+N7yLFxVxXe1ClQ0=
github.com/aws/aws-sdk-go-v2/config v1.19.0/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE=
github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8=
github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg=
github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.10.43 h1:jlR1Rwjb3z5d1p0sqhNcuCaqdp73H+1O/X8Lc2kBDrY=
github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.10.43/go.mod h1:X1HGecFASboCkBt1GJRM4a/FDYYogu9AciUoXVsbr4U=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 h1:nFBQlGtkbPzp/NjZLuFxRqmT91rLJkgvsEQs68h962Y=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43/go.mod h1:auo+PiyLl0n1l8A0e8RIeR8tOzYPfZZH/JNlrJ8igTQ=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 h1:JRVhO25+r3ar2mKGP7E0LDl8K9/G36gjlqca5iQbaqc=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37/go.mod h1:Qe+2KtKml+FEsQF/DHmDV+xjtche/hwoF75EG4UlHW8=
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4=
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE=
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.23.0 h1:xmSAn14nM6IdHyuWO/bsrAagOQtnqzuUCLxdVmj9nhg=
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.23.0/go.mod h1:1HkLh8vaL4obF95fne7ZOu7sxomS/+vkBt3/+gqqwE4=
github.com/aws/aws-sdk-go-v2/service/dynamodbstreams v1.15.7 h1:WCeS9WZbIqEKCbgIkrHB5jw/9mO2QMYTLPF8wee3v4Y=
github.com/aws/aws-sdk-go-v2/service/dynamodbstreams v1.15.7/go.mod h1:uT1paW42RVCVEoAEbWKu98gEI0GMBWUsT/H+pI4ODJQ=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.15 h1:7R8uRYyXzdD71KWVCL78lJZltah6VVznXBazvKjfH58=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.15/go.mod h1:26SQUPcTNgV1Tapwdt4a1rOsYRsnBsJHLMPoxK2b0d8=
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.7.37 h1:4LoizcvPT9A0tiAFhepxn0bGZXkzvN0pG0epydY3Pno=
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.7.37/go.mod h1:7xBUZyP6LeLc+5Ym9PG7atqw4sR28sBtYcHETik+bPE=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck=
github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k=
github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg=
github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU=
github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ=
github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8=
github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA=
github.com/aws/aws-sdk-go-v2 v1.22.1 h1:sjnni/AuoTXxHitsIdT0FwmqUuNUuHtufcVDErVFT9U=
github.com/aws/aws-sdk-go-v2 v1.22.1/go.mod h1:Kd0OJtkW3Q0M0lUWGszapWjEvrXDzRW+D21JNsroB+c=
github.com/aws/aws-sdk-go-v2/config v1.22.0 h1:9Mm99OalzZRz0ab5fpodMoHBApHS6pqRNp3M9NmzvDg=
github.com/aws/aws-sdk-go-v2/config v1.22.0/go.mod h1:2eWgw5lps8fKI7LZVTrRTYP6HE6k/uEFUuTSHfXwqP0=
github.com/aws/aws-sdk-go-v2/credentials v1.15.1 h1:hmf6lAm9hk7uLCfapZn/jL05lm6Uwdbn1B0fgjyuf4M=
github.com/aws/aws-sdk-go-v2/credentials v1.15.1/go.mod h1:QTcHga3ZbQOneJuxmGBOCxiClxmp+TlvmjFexAnJ790=
github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.12.0 h1:nKmTvugKsuO2bHkL0vkpHEFtRoT/ijOVx0VdP+LLjgw=
github.com/aws/aws-sdk-go-v2/feature/dynamodb/attributevalue v1.12.0/go.mod h1:vxJ/EEKuP9CCSG4lEViyU9i5gr2M0X5OIJqTcX/oxuU=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.2 h1:gIeH4+o1MN/caGBWjoGQTUTIu94xD6fI5B2+TcwBf70=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.2/go.mod h1:wLyMIo/zPOhQhPXTddpfdkSleyigtFi8iMnC+2m/SK4=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.1 h1:fi1ga6WysOyYb5PAf3Exd6B5GiSNpnZim4h1rhlBqx0=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.1/go.mod h1:V5CY8wNurvPUibTi9mwqUqpiFZ5LnioKWIFUDtIzdI8=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.1 h1:ZpaV/j48RlPc4AmOZuPv22pJliXjXq8/reL63YzyFnw=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.1/go.mod h1:R8aXraabD2e3qv1csxM14/X9WF4wFMIY0kH4YEtYD5M=
github.com/aws/aws-sdk-go-v2/internal/ini v1.5.0 h1:DqOQvIfmGkXZUVJnl9VRk0AnxyS59tCtX9k1Pyss4Ak=
github.com/aws/aws-sdk-go-v2/internal/ini v1.5.0/go.mod h1:VV/Kbw9Mg1GWJOT9WK+oTL3cWZiXtapnNvDSRqTZLsg=
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.25.0 h1:wAG9NailFhGhg8Ngg2YeCtzGmFWc63SYqJKdvN5ZMkE=
github.com/aws/aws-sdk-go-v2/service/dynamodb v1.25.0/go.mod h1:ByrosnNlEq6xkA0d+FwB4f0HH/5KWCcgBqVxAt+Rsps=
github.com/aws/aws-sdk-go-v2/service/dynamodbstreams v1.17.0 h1:iTGBKvqZNU9SsQCzRiK8f0u9kVtdG4K1Q68A97JRn6w=
github.com/aws/aws-sdk-go-v2/service/dynamodbstreams v1.17.0/go.mod h1:EabdnPA1OVcrolKX/hyMSNvJv8MBCZtlAlncsg/b/rA=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.10.0 h1:CJxo7ZBbaIzmXfV3hjcx36n9V87gJsIUPJflwqEHl3Q=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.10.0/go.mod h1:yjVfjuY4nD1EW9i387Kau+I6V5cBA5YnC/mWNopjZrI=
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.8.1 h1:aY45T0Xk+xHHrQPlQrp8IhrgN7k4SL5VF2UXhsmI2rs=
github.com/aws/aws-sdk-go-v2/service/internal/endpoint-discovery v1.8.1/go.mod h1:5E/dXkj2ljMIAvuYaFuYwitKJg6ULwsDbUr3g8izVB0=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.10.1 h1:2OXw3ppu1XsB6rqKEMV4tnecTjIY3PRV2U6IP6KPJQo=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.10.1/go.mod h1:FZB4AdakIqW/yERVdGJA6Z9jraax1beXfhBBnK2wwR8=
github.com/aws/aws-sdk-go-v2/service/sso v1.17.0 h1:I/Oh3IxGPfHXiGnwM54TD6hNr/8TlUrBXAtTyGhR+zw=
github.com/aws/aws-sdk-go-v2/service/sso v1.17.0/go.mod h1:H6NCMvDBqA+CvIaXzaSqM6LWtzv9BzZrqBOqz+PzRF8=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.19.0 h1:irbXQkfVYIRaewYSXcu4yVk0m2T+JzZd0dkop7FjmO0=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.19.0/go.mod h1:4wPNCkM22+oRe71oydP66K50ojDUC33XutSMi2pEF/M=
github.com/aws/aws-sdk-go-v2/service/sts v1.25.0 h1:sYIFy8tm1xQwRvVQ4CRuBGXKIg9sHNuG6+3UAQuoujk=
github.com/aws/aws-sdk-go-v2/service/sts v1.25.0/go.mod h1:S/LOQUeYDfJeJpFCIJDMjy7dwL4aA33HUdVi+i7uH8k=
github.com/aws/smithy-go v1.16.0 h1:gJZEH/Fqh+RsvlJ1Zt4tVAtV6bKkp3cC+R6FCZMNzik=
github.com/aws/smithy-go v1.16.0/go.mod h1:NukqUGpCZIILqqiV0NIjeFh24kd/FAa4beRb6nbIUPE=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=

View File

@@ -31,6 +31,7 @@ func (s *Storage) Delete(key string) error
func (s *Storage) Reset() error
func (s *Storage) Close() error
func (s *Storage) Conn() map[string]entry
func (s *Storage) Keys() ([][]byte, error)
```
### Installation

View File

@@ -2,14 +2,10 @@ module github.com/gofiber/storage/memory/v2
go 1.19
require (
github.com/gofiber/utils/v2 v2.0.0-beta.3
github.com/stretchr/testify v1.8.4
)
require github.com/stretchr/testify v1.8.4
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

View File

@@ -1,9 +1,5 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gofiber/utils/v2 v2.0.0-beta.3 h1:pfOhUDDVjBJpkWv6C5jaDyYLvpui7zQ97zpyFFsUOKw=
github.com/gofiber/utils/v2 v2.0.0-beta.3/go.mod h1:jsl17+MsKfwJjM3ONCE9Rzji/j8XNbwjhUVTjzgfDCo=
github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4=
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=

View File

@@ -141,3 +141,29 @@ func (s *Storage) Conn() map[string]entry {
defer s.mux.RUnlock()
return s.db
}
// Return all the keys
func (s *Storage) Keys() ([][]byte, error) {
s.mux.RLock()
defer s.mux.RUnlock()
if len(s.db) == 0 {
return nil, nil
}
ts := atomic.LoadUint32(&internal.Timestamp)
keys := make([][]byte, 0, len(s.db))
for key, v := range s.db {
// Filter out the expired keys
if v.expiry == 0 || v.expiry > ts {
keys = append(keys, []byte(key))
}
}
// Double check if no valid keys were found
if len(keys) == 0 {
return nil, nil
}
return keys, nil
}

View File

@@ -7,22 +7,26 @@ import (
"github.com/stretchr/testify/require"
)
var testStore = New()
func Test_Storage_Memory_Set(t *testing.T) {
var (
key = "john"
val = []byte("doe")
testStore = New()
key = "john"
val = []byte("doe")
)
err := testStore.Set(key, val, 0)
require.NoError(t, err)
keys, err := testStore.Keys()
require.NoError(t, err)
require.Len(t, keys, 1)
}
func Test_Storage_Memory_Set_Override(t *testing.T) {
var (
key = "john"
val = []byte("doe")
testStore = New()
key = "john"
val = []byte("doe")
)
err := testStore.Set(key, val, 0)
@@ -30,12 +34,17 @@ func Test_Storage_Memory_Set_Override(t *testing.T) {
err = testStore.Set(key, val, 0)
require.NoError(t, err)
keys, err := testStore.Keys()
require.NoError(t, err)
require.Len(t, keys, 1)
}
func Test_Storage_Memory_Get(t *testing.T) {
var (
key = "john"
val = []byte("doe")
testStore = New()
key = "john"
val = []byte("doe")
)
err := testStore.Set(key, val, 0)
@@ -44,53 +53,104 @@ func Test_Storage_Memory_Get(t *testing.T) {
result, err := testStore.Get(key)
require.NoError(t, err)
require.Equal(t, val, result)
keys, err := testStore.Keys()
require.NoError(t, err)
require.Len(t, keys, 1)
}
func Test_Storage_Memory_Set_Expiration(t *testing.T) {
var (
key = "john"
val = []byte("doe")
exp = 1 * time.Second
testStore = New()
key = "john"
val = []byte("doe")
exp = 1 * time.Second
)
err := testStore.Set(key, val, exp)
require.NoError(t, err)
time.Sleep(1100 * time.Millisecond)
}
func Test_Storage_Memory_Get_Expired(t *testing.T) {
key := "john"
result, err := testStore.Get(key)
require.NoError(t, err)
require.Zero(t, len(result))
keys, err := testStore.Keys()
require.NoError(t, err)
require.Nil(t, keys)
}
func Test_Storage_Memory_Set_Long_Expiration_with_Keys(t *testing.T) {
var (
testStore = New()
key = "john"
val = []byte("doe")
exp = 5 * time.Second
)
keys, err := testStore.Keys()
require.NoError(t, err)
require.Nil(t, keys)
err = testStore.Set(key, val, exp)
require.NoError(t, err)
time.Sleep(1100 * time.Millisecond)
keys, err = testStore.Keys()
require.NoError(t, err)
require.Len(t, keys, 1)
time.Sleep(4000 * time.Millisecond)
result, err := testStore.Get(key)
require.NoError(t, err)
require.Zero(t, len(result))
keys, err = testStore.Keys()
require.NoError(t, err)
require.Nil(t, keys)
}
func Test_Storage_Memory_Get_NotExist(t *testing.T) {
testStore := New()
result, err := testStore.Get("notexist")
require.NoError(t, err)
require.Zero(t, len(result))
keys, err := testStore.Keys()
require.NoError(t, err)
require.Nil(t, keys)
}
func Test_Storage_Memory_Delete(t *testing.T) {
var (
key = "john"
val = []byte("doe")
testStore = New()
key = "john"
val = []byte("doe")
)
err := testStore.Set(key, val, 0)
require.NoError(t, err)
keys, err := testStore.Keys()
require.NoError(t, err)
require.Len(t, keys, 1)
err = testStore.Delete(key)
require.NoError(t, err)
result, err := testStore.Get(key)
require.NoError(t, err)
require.Zero(t, len(result))
keys, err = testStore.Keys()
require.NoError(t, err)
require.Nil(t, keys)
}
func Test_Storage_Memory_Reset(t *testing.T) {
testStore := New()
val := []byte("doe")
err := testStore.Set("john1", val, 0)
@@ -99,6 +159,10 @@ func Test_Storage_Memory_Reset(t *testing.T) {
err = testStore.Set("john2", val, 0)
require.NoError(t, err)
keys, err := testStore.Keys()
require.NoError(t, err)
require.Len(t, keys, 2)
err = testStore.Reset()
require.NoError(t, err)
@@ -109,17 +173,24 @@ func Test_Storage_Memory_Reset(t *testing.T) {
result, err = testStore.Get("john2")
require.NoError(t, err)
require.Zero(t, len(result))
keys, err = testStore.Keys()
require.NoError(t, err)
require.Nil(t, keys)
}
func Test_Storage_Memory_Close(t *testing.T) {
testStore := New()
require.Nil(t, testStore.Close())
}
func Test_Storage_Memory_Conn(t *testing.T) {
testStore := New()
require.True(t, testStore.Conn() != nil)
}
func Benchmark_Memory_Set(b *testing.B) {
testStore := New()
b.ReportAllocs()
b.ResetTimer()
@@ -132,6 +203,7 @@ func Benchmark_Memory_Set(b *testing.B) {
}
func Benchmark_Memory_Get(b *testing.B) {
testStore := New()
err := testStore.Set("john", []byte("doe"), 0)
require.NoError(b, err)
@@ -146,6 +218,7 @@ func Benchmark_Memory_Get(b *testing.B) {
}
func Benchmark_Memory_SetAndDelete(b *testing.B) {
testStore := New()
b.ReportAllocs()
b.ResetTimer()

View File

@@ -3,7 +3,7 @@ module github.com/gofiber/storage/postgres/v3
go 1.19
require (
github.com/jackc/pgx/v5 v5.4.3
github.com/jackc/pgx/v5 v5.5.0
github.com/stretchr/testify v1.8.4
)

View File

@@ -6,8 +6,8 @@ github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsI
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk=
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
github.com/jackc/pgx/v5 v5.4.3 h1:cxFyXhxlvAifxnkKKdlxv8XqUf59tDlYjnV5YYfsJJY=
github.com/jackc/pgx/v5 v5.4.3/go.mod h1:Ig06C2Vu0t5qXC60W8sqIthScaEnFvojjj9dSljmHRA=
github.com/jackc/pgx/v5 v5.5.0 h1:NxstgwndsTRy7eq9/kqYc/BZh5w2hHJV86wjvO+1xPw=
github.com/jackc/pgx/v5 v5.5.0/go.mod h1:Ig06C2Vu0t5qXC60W8sqIthScaEnFvojjj9dSljmHRA=
github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk=
github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=

View File

@@ -29,6 +29,7 @@ func (s *Storage) Delete(key string) error
func (s *Storage) Reset() error
func (s *Storage) Close() error
func (s *Storage) Conn() redis.UniversalClient
func (s *Storage) Keys() ([][]byte, error)
```
### Installation
Redis 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:

View File

@@ -3,7 +3,7 @@ module github.com/gofiber/storage/redis/v3
go 1.19
require (
github.com/redis/go-redis/v9 v9.2.1
github.com/redis/go-redis/v9 v9.3.0
github.com/stretchr/testify v1.8.4
)

View File

@@ -8,8 +8,8 @@ github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/r
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/redis/go-redis/v9 v9.2.1 h1:WlYJg71ODF0dVspZZCpYmoF1+U1Jjk9Rwd7pq6QmlCg=
github.com/redis/go-redis/v9 v9.2.1/go.mod h1:hdY0cQFCN4fnSYT6TkisLufl/4W5UIXyv0b/CLO2V2M=
github.com/redis/go-redis/v9 v9.3.0 h1:RiVDjmig62jIWp7Kk4XVLs0hzV6pI3PyTnnL0cnn0u0=
github.com/redis/go-redis/v9 v9.3.0/go.mod h1:hdY0cQFCN4fnSYT6TkisLufl/4W5UIXyv0b/CLO2V2M=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=

View File

@@ -74,8 +74,6 @@ func New(config ...Config) *Storage {
}
}
// ...
// Get value by key
func (s *Storage) Get(key string) ([]byte, error) {
if len(key) <= 0 {
@@ -118,3 +116,32 @@ func (s *Storage) Close() error {
func (s *Storage) Conn() redis.UniversalClient {
return s.db
}
// Return all the keys
func (s *Storage) Keys() ([][]byte, error) {
var keys [][]byte
var cursor uint64
var err error
for {
var batch []string
if batch, cursor, err = s.db.Scan(context.Background(), cursor, "*", 10).Result(); err != nil {
return nil, err
}
for _, key := range batch {
keys = append(keys, []byte(key))
}
if cursor == 0 {
break
}
}
if len(keys) == 0 {
return nil, nil
}
return keys, nil
}

View File

@@ -9,12 +9,11 @@ import (
"github.com/stretchr/testify/require"
)
var testStore = New(Config{
Reset: true,
})
func Test_Redis_Set(t *testing.T) {
var (
testStore = New(Config{
Reset: true,
})
key = "john"
val = []byte("doe")
)
@@ -25,6 +24,9 @@ func Test_Redis_Set(t *testing.T) {
func Test_Redis_Set_Override(t *testing.T) {
var (
testStore = New(Config{
Reset: true,
})
key = "john"
val = []byte("doe")
)
@@ -34,10 +36,17 @@ func Test_Redis_Set_Override(t *testing.T) {
err = testStore.Set(key, val, 0)
require.NoError(t, err)
keys, err := testStore.Keys()
require.NoError(t, err)
require.Len(t, keys, 1)
}
func Test_Redis_Get(t *testing.T) {
var (
testStore = New(Config{
Reset: true,
})
key = "john"
val = []byte("doe")
)
@@ -48,10 +57,17 @@ func Test_Redis_Get(t *testing.T) {
result, err := testStore.Get(key)
require.NoError(t, err)
require.Equal(t, val, result)
keys, err := testStore.Keys()
require.NoError(t, err)
require.Len(t, keys, 1)
}
func Test_Redis_Set_Expiration(t *testing.T) {
func Test_Redis_Expiration(t *testing.T) {
var (
testStore = New(Config{
Reset: true,
})
key = "john"
val = []byte("doe")
exp = 1 * time.Second
@@ -61,17 +77,20 @@ func Test_Redis_Set_Expiration(t *testing.T) {
require.NoError(t, err)
time.Sleep(1100 * time.Millisecond)
}
func Test_Redis_Get_Expired(t *testing.T) {
key := "john"
result, err := testStore.Get(key)
require.NoError(t, err)
require.Zero(t, len(result))
keys, err := testStore.Keys()
require.NoError(t, err)
require.Nil(t, keys)
}
func Test_Redis_Get_NotExist(t *testing.T) {
testStore := New(Config{
Reset: true,
})
result, err := testStore.Get("notexist")
require.NoError(t, err)
require.Zero(t, len(result))
@@ -79,6 +98,9 @@ func Test_Redis_Get_NotExist(t *testing.T) {
func Test_Redis_Delete(t *testing.T) {
var (
testStore = New(Config{
Reset: true,
})
key = "john"
val = []byte("doe")
)
@@ -92,9 +114,16 @@ func Test_Redis_Delete(t *testing.T) {
result, err := testStore.Get(key)
require.NoError(t, err)
require.Zero(t, len(result))
keys, err := testStore.Keys()
require.NoError(t, err)
require.Nil(t, keys)
}
func Test_Redis_Reset(t *testing.T) {
testStore := New(Config{
Reset: true,
})
val := []byte("doe")
err := testStore.Set("john1", val, 0)
@@ -103,6 +132,10 @@ func Test_Redis_Reset(t *testing.T) {
err = testStore.Set("john2", val, 0)
require.NoError(t, err)
keys, err := testStore.Keys()
require.NoError(t, err)
require.Len(t, keys, 2)
err = testStore.Reset()
require.NoError(t, err)
@@ -113,13 +146,23 @@ func Test_Redis_Reset(t *testing.T) {
result, err = testStore.Get("john2")
require.NoError(t, err)
require.Zero(t, len(result))
keys, err = testStore.Keys()
require.NoError(t, err)
require.Nil(t, keys)
}
func Test_Redis_Close(t *testing.T) {
testStore := New(Config{
Reset: true,
})
require.Nil(t, testStore.Close())
}
func Test_Redis_Conn(t *testing.T) {
testStore := New(Config{
Reset: true,
})
require.True(t, testStore.Conn() != nil)
}
@@ -184,6 +227,10 @@ func Test_Redis_Initalize_WithURL_TLS(t *testing.T) {
err = testStoreUrl.Delete(key)
require.NoError(t, err)
keys, err := testStoreUrl.Keys()
require.NoError(t, err)
require.Nil(t, keys)
require.Nil(t, testStoreUrl.Close())
}
@@ -226,6 +273,10 @@ func Test_Redis_Initalize_WithURL_TLS_Verify(t *testing.T) {
err = testStoreUrl.Delete(key)
require.NoError(t, err)
keys, err := testStoreUrl.Keys()
require.NoError(t, err)
require.Nil(t, keys)
require.Nil(t, testStoreUrl.Close())
}
@@ -249,6 +300,10 @@ func Test_Redis_Initalize_With_Secure_URL(t *testing.T) {
err = testStoreUrl.Delete(key)
require.NoError(t, err)
keys, err := testStoreUrl.Keys()
require.NoError(t, err)
require.Nil(t, keys)
require.Nil(t, testStoreUrl.Close())
}
@@ -273,6 +328,10 @@ func Test_Redis_Universal_Addrs(t *testing.T) {
err = testStoreUniversal.Delete(key)
require.NoError(t, err)
keys, err := testStoreUniversal.Keys()
require.NoError(t, err)
require.Nil(t, keys)
require.Nil(t, testStoreUniversal.Close())
}
@@ -299,6 +358,10 @@ func Test_Redis_Universal_With_URL_Undefined(t *testing.T) {
err = testStoreUniversal.Delete(key)
require.NoError(t, err)
keys, err := testStoreUniversal.Keys()
require.NoError(t, err)
require.Nil(t, keys)
require.Nil(t, testStoreUniversal.Close())
}
@@ -325,6 +388,10 @@ func Test_Redis_Universal_With_URL_Defined(t *testing.T) {
err = testStoreUniversal.Delete(key)
require.NoError(t, err)
keys, err := testStoreUniversal.Keys()
require.NoError(t, err)
require.Nil(t, keys)
require.Nil(t, testStoreUniversal.Close())
}
@@ -352,6 +419,10 @@ func Test_Redis_Universal_With_HostPort(t *testing.T) {
err = testStoreUniversal.Delete(key)
require.NoError(t, err)
keys, err := testStoreUniversal.Keys()
require.NoError(t, err)
require.Nil(t, keys)
require.Nil(t, testStoreUniversal.Close())
}
@@ -380,6 +451,10 @@ func Test_Redis_Universal_With_HostPort_And_URL(t *testing.T) {
err = testStoreUniversal.Delete(key)
require.NoError(t, err)
keys, err := testStoreUniversal.Keys()
require.NoError(t, err)
require.Nil(t, keys)
require.Nil(t, testStoreUniversal.Close())
}
@@ -410,10 +485,17 @@ func Test_Redis_Cluster(t *testing.T) {
err = testStoreUniversal.Delete(key)
require.NoError(t, err)
keys, err := testStoreUniversal.Keys()
require.NoError(t, err)
require.Nil(t, keys)
require.Nil(t, testStoreUniversal.Close())
}
func Benchmark_Redis_Set(b *testing.B) {
testStore := New(Config{
Reset: true,
})
b.ReportAllocs()
b.ResetTimer()
@@ -426,6 +508,9 @@ func Benchmark_Redis_Set(b *testing.B) {
}
func Benchmark_Redis_Get(b *testing.B) {
testStore := New(Config{
Reset: true,
})
err := testStore.Set("john", []byte("doe"), 0)
require.NoError(b, err)
@@ -440,6 +525,9 @@ func Benchmark_Redis_Get(b *testing.B) {
}
func Benchmark_Redis_SetAndDelete(b *testing.B) {
testStore := New(Config{
Reset: true,
})
b.ReportAllocs()
b.ResetTimer()

View File

@@ -4,7 +4,7 @@ go 1.20
require (
github.com/gofiber/utils/v2 v2.0.0-beta.3
github.com/redis/rueidis v1.0.20
github.com/redis/rueidis v1.0.21
github.com/stretchr/testify v1.8.4
)

View File

@@ -10,8 +10,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/onsi/gomega v1.28.0 h1:i2rg/p9n/UqIDAMFUJ6qIUUMcsqOuUHgbpbu235Vr1c=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/redis/rueidis v1.0.20 h1:OVEVkQBgNV5t7BC2YKXD2rd+BxuD4ExboyHKayiRgsI=
github.com/redis/rueidis v1.0.20/go.mod h1:8EOzvsg3o5dUDitRj4vpsolUKkSIvFz88PeQnqwTVk0=
github.com/redis/rueidis v1.0.21 h1:5vd5672hdNLQ7vaHygiZWZVhSrQ239PepuX9lkgAano=
github.com/redis/rueidis v1.0.21/go.mod h1:8EOzvsg3o5dUDitRj4vpsolUKkSIvFz88PeQnqwTVk0=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=

View File

@@ -3,29 +3,29 @@ module github.com/gofiber/storage/s3/v2
go 1.19
require (
github.com/aws/aws-sdk-go-v2 v1.21.2
github.com/aws/aws-sdk-go-v2/config v1.19.0
github.com/aws/aws-sdk-go-v2/credentials v1.13.43
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.11.91
github.com/aws/aws-sdk-go-v2/service/s3 v1.40.2
github.com/aws/aws-sdk-go-v2 v1.22.1
github.com/aws/aws-sdk-go-v2/config v1.22.0
github.com/aws/aws-sdk-go-v2/credentials v1.15.1
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.13.1
github.com/aws/aws-sdk-go-v2/service/s3 v1.42.0
github.com/stretchr/testify v1.8.4
)
require (
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.14 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.1.6 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.15 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.38 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.15.6 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 // indirect
github.com/aws/smithy-go v1.15.0 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.5.0 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.2 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.1 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.1 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.5.0 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.2.1 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.10.0 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.2.1 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.10.1 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.16.1 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.17.0 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.19.0 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.25.0 // indirect
github.com/aws/smithy-go v1.16.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect

View File

@@ -1,46 +1,45 @@
github.com/aws/aws-sdk-go-v2 v1.21.2 h1:+LXZ0sgo8quN9UOKXXzAWRT3FWd4NxeXWOZom9pE7GA=
github.com/aws/aws-sdk-go-v2 v1.21.2/go.mod h1:ErQhvNuEMhJjweavOYhxVkn2RUx7kQXVATHrjKtxIpM=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.14 h1:Sc82v7tDQ/vdU1WtuSyzZ1I7y/68j//HJ6uozND1IDs=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.14/go.mod h1:9NCTOURS8OpxvoAVHq79LK81/zC78hfRWFn+aL0SPcY=
github.com/aws/aws-sdk-go-v2/config v1.19.0 h1:AdzDvwH6dWuVARCl3RTLGRc4Ogy+N7yLFxVxXe1ClQ0=
github.com/aws/aws-sdk-go-v2/config v1.19.0/go.mod h1:ZwDUgFnQgsazQTnWfeLWk5GjeqTQTL8lMkoE1UXzxdE=
github.com/aws/aws-sdk-go-v2/credentials v1.13.43 h1:LU8vo40zBlo3R7bAvBVy/ku4nxGEyZe9N8MqAeFTzF8=
github.com/aws/aws-sdk-go-v2/credentials v1.13.43/go.mod h1:zWJBz1Yf1ZtX5NGax9ZdNjhhI4rgjfgsyk6vTY1yfVg=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13 h1:PIktER+hwIG286DqXyvVENjgLTAwGgoeriLDD5C+YlQ=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.13/go.mod h1:f/Ib/qYjhV2/qdsf79H3QP/eRE4AkVyEf6sk7XfZ1tg=
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.11.91 h1:haAyxKHwoE+y/TJt+qHcPQf1dCViyyGbWcKjjYUllTE=
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.11.91/go.mod h1:ACQ6ta5YFlfSOz2c9A+EVYawLxFMZ0rI3Q0A0tGieKo=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43 h1:nFBQlGtkbPzp/NjZLuFxRqmT91rLJkgvsEQs68h962Y=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.43/go.mod h1:auo+PiyLl0n1l8A0e8RIeR8tOzYPfZZH/JNlrJ8igTQ=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37 h1:JRVhO25+r3ar2mKGP7E0LDl8K9/G36gjlqca5iQbaqc=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.37/go.mod h1:Qe+2KtKml+FEsQF/DHmDV+xjtche/hwoF75EG4UlHW8=
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45 h1:hze8YsjSh8Wl1rYa1CJpRmXP21BvOBuc76YhW0HsuQ4=
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.45/go.mod h1:lD5M20o09/LCuQ2mE62Mb/iSdSlCNuj6H5ci7tW7OsE=
github.com/aws/aws-sdk-go-v2/internal/v4a v1.1.6 h1:wmGLw2i8ZTlHLw7a9ULGfQbuccw8uIiNr6sol5bFzc8=
github.com/aws/aws-sdk-go-v2/internal/v4a v1.1.6/go.mod h1:Q0Hq2X/NuL7z8b1Dww8rmOFl+jzusKEcyvkKspwdpyc=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.15 h1:7R8uRYyXzdD71KWVCL78lJZltah6VVznXBazvKjfH58=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.15/go.mod h1:26SQUPcTNgV1Tapwdt4a1rOsYRsnBsJHLMPoxK2b0d8=
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.38 h1:skaFGzv+3kA+v2BPKhuekeb1Hbb105+44r8ASC+q5SE=
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.38/go.mod h1:epIZoRSSbRIwLPJU5F+OldHhwZPBdpDeQkRdCeY3+00=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37 h1:WWZA/I2K4ptBS1kg0kV1JbBtG/umed0vwHRrmcr9z7k=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.37/go.mod h1:vBmDnwWXWxNPFRMmG2m/3MKOe+xEcMDo1tanpaWCcck=
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.15.6 h1:9ulSU5ClouoPIYhDQdg9tpl83d5Yb91PXTKK+17q+ow=
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.15.6/go.mod h1:lnc2taBsR9nTlz9meD+lhFZZ9EWY712QHrRflWpTcOA=
github.com/aws/aws-sdk-go-v2/service/s3 v1.40.2 h1:Ll5/YVCOzRB+gxPqs2uD0R7/MyATC0w85626glSKmp4=
github.com/aws/aws-sdk-go-v2/service/s3 v1.40.2/go.mod h1:Zjfqt7KhQK+PO1bbOsFNzKgaq7TcxzmEoDWN8lM0qzQ=
github.com/aws/aws-sdk-go-v2/service/sso v1.15.2 h1:JuPGc7IkOP4AaqcZSIcyqLpFSqBWK32rM9+a1g6u73k=
github.com/aws/aws-sdk-go-v2/service/sso v1.15.2/go.mod h1:gsL4keucRCgW+xA85ALBpRFfdSLH4kHOVSnLMSuBECo=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3 h1:HFiiRkf1SdaAmV3/BHOFZ9DjFynPHj8G/UIO1lQS+fk=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.17.3/go.mod h1:a7bHA82fyUXOm+ZSWKU6PIoBxrjSprdLoM8xPYvzYVg=
github.com/aws/aws-sdk-go-v2/service/sts v1.23.2 h1:0BkLfgeDjfZnZ+MhB3ONb01u9pwFYTCZVhlsSSBvlbU=
github.com/aws/aws-sdk-go-v2/service/sts v1.23.2/go.mod h1:Eows6e1uQEsc4ZaHANmsPRzAKcVDrcmjjWiih2+HUUQ=
github.com/aws/smithy-go v1.15.0 h1:PS/durmlzvAFpQHDs4wi4sNNP9ExsqZh6IlfdHXgKK8=
github.com/aws/smithy-go v1.15.0/go.mod h1:Tg+OJXh4MB2R/uN61Ko2f6hTZwB/ZYGOtib8J3gBHzA=
github.com/aws/aws-sdk-go-v2 v1.22.1 h1:sjnni/AuoTXxHitsIdT0FwmqUuNUuHtufcVDErVFT9U=
github.com/aws/aws-sdk-go-v2 v1.22.1/go.mod h1:Kd0OJtkW3Q0M0lUWGszapWjEvrXDzRW+D21JNsroB+c=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.5.0 h1:hHgLiIrTRtddC0AKcJr5s7i/hLgcpTt+q/FKxf1Zayk=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.5.0/go.mod h1:w4I/v3NOWgD+qvs1NPEwhd++1h3XPHFaVxasfY6HlYQ=
github.com/aws/aws-sdk-go-v2/config v1.22.0 h1:9Mm99OalzZRz0ab5fpodMoHBApHS6pqRNp3M9NmzvDg=
github.com/aws/aws-sdk-go-v2/config v1.22.0/go.mod h1:2eWgw5lps8fKI7LZVTrRTYP6HE6k/uEFUuTSHfXwqP0=
github.com/aws/aws-sdk-go-v2/credentials v1.15.1 h1:hmf6lAm9hk7uLCfapZn/jL05lm6Uwdbn1B0fgjyuf4M=
github.com/aws/aws-sdk-go-v2/credentials v1.15.1/go.mod h1:QTcHga3ZbQOneJuxmGBOCxiClxmp+TlvmjFexAnJ790=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.2 h1:gIeH4+o1MN/caGBWjoGQTUTIu94xD6fI5B2+TcwBf70=
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.14.2/go.mod h1:wLyMIo/zPOhQhPXTddpfdkSleyigtFi8iMnC+2m/SK4=
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.13.1 h1:ULswbgGNVrW8zEhkCNwrwXrs1mUvy2JTqWaCRsD2ZZw=
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.13.1/go.mod h1:pAXgsDPk1rRwwfkz8/9ISO75vXEHqTGIgbLhGqqQ1GY=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.1 h1:fi1ga6WysOyYb5PAf3Exd6B5GiSNpnZim4h1rhlBqx0=
github.com/aws/aws-sdk-go-v2/internal/configsources v1.2.1/go.mod h1:V5CY8wNurvPUibTi9mwqUqpiFZ5LnioKWIFUDtIzdI8=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.1 h1:ZpaV/j48RlPc4AmOZuPv22pJliXjXq8/reL63YzyFnw=
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.5.1/go.mod h1:R8aXraabD2e3qv1csxM14/X9WF4wFMIY0kH4YEtYD5M=
github.com/aws/aws-sdk-go-v2/internal/ini v1.5.0 h1:DqOQvIfmGkXZUVJnl9VRk0AnxyS59tCtX9k1Pyss4Ak=
github.com/aws/aws-sdk-go-v2/internal/ini v1.5.0/go.mod h1:VV/Kbw9Mg1GWJOT9WK+oTL3cWZiXtapnNvDSRqTZLsg=
github.com/aws/aws-sdk-go-v2/internal/v4a v1.2.1 h1:vzYLDkwTw4CY0vUk84MeSufRf8XIsC/GsoIFXD60sTg=
github.com/aws/aws-sdk-go-v2/internal/v4a v1.2.1/go.mod h1:ToBFBnjeGR2ruMx8IWp/y7vSK3Irj5/oPwifruiqoOM=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.10.0 h1:CJxo7ZBbaIzmXfV3hjcx36n9V87gJsIUPJflwqEHl3Q=
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.10.0/go.mod h1:yjVfjuY4nD1EW9i387Kau+I6V5cBA5YnC/mWNopjZrI=
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.2.1 h1:15FUCJzAP9Y25nioTqTrGlZmhOtthaXBWlt4pS+d3Xo=
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.2.1/go.mod h1:5655NW53Un6l7JzkI6AA3rZvf0m532cSnLThA1fVXcA=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.10.1 h1:2OXw3ppu1XsB6rqKEMV4tnecTjIY3PRV2U6IP6KPJQo=
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.10.1/go.mod h1:FZB4AdakIqW/yERVdGJA6Z9jraax1beXfhBBnK2wwR8=
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.16.1 h1:dnl0klXYX9EKpzZbWlH5LJL+YTcEZcJEMPFFr/rAHUQ=
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.16.1/go.mod h1:Mfk/9Joso4tCQYzM4q4HRUIqwln8lnIIMB/OE8Zebdc=
github.com/aws/aws-sdk-go-v2/service/s3 v1.42.0 h1:u0YoSrxjr3Lm+IqIlRAV+4YTFwkXjyB9db9CfUFge2w=
github.com/aws/aws-sdk-go-v2/service/s3 v1.42.0/go.mod h1:98EIdRu+BNsdqITsXfy+57TZfwlUQC9aDn9a9qoo90U=
github.com/aws/aws-sdk-go-v2/service/sso v1.17.0 h1:I/Oh3IxGPfHXiGnwM54TD6hNr/8TlUrBXAtTyGhR+zw=
github.com/aws/aws-sdk-go-v2/service/sso v1.17.0/go.mod h1:H6NCMvDBqA+CvIaXzaSqM6LWtzv9BzZrqBOqz+PzRF8=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.19.0 h1:irbXQkfVYIRaewYSXcu4yVk0m2T+JzZd0dkop7FjmO0=
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.19.0/go.mod h1:4wPNCkM22+oRe71oydP66K50ojDUC33XutSMi2pEF/M=
github.com/aws/aws-sdk-go-v2/service/sts v1.25.0 h1:sYIFy8tm1xQwRvVQ4CRuBGXKIg9sHNuG6+3UAQuoujk=
github.com/aws/aws-sdk-go-v2/service/sts v1.25.0/go.mod h1:S/LOQUeYDfJeJpFCIJDMjy7dwL4aA33HUdVi+i7uH8k=
github.com/aws/smithy-go v1.16.0 h1:gJZEH/Fqh+RsvlJ1Zt4tVAtV6bKkp3cC+R6FCZMNzik=
github.com/aws/smithy-go v1.16.0/go.mod h1:NukqUGpCZIILqqiV0NIjeFh24kd/FAa4beRb6nbIUPE=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=

183
scylladb/README.md Normal file
View File

@@ -0,0 +1,183 @@
---
id: scylladb
title: ScyllaDb
---
![Release](https://img.shields.io/github/v/tag/gofiber/storage?filter=scylladb*)
[![Discord](https://img.shields.io/discord/704680098577514527?style=flat&label=%F0%9F%92%AC%20discord&color=00ACD7)](https://gofiber.io/discord)
![Test](https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-scylladb.yml?label=Tests)
![Security](https://img.shields.io/github/actions/workflow/status/gofiber/storage/gosec.yml?label=Security)
![Linter](https://img.shields.io/github/actions/workflow/status/gofiber/storage/linter.yml?label=Linter)
# ScyllaDb
A ScyllaDb storage engine for [Fiber](github.com/gofiber/fiber) using [gocql](github.com/scylladb/gocql).
### Table of Contents
- [Signatures](#signatures)
- [Installation](#installation)
- [Examples](#examples)
- [Config](#config)
- [Default Config](#default-config)
### Signatures
```go
func New(config ...Config) Storage
func (s *Storage) Get(key string) ([]byte, error)
func (s *Storage) Set(key string, value []byte, expire time.Duration) error
func (s *Storage) Delete(key string) error
func (s *Storage) Reset() error
func (s *Storage) Close() error
func (s *Storage) Conn() *gocql.Session
```
### Installation
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:
```bash
go mod init github.com/<user>/<repo>
```
And then install the scylladb implementation:
```bash
go get github.com/gofiber/storage/scylladb
```
### Examples
Import the storage package.
```go
import "github.com/gofiber/storage/scylladb"
```
You can use the following possibilities to create a storage:
```go
// Initialize default config
store := scylladb.New()
// Initialize custom config
store := scylladb.New(scylladb.Config{
Keyspace: "fiber",
Hosts: []string{"127.0.0.1"},
Port: 9042,
Table: "fiber_storage",
Consistency: "ONE",
Reset: false,
})
// Initialize with support for TLS (SslOptions configures TLS use)
//
// InsecureSkipVerify and EnableHostVerification interact as follows:
//
// |Config.InsecureSkipVerify | EnableHostVerification | Result |
// |--------------------------|------------------------|--------------------|
// |Config is nil | false | do not verify host |
// |Config is nil | true | verify host |
// |false | false | verify host |
// |true | false | do not verify host |
// |false | true | verify host |
// |true | true | verify host |
store := New(
Config{
Keyspace: "fiber",
Hosts: []string{"127.0.0.1"},
Port: 9042,
Table: "fiber_storage",
Consistency: "ONE",
SslOpts: &gocql.SslOptions{
Config: &tls.Config{
InsecureSkipVerify: false, // Set this too false to enable certificate verification
},
CertPath: "/path/to/client_cert.pem", // Path to the client certificate
KeyPath: "/path/to/client_key.pem", // Path to the client certificate's private key
CaPath: "/path/to/ca_cert.pem", // Path to the CA certificate
EnableHostVerification: true, // Enable hostname verification
},
Reset: false,
},
)
// Initialize custom config using scylladb connection
cluster, _ := gocql.NewCluster("127.0.0.1")
cluster.Keyspace = "fiber"
cluster.Port = 9042
session, _ := cluster.CreateSession()
store := scylladb.New(scylladb.Config{
Session: session,
Keyspace: "fiber",
Table: "fiber_storage",
Reset: false,
})
```
### Config
```go
type Config struct {
// Session is provided by the user to use an existing ScyllaDb session
// Session Will override Keyspace and all other authentication values if used
//
// Optional. Default is nil
Session *gocql.Session
// Keyspace name
//
// Optional. Default is "fiber"
Keyspace string
// Hosts are an array of network addresses for establishing initial connections
// You have the flexibility to specify one or multiple addresses as needed
//
// Optional. Default is "127.0.0.1"
Hosts []string
// Port where the ScyllaDb cluster is listening on
//
// Optional. Default is 9042
Port int
// Username for ScyllaDb cluster
//
// Optional. Default is ""
Username string
// Password for ScyllaDb cluster
//
// Optional. Default is ""
Password string
// Table name
//
// Optional. Default is "fiber_storage"
Table string
// Level of the consistency
//
// Optional. Default is "LOCAL_ONE"
Consistency string
// SslOpts configures TLS use.
//
// Optional. Default is nil
SslOpts *gocql.SslOptions
// Reset clears any existing keys in existing Table
//
// Optional. Default is false
Reset bool
}
```
### Default Config
```go
// ConfigDefault is the default config
var ConfigDefault = Config{
Session: nil,
Keyspace: "fiber",
Hosts: []string{"127.0.0.1"},
Username: "",
Password: "",
Port: 9042,
Table: "fiber_storage",
Consistency: "LOCAL_ONE",
SslOpts: nil,
Reset: false,
}
```

102
scylladb/config.go Normal file
View File

@@ -0,0 +1,102 @@
package scylladb
import (
"github.com/gocql/gocql"
"strings"
)
type Config struct {
// Session is provided by the user to use an existing ScyllaDb session
//
// Optional. Default is nil
Session *gocql.Session
// Keyspace name
//
// Optional. Default is "fiber"
Keyspace string
// Hosts are an array of network addresses for establishing initial connections.
// You have the flexibility to specify one or multiple addresses as needed.
//
// Optional. Default is "127.0.0.1"
Hosts []string
// Port where the ScyllaDb cluster is listening on
//
// Optional. Default is 9042
Port int
// Username for ScyllaDb cluster
//
// Optional. Default is ""
Username string
// Password for ScyllaDb cluster
//
// Optional. Default is ""
Password string
// Table name
//
// Optional. Default is "fiber_storage"
Table string
// Level of the consistency
//
// Optional. Default is "LOCAL_ONE"
Consistency string
// SslOpts configures TLS use.
//
// Optional. Default is nil
SslOpts *gocql.SslOptions
// Reset clears any existing keys in existing Table
//
// Optional. Default is false
Reset bool
}
// ConfigDefault is the default config
var ConfigDefault = Config{
Session: nil,
Keyspace: "fiber",
Hosts: []string{"127.0.0.1"},
Username: "",
Password: "",
Port: 9042,
Table: "fiber_storage",
Consistency: "LOCAL_ONE",
SslOpts: nil,
Reset: false,
}
// configDefault helps to set a default config
func configDefault(config ...Config) Config {
// Return default config if nothing provided
if len(config) < 1 {
return ConfigDefault
}
// Override default config
cfg := config[0]
// Set default values
if cfg.Hosts == nil {
cfg.Hosts = ConfigDefault.Hosts
}
if cfg.Port <= 0 {
cfg.Port = ConfigDefault.Port
}
if len(strings.TrimSpace(cfg.Table)) == 0 {
cfg.Table = ConfigDefault.Table
}
if len(strings.TrimSpace(cfg.Keyspace)) == 0 {
cfg.Keyspace = ConfigDefault.Keyspace
}
if len(strings.TrimSpace(cfg.Consistency)) == 0 {
cfg.Consistency = ConfigDefault.Consistency
}
return cfg
}

19
scylladb/go.mod Normal file
View File

@@ -0,0 +1,19 @@
module github.com/gofiber/storage/scylladb
go 1.20
require (
github.com/gocql/gocql v1.6.0
github.com/stretchr/testify v1.8.4
)
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
replace github.com/gocql/gocql => github.com/scylladb/gocql v1.11.1

45
scylladb/go.sum Normal file
View File

@@ -0,0 +1,45 @@
github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932 h1:mXoPYz/Ul5HYEDvkta6I8/rnYM5gSdSV2tJ6XbZuEtY=
github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932/go.mod h1:NOuUCSz6Q9T7+igc/hlvDOUdtWKryOrtFyIVABv/p7k=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed h1:5upAirOpQc1Q53c0bnx2ufif5kANL7bfZWcc6VJWJd8=
github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed/go.mod h1:tMWxXQ9wFIaZeTI9F+hmhFiGpFmhOHzyShyFUhRm0H4=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/scylladb/gocql v1.11.1 h1:AlIPHHZf2l0Cbj8wGjfELspaGfnd4meGj9sPQnr5dn8=
github.com/scylladb/gocql v1.11.1/go.mod h1:ZLEJ0EVE5JhmtxIW2stgHq/v1P4fWap0qyyXSKyV8K0=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
golang.org/x/net v0.0.0-20220526153639-5463443f8c37 h1:lUkvobShwKsOesNfWWlCS5q7fnbG1MEliIzwu886fn8=
golang.org/x/net v0.0.0-20220526153639-5463443f8c37/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=
sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8=

175
scylladb/scylladb.go Normal file
View File

@@ -0,0 +1,175 @@
package scylladb
import (
"errors"
"fmt"
"github.com/gocql/gocql"
"strings"
"time"
)
// Storage interface that is implemented by storage providers
type Storage struct {
session *gocql.Session
tableName string
selectQuery string
insertQuery string
deleteQuery string
resetQuery string
}
var (
checkSchemaErrorMsg = errors.New("the `value` row has an incorrect data type. " +
"The message should be BLOB, but it is instead %s. This could lead to encoding-related issues if the database is not migrated (refer to https://github.com/gofiber/storage/blob/main/MIGRATE.md)")
keyspaceErrorMsg = errors.New(`keyspace cannot be empty`)
createKeyspaceQuery = `CREATE KEYSPACE IF NOT EXISTS %s WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1};`
dropQuery = `DROP TABLE IF EXISTS %s.%s;`
createTableQuery = `CREATE TABLE IF NOT EXISTS %s.%s (key TEXT PRIMARY KEY, value BLOB)`
checkSchemaQuery = `SELECT type FROM system_schema.columns WHERE keyspace_name = '%s' AND table_name = '%s' AND column_name = 'value';`
selectQuery = `SELECT value FROM %s.%s WHERE key = ?`
insertQuery = `INSERT INTO %s.%s (key, value) VALUES (?, ?) USING TTL ?`
deleteQuery = `DELETE FROM %s.%s WHERE key = ?`
resetQuery = `TRUNCATE %s.%s`
)
// New creates a new storage
func New(config ...Config) *Storage {
var err error
var session *gocql.Session
// Set default config
cfg := configDefault(config...)
if len(strings.TrimSpace(cfg.Keyspace)) == 0 {
panic(keyspaceErrorMsg)
}
if cfg.Session == nil {
// Create a new cluster
cluster := gocql.NewCluster(cfg.Hosts...)
cluster.Consistency = gocql.ParseConsistency(cfg.Consistency)
cluster.Port = cfg.Port
// Set credentials if provided
if len(strings.TrimSpace(cfg.Username)) > 0 && len(strings.TrimSpace(cfg.Password)) > 0 {
cluster.Authenticator = gocql.PasswordAuthenticator{
Username: cfg.Username,
Password: cfg.Password,
}
}
// Set cfg.SslOpts if provided.
if cfg.SslOpts != nil {
cluster.SslOpts = cfg.SslOpts
}
// Create session
session, err = cluster.CreateSession()
if err != nil {
panic(err)
}
} else {
// Set session if provided
session = cfg.Session
}
// Create keyspace if it does not exist
if err = session.Query(fmt.Sprintf(createKeyspaceQuery, cfg.Keyspace)).Exec(); err != nil {
session.Close()
panic(err)
}
// Drop table if reset is true
if cfg.Reset {
if err = session.Query(fmt.Sprintf(dropQuery, cfg.Keyspace, cfg.Table)).Exec(); err != nil {
session.Close()
panic(err)
}
}
// Create the storage
store := &Storage{
session: session,
tableName: cfg.Table,
selectQuery: fmt.Sprintf(selectQuery, cfg.Keyspace, cfg.Table),
insertQuery: fmt.Sprintf(insertQuery, cfg.Keyspace, cfg.Table),
deleteQuery: fmt.Sprintf(deleteQuery, cfg.Keyspace, cfg.Table),
resetQuery: fmt.Sprintf(resetQuery, cfg.Keyspace, cfg.Table),
}
// Create table if not exists
if err = store.createTableIfNotExists(cfg.Keyspace); err != nil {
session.Close()
panic(err)
}
// Check schema
store.checkSchema(cfg.Keyspace)
return store // Return storage
}
func (s *Storage) createTableIfNotExists(keyspace string) error {
// Create table if not exists
query := fmt.Sprintf(createTableQuery, keyspace, s.tableName)
if err := s.session.Query(query).Exec(); err != nil {
return err
}
return nil
}
func (s *Storage) checkSchema(keyspace string) {
// Check schema for value column type (should be blob)
var dataType string
query := fmt.Sprintf(checkSchemaQuery, keyspace, s.tableName)
if err := s.session.Query(query).Scan(&dataType); err != nil {
panic(err)
}
if dataType != "blob" {
panic(fmt.Errorf(checkSchemaErrorMsg.Error(), dataType))
}
}
// Get retrieves a value by key
func (s *Storage) Get(key string) ([]byte, error) {
var value []byte
if err := s.session.Query(s.selectQuery, key).Scan(&value); err != nil {
if errors.Is(err, gocql.ErrNotFound) {
return nil, nil
}
return nil, err
}
return value, nil
}
// Set sets a value by key
func (s *Storage) Set(key string, value []byte, expire time.Duration) error {
var expiration int
if expire != 0 {
expiration = int(expire.Round(time.Second).Seconds())
}
return s.session.Query(s.insertQuery, key, value, expiration).Exec()
}
// Delete removes a value by key
func (s *Storage) Delete(key string) error {
return s.session.Query(s.deleteQuery, key).Exec()
}
// Reset resets all values
func (s *Storage) Reset() error {
return s.session.Query(s.resetQuery).Exec()
}
// Close closes the storage
func (s *Storage) Close() error {
s.session.Close()
return nil
}
// Conn returns the underlying gocql session
func (s *Storage) Conn() *gocql.Session {
return s.session
}

164
scylladb/scylladb_test.go Normal file
View File

@@ -0,0 +1,164 @@
package scylladb
import (
"github.com/stretchr/testify/require"
"testing"
"time"
)
var testStore = New(Config{Reset: true})
func Test_Scylla_Set(t *testing.T) {
// Create a new instance of the Storage
var (
key = "john"
value = []byte("doe")
)
err := testStore.Set(key, value, 0)
require.NoError(t, err)
}
func Test_Scylla_Set_Override_Get(t *testing.T) {
var (
key = "john"
valInitial = []byte("doe")
valOverride = []byte("doe2")
)
err := testStore.Set(key, valInitial, 0)
require.NoError(t, err)
result, err := testStore.Get(key)
require.NoError(t, err)
require.Equal(t, valInitial, result)
err = testStore.Set(key, valOverride, 0)
require.NoError(t, err)
result, err = testStore.Get(key)
require.NoError(t, err)
require.Equal(t, valOverride, result)
}
func Test_Scylla_Get(t *testing.T) {
var (
key = "john"
val = []byte("doe")
)
err := testStore.Set(key, val, 0)
require.NoError(t, err)
result, err := testStore.Get(key)
require.NoError(t, err)
require.Equal(t, val, result)
}
func Test_Scylla_Set_Expiration_Get(t *testing.T) {
var (
key = "john"
val = []byte("doe")
exp = 1 * time.Second
)
err := testStore.Set(key, val, exp)
require.NoError(t, err)
time.Sleep(1001 * time.Millisecond)
result, err := testStore.Get(key)
require.NoError(t, err)
require.Empty(t, result)
}
func Test_Scylla_Get_NotExist(t *testing.T) {
result, err := testStore.Get("not-exist")
require.NoError(t, err)
require.Zero(t, len(result))
}
func Test_Scylla_Delete(t *testing.T) {
var (
key = "john"
val = []byte("doe")
)
err := testStore.Set(key, val, 0)
require.NoError(t, err)
err = testStore.Delete(key)
require.NoError(t, err)
result, err := testStore.Get(key)
require.NoError(t, err)
require.Zero(t, len(result))
}
func Test_Scylla_Reset(t *testing.T) {
var val = []byte("doe")
err := testStore.Set("john1", val, 0)
require.NoError(t, err)
err = testStore.Set("john2", val, 0)
require.NoError(t, err)
err = testStore.Reset()
require.NoError(t, err)
result, err := testStore.Get("john1")
require.NoError(t, err)
require.Zero(t, len(result))
result, err = testStore.Get("john2")
require.NoError(t, err)
require.Zero(t, len(result))
}
func Test_Scylla_Close(t *testing.T) {
require.Nil(t, testStore.Close())
}
func Test_Scylla_Conn(t *testing.T) {
require.True(t, testStore.Conn() != nil)
}
func Benchmark_Scylla_Set(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
var err error
for i := 0; i < b.N; i++ {
err = testStore.Set("john", []byte("doe"), 0)
}
require.NoError(b, err)
}
func Benchmark_Scylla_Get(b *testing.B) {
err := testStore.Set("john", []byte("doe"), 0)
require.NoError(b, err)
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err = testStore.Get("john")
}
require.NoError(b, err)
}
func Benchmark_Scylla_SetAndDelete(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()
var err error
for i := 0; i < b.N; i++ {
_ = testStore.Set("john", []byte("doe"), 0)
err = testStore.Delete("john")
}
require.NoError(b, err)
}