Go Fiber 한글 공식 문서
  • 🙇‍♀️안녕하세요
  • 🏠Home
    • 👋Welcome
    • 📁API
      • 📦Fiber
      • 🚀App
      • 🧠Ctx
      • 📋Constants
      • 🌎Client
      • 📃Log
      • 🧬Middleware
        • Adaptor
        • BasicAuth
        • Cache
        • Compress
        • CORS
        • CSRF
        • EarlyData
        • Encrypt Cookie
        • EnvVar
        • ETag
        • ExpVar
        • Favicon
        • FileSystem
        • Health Check
        • Helmet
        • Idempotency
        • Keyauth
        • Limiter
        • Logger
        • Monitor
        • Pprof
        • Proxy
        • Recover
        • Redirect
        • RequestID
        • Rewrite
        • Session
        • Skip
        • Timeout
    • 📁Guide
      • 🔌Routing
      • 🎭Grouping
      • 📝Templates
      • 🐛Error Handling
      • 🔎Validation
      • 🎣Hooks
      • ⚡Make Fiber Faster
    • 📁Extra
      • 🤔FAQ
      • 📊Benchmarks
  • 🧩Extra
    • 🧬Contrip
      • 👋Welcome
      • Casbin
      • Fgprof
      • Fiberi18n
      • Fibernewrelic
      • Fibersentry
      • Fiberzap
      • Fiberzerolog
      • JWT
      • LoadShed
      • Opafiber
      • Otelfiber
        • Example
      • Paseto
      • README
      • Swagger
      • Websocket
    • 📦Storage
      • 👋Welcome
      • ArangoDB
      • Azure Blob
      • Badger
      • Bbolt
      • Coherence
      • Couchbase
      • DynamoDB
      • Etcd
      • Memcache
      • Memory
      • Minio
      • MongoDB
      • MSSQL
      • MySQL
      • Nats
      • Pebble
      • Postgres
      • Redis
      • Ristretto
      • Rueidis
      • S3
      • ScyllaDb
      • SQLite3
    • 📃Template
      • 👋Welcome
      • Ace
      • Amber
      • Django
      • Handlebars
      • HTML
        • Golang Templates Cheatsheet
      • Jet
      • Mustache
      • Pug
      • Slim
Powered by GitBook
On this page
  • Table of Contents
  • Signatures
  • Installation
  • Examples
  • Config
  • Default Config
  1. Extra
  2. Storage

Coherence

PreviousBboltNextCouchbase

Last updated 1 year ago


를 사용하는 Coherence 스토리지 드라이버입니다.

Table of Contents

  • Signatures

  • Installation

  • Examples

  • Config

  • Default Config

Signatures

func New(config ...Config) (*Storage, error)
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() *Session

Installation

Coherence는 Go 버전 1.19 이상에서 지원됩니다:

coherence 구현을 설치합니다:

go get github.com/gofiber/storage/coherence

이 구현을 실행하거나 테스트하기 전에 Coherence 클러스터가 사용 가능한지 확인해야 합니다. 로컬 개발을 위해 Coherence CE Docker 이미지를 사용하는 것을 추천합니다; 클라이언트가 올바르게 작동하는 데 필요한 모든 것이 포함되어 있습니다.

Docker를 사용하여 Coherence 클러스터를 시작하려면 다음을 실행하세요:

docker run -d -p 1408:1408 ghcr.io/oracle/coherence-ce:22.06.7  

Examples

스토리지 패키지를 가져옵니다.

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

다음과 같은 방법으로 스토리지를 생성할 수 있습니다:

// 기본 config를 초기화하여 일반 텍스트를 사용하여 localhost:1408에 연결합니다
store, err := coherence.New()

// 사용자 정의 config를 초기화하여 다른 host/port에 연결하고 일반 텍스트 및 5분의 만료 시간을 사용합니다.  
store, err := coherence.New(coherence.Config{
    Address: "my-host:myport",
    Expiration: time.Duration(300) * time.Second, // 5분
})

// TLS를 사용하도록 설정하고 사용자 정의 tls.Config로 초기화합니다
tlsConfig := config := &tls.Config{...}

store, err := coherence.New(coherence.Config{
    Address: "my-host:myport", 
    TLSConfig: tlsConfig,
})

coherence.New()를 사용하여 두 개의 저장소를 만들면 사실상 동일합니다. 별도의 저장소를 사용하려면 다음과 같이 할 수 있습니다:

store1, err := coherence.New(Config{ScopeName: "scope1"}) 
store2, err := coherence.New(Config{ScopeName: "scope2"})

Near Caches

Coherence Go 클라이언트의 최신 버전은 네트워크를 통해 요청을 보내지 않고 Go 클라이언트에서 자주 액세스하는 데이터를 캐시하기 위한 Near Cache 지원을 도입했습니다.

이는 특히 LBR을 통해 스티키 세션을 사용하는 경우에 유용한데, 이는 Go 프로세스에 세션을 캐시하고 Get() 작업이 훨씬 더 빨라지기 때문입니다.

서버에서 세션이 만료되면 Near Cache에서 자동으로 제거됩니다.

세션에 이 기능을 사용하려면 NearCacheTimeout를 만료 시간보다 짧은 기간으로 설정할 수 있습니다.

// 기본 config를 초기화하여 일반 텍스트를 사용하여 localhost:1408에 연결합니다
store, err := coherence.New()

// 일반 텍스트를 사용하고 기본 만료 시간은 5분, Near Cache 만료 시간은 2분으로 설정합니다
store, err := coherence.New(coherence.Config{
    Address: "my-host:myport",
    Expiration: time.Duration(300) * time.Second,       // 5분
    NearCacheTimeout: time.Duration(120) * time.Second, // 2분 
})

Near Cache 시간 초과가 세션 시간 초과보다 작아야 합니다.

Config

// Config는 Coherence 연결에 대한 구성 옵션을 정의합니다.
type Config struct {
    // 연결할 주소, 기본값은 "localhost:1408"
    Address string

    // Timeout은 Coherence에 연결하기 위한 기본 세션 시간 초과이며, 기본값은 30초입니다
    Timeout time.Duration
	
    // ScopeName은 여러 스토리지 세션을 허용하는 범위를 정의합니다
    ScopeName string

    // Reset은 스토리지가 생성된 후 재설정 여부를 나타냅니다 
    Reset bool

    // TLSConfig는 연결 시 사용할 tls.Config를 지정합니다. nil인 경우 일반 텍스트가 사용됩니다
    TLSConfig *tls.Config

    // NearCacheTimeout은 Near Cache의 시간 초과를 정의합니다.
    // 이 값이 설정되면 지정된 시간 초과를 사용하여 Near Cache가 생성됩니다. 
    // 참고: 이 값은 세션 시간 초과 또는 Set() 사용 시 지정하는 모든 시간 초과보다 작아야 합니다.
    NearCacheTimeout time.Duration
}

Default Config

var DefaultConfig = Config{
    Address:   "localhost:1408",
    Timeout:   time.Duration(120) * time.Seconds,
    ScopeName: defaultScopeName,
    Reset:     false,
    NearCacheTimeout: time.Duration(60) * time.Seconds,
}

Coherence 세션을 생성할 때 연결 옵션에 대한 문서는 를 참조하세요.

🧩
📦
https://github.com/oracle/coherence-go-client
여기