Files
storage/scylladb/README.md
René 9f8091caff
Some checks failed
Release Drafter (All) / changes (push) Has been cancelled
Sync docs / sync-docs (push) Has been cancelled
Tests ArangoDB / Tests (1.19.x) (push) Has been cancelled
Tests ArangoDB / Tests (1.20.x) (push) Has been cancelled
Tests ArangoDB / Tests (1.21.x) (push) Has been cancelled
Tests Azure Blob / Tests (1.19.x) (push) Has been cancelled
Tests Azure Blob / Tests (1.20.x) (push) Has been cancelled
Tests Azure Blob / Tests (1.21.x) (push) Has been cancelled
Tests Badger / Tests (1.19.x) (push) Has been cancelled
Tests Badger / Tests (1.20.x) (push) Has been cancelled
Tests Badger / Tests (1.21.x) (push) Has been cancelled
Tests Bbolt / Tests (1.19.x) (push) Has been cancelled
Tests Bbolt / Tests (1.20.x) (push) Has been cancelled
Tests Bbolt / Tests (1.21.x) (push) Has been cancelled
Tests Clickhouse / Tests (1.22.x) (push) Has been cancelled
Tests Clickhouse / Tests (1.23.x) (push) Has been cancelled
Tests Clickhouse / Tests (1.24.x) (push) Has been cancelled
Tests CloudflareKV / Tests (1.21.x) (push) Has been cancelled
Tests CloudflareKV / Tests (1.22.x) (push) Has been cancelled
Tests Coherence / Tests (1.19.x) (push) Has been cancelled
Tests Coherence / Tests (1.20.x) (push) Has been cancelled
Tests Coherence / Tests (1.21.x) (push) Has been cancelled
Tests Coherence / Tests (1.22.x) (push) Has been cancelled
Tests Couchbase / Tests (1.22.x) (push) Has been cancelled
Tests Couchbase / Tests (1.23.x) (push) Has been cancelled
Tests Couchbase / Tests (1.24.x) (push) Has been cancelled
Tests DynamoDB / Tests (1.22.x) (push) Has been cancelled
Tests DynamoDB / Tests (1.23.x) (push) Has been cancelled
Tests DynamoDB / Tests (1.24.x) (push) Has been cancelled
Tests Etcd / Tests (1.19.x) (push) Has been cancelled
Tests Etcd / Tests (1.20.x) (push) Has been cancelled
Tests Etcd / Tests (1.21.x) (push) Has been cancelled
Tests LevelDB / Tests (1.23.x) (push) Has been cancelled
Tests LevelDB / Tests (1.24.x) (push) Has been cancelled
Tests Memcache / Tests (1.19.x) (push) Has been cancelled
Tests Memcache / Tests (1.20.x) (push) Has been cancelled
Tests Memcache / Tests (1.21.x) (push) Has been cancelled
Tests Local Storage / Tests (1.19.x) (push) Has been cancelled
Tests Local Storage / Tests (1.20.x) (push) Has been cancelled
Tests Local Storage / Tests (1.21.x) (push) Has been cancelled
Tests Minio / Tests (1.22.x) (push) Has been cancelled
Tests Minio / Tests (1.23.x) (push) Has been cancelled
Tests Minio / Tests (1.24.x) (push) Has been cancelled
Tests Local Storage / Tests (1.22.x) (push) Has been cancelled
Tests Mongodb / Tests (1.22.x) (push) Has been cancelled
Tests Mongodb / Tests (1.23.x) (push) Has been cancelled
Tests Mongodb / Tests (1.24.x) (push) Has been cancelled
Tests MSSQL / Tests (1.19.x) (push) Has been cancelled
Tests MSSQL / Tests (1.20.x) (push) Has been cancelled
Tests MSSQL / Tests (1.21.x) (push) Has been cancelled
Tests MySQL / Tests (1.22.x) (push) Has been cancelled
Tests MySQL / Tests (1.23.x) (push) Has been cancelled
Tests MySQL / Tests (1.24.x) (push) Has been cancelled
Tests Nats Driver / Tests (1.22.x) (push) Has been cancelled
Tests Nats Driver / Tests (1.23.x) (push) Has been cancelled
Tests Nats Driver / Tests (1.24.x) (push) Has been cancelled
Tests Neo4j / Tests (1.23.x) (push) Has been cancelled
Tests pebble / Tests (1.19.x) (push) Has been cancelled
Tests pebble / Tests (1.20.x) (push) Has been cancelled
Tests pebble / Tests (1.21.x) (push) Has been cancelled
Tests Postgres / Tests (1.22.x) (push) Has been cancelled
Tests Postgres / Tests (1.23.x) (push) Has been cancelled
Tests Postgres / Tests (1.24.x) (push) Has been cancelled
Tests Redis / Tests (1.19.x, 6.x) (push) Has been cancelled
Tests Redis / Tests (1.19.x, 7.x) (push) Has been cancelled
Tests Redis / Tests (1.20.x, 6.x) (push) Has been cancelled
Tests Redis / Tests (1.20.x, 7.x) (push) Has been cancelled
Tests Redis / Tests (1.21.x, 6.x) (push) Has been cancelled
Tests Redis / Tests (1.21.x, 7.x) (push) Has been cancelled
Tests Ristretto / Tests (1.19.x) (push) Has been cancelled
Tests Ristretto / Tests (1.20.x) (push) Has been cancelled
Tests Ristretto / Tests (1.21.x) (push) Has been cancelled
Tests Rueidis / Tests (1.20.x, 6.x) (push) Has been cancelled
Tests Rueidis / Tests (1.20.x, 7.x) (push) Has been cancelled
Tests Rueidis / Tests (1.21.x, 6.x) (push) Has been cancelled
Tests Rueidis / Tests (1.21.x, 7.x) (push) Has been cancelled
Tests S3 / Tests (1.21.x) (push) Has been cancelled
Tests S3 / Tests (1.22.x) (push) Has been cancelled
Tests S3 / Tests (1.23.x) (push) Has been cancelled
Tests ScyllaDb / Tests (1.20.x) (push) Has been cancelled
Tests ScyllaDb / Tests (1.21.x) (push) Has been cancelled
Tests Sqlite3 / Tests (1.19.x) (push) Has been cancelled
Tests Sqlite3 / Tests (1.20.x) (push) Has been cancelled
Tests Sqlite3 / Tests (1.21.x) (push) Has been cancelled
Tests Valkey / Tests (1.23.x, 7.x) (push) Has been cancelled
Tests Valkey / Tests (1.23.x, 8.x) (push) Has been cancelled
Release Drafter (All) / release-drafter (push) Has been cancelled
Fix badges
2025-03-23 16:33:25 +01:00

5.3 KiB

id, title
id title
scylladb ScyllaDb

Release Discord Test

ScyllaDb

A ScyllaDb storage engine for Fiber using gocql.

Table of Contents

Signatures

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 with support for modules. So make sure to initialize one first if you didn't do that yet:

go mod init github.com/<user>/<repo>

And then install the scylladb implementation:

go get github.com/gofiber/storage/scylladb

Examples

Import the storage package.

import "github.com/gofiber/storage/scylladb"

You can use the following possibilities to create a storage:

// 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

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

// 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,
}