Skip to content

Commit

Permalink
Merge branch 'main' into objectbox_
Browse files Browse the repository at this point in the history
  • Loading branch information
gaby authored Jan 7, 2025
2 parents 4521a29 + 76c5211 commit 9dd5aa8
Show file tree
Hide file tree
Showing 11 changed files with 1,018 additions and 1 deletion.
50 changes: 50 additions & 0 deletions .github/release-drafter-valkey.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name-template: 'Valkey - v$RESOLVED_VERSION'
tag-template: 'valkey/v$RESOLVED_VERSION'
tag-prefix: valkey/v
include-paths:
- valkey
categories:
- title: '❗ Breaking Changes'
labels:
- '❗ BreakingChange'
- 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.
exclude-contributors:
- dependabot
- dependabot[bot]
version-resolver:
major:
labels:
- 'major'
- '❗ BreakingChange'
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...valkey/v$RESOLVED_VERSION
Thank you $CONTRIBUTORS for making this update possible.
3 changes: 2 additions & 1 deletion .github/scripts/gen-test-certs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ _END_
generate_cert server "Server-only" "-extfile ./tls/openssl.cnf -extensions server_cert"
generate_cert client "Client-only" "-extfile ./tls/openssl.cnf -extensions client_cert"
generate_cert redis "localhost" "-extfile ./tls/openssl.cnf -extensions server_cert"
generate_cert valkey "localhost" "-extfile ./tls/openssl.cnf -extensions server_cert"

# List generated certs
ls -la ./tls
echo "$PWD"
echo "$PWD"
19 changes: 19 additions & 0 deletions .github/workflows/release-drafter-valkey.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Release Drafter Valkey
on:
push:
# branches to consider in the event; optional, defaults to all
branches:
- master
- main
paths:
- 'valkey/**'
jobs:
draft_release_valkey:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: release-drafter/release-drafter@v6
with:
config-name: release-drafter-valkey.yml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
63 changes: 63 additions & 0 deletions .github/workflows/test-valkey.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
on:
push:
branches:
- master
- main
paths:
- 'valkey/**'
pull_request:
paths:
- 'valkey/**'
- '.github/workflows/test-valkey.yml'
name: "Tests Valkey"
jobs:
Tests:
runs-on: ubuntu-latest
strategy:
matrix:
go-version:
- 1.23.x
valkey:
- '7.x'
- '8.x'
steps:
- name: Fetch Repository
uses: actions/checkout@v4

- name: Generate TLS certs
run: ./.github/scripts/gen-test-certs.sh

- name: Setup Valkey
uses: shogo82148/actions-setup-redis@v1
with:
distribution: 'valkey'
redis-version: ${{ matrix.valkey }}
auto-start: 'false'
redis-port: '6379'
redis-tls-port: '6380'

- name: Run Valkey
run: |
valkey-server --tls-port 6380 --port 6379 \
--tls-cert-file /home/runner/work/storage/storage/tls/valkey.crt \
--tls-key-file /home/runner/work/storage/storage/tls/valkey.key \
--tls-ca-cert-file /home/runner/work/storage/storage/tls/ca.crt &
- name: Setup Valkey Cluster
uses: vishnudxb/[email protected]
with:
master1-port: 7000
master2-port: 7001
master3-port: 7002
slave1-port: 7003
slave2-port: 7004
slave3-port: 7005
sleep-duration: 10

- name: Install Go
uses: actions/setup-go@v5
with:
go-version: '${{ matrix.go-version }}'

- name: Run Test
run: cd ./valkey && go test ./... -v -race
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,4 @@ type Storage interface {
- [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>
- [ClickHouse](./clickhouse/README.md) <a href="https://github.com/gofiber/storage/actions?query=workflow%3A%22Tests+Clickhouse%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-clickhouse.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a>
- [Valkey](./valkey/README.md) <a href="https://github.com/gofiber/storage/actions?query=workflow%3A%22Tests+valkey%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-valkey.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a>
222 changes: 222 additions & 0 deletions valkey/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
---
id: valkey
title: Valkey
---

![Release](https://img.shields.io/github/v/tag/gofiber/storage?filter=valkey*)
[![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-valkey.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)

A fast Valkey Storage that does auto pipelining and supports client side caching. Implementation is based on [valkey-io/valkey](https://github.com/valkey-io/valkey-go).

### 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, val []byte, exp time.Duration) error
func (s *Storage) Delete(key string) error
func (s *Storage) Reset() error
func (s *Storage) Close() error
func (s *Storage) Conn() valkey.Client
```

### Installation

The valkey driver is tested on the latest two [Go version](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 valkey implementation:

```bash
go get github.com/gofiber/storage/valkey
```

### Examples

Import the storage package.

```go
import "github.com/gofiber/storage/valkey"
```

You can use the one of the following options to create a Valkey Storage:

```go
// Initialize default config (localhost:6379)
store := valkey.New()

// Initialize custom config
store := valkey.New(valkey.Config{
InitAddress: []string{"localhost:6380"},
Username: "",
Password: "",
Database: 0,
Reset: false,
TLSConfig: nil,
})

// Initialize using Redis-style URL
store := valkey.New(valkey.Config{
URL: "redis://localhost:6379",
})

// Initialize Valkey Cluster Client
store := valkey.New(valkey.Config{
InitAddress: []string{":6379", ":6380"},
})

// Create a client with support for TLS
cer, err := tls.LoadX509KeyPair("./client.crt", "./client.key")
if err != nil {
log.Println(err)
return
}
tlsCfg := &tls.Config{
MinVersion: tls.VersionTLS12,
InsecureSkipVerify: true,
Certificates: []tls.Certificate{cer},
}
store = valkey.New(valkey.Config{
InitAddress: []string{"localhost:6380"},
Username: "<user>",
Password: "<password>",
SelectDB: 0,
TLSConfig: tlsCfg,
})

```

### Config

```go
type Config struct {
// Server username
//
// Optional. Default is ""
Username string

// Server password
//
// Optional. Default is ""
Password string

// ClientName will execute the `CLIENT SETNAME ClientName` command for each conn.
//
// Optional. Default is ""
ClientName string

// URL standard format Redis-style URL. If this is set all other config options, InitAddress, Username, Password, ClientName, and SelectDB have no effect.
//
// Example: redis://<user>:<pass>@localhost:6379/<db>
// Optional. Default is ""
URL string

// SelectDB to be selected after connecting to the server.
//
// Optional. Default is 0
SelectDB int

// Either a single address or a seed list of host:port addresses, this enables FailoverClient and ClusterClient
//
// Optional. Default is []string{"127.0.0.1:6379"}
InitAddress []string

// TLS Config to use. When set TLS will be negotiated.
//
// Optional. Default is nil
TLSConfig *tls.Config

// CacheSizeEachConn is valkey client side cache size that bind to each TCP connection to a single valkey instance.
//
// Optional. The default is DefaultCacheBytes: 128 * (1 << 20)
CacheSizeEachConn int

// RingScaleEachConn sets the size of the ring buffer in each connection to (2 ^ RingScaleEachConn).
//
// Optional. The default is RingScaleEachConn, which results into having a ring of size 2^10 for each connection.
RingScaleEachConn int

// ReadBufferEachConn is the size of the bufio.NewReaderSize for each connection, default to DefaultReadBuffer (0.5 MiB).
//
// Optional. The default is DefaultReadBuffer: 1 << 19
ReadBufferEachConn int

// WriteBufferEachConn is the size of the bufio.NewWriterSize for each connection, default to DefaultWriteBuffer (0.5 MiB).
//
// Optional. The default is DefaultWriteBuffer: 1 << 19
WriteBufferEachConn int

// BlockingPoolSize is the size of the connection pool shared by blocking commands (ex BLPOP, XREAD with BLOCK).
//
// Optional. The default is DefaultPoolSize: 1000
BlockingPoolSize int

// PipelineMultiplex determines how many tcp connections used to pipeline commands to one valkey instance.
//
// Optional. The default for single and sentinel clients is 2, which means 4 connections (2^2).
PipelineMultiplex int

// DisableRetry disables retrying read-only commands under network errors
//
// Optional. The default is False
DisableRetry bool

// DisableCache falls back Client.DoCache/Client.DoMultiCache to Client.Do/Client.DoMulti
//
// Optional. The default is false
DisableCache bool

// AlwaysPipelining makes valkey.Client always pipeline valkey commands even if they are not issued concurrently.
//
// Optional. The default is true
AlwaysPipelining bool

// Reset clears any existing keys in existing Collection
//
// Optional. Default is false
Reset bool

// CacheTTL TTL
//
// Optional. Default is time.Minute
CacheTTL time.Duration
}
```

### Default Config

```go
var ConfigDefault = Config{
Username: "",
Password: "",
ClientName: "",
SelectDB: 0,
InitAddress: []string{"127.0.0.1:6379"},
TLSConfig: nil,
CacheSizeEachConn: valkey.DefaultCacheBytes,
RingScaleEachConn: valkey.DefaultRingScale,
ReadBufferEachConn: valkey.DefaultReadBuffer,
WriteBufferEachConn: valkey.DefaultWriteBuffer,
BlockingPoolSize: valkey.DefaultPoolSize,
PipelineMultiplex: 2,
DisableRetry: false,
DisableCache: false,
AlwaysPipelining: true,
Reset: false,
CacheTTL: time.Minute,
}
```
Loading

0 comments on commit 9dd5aa8

Please sign in to comment.