1"use strict";(self.webpackChunkfiber_docs=self.webpackChunkfiber_docs||[]).push([["10744"],{66813(e,n,t){t.r(n),t.d(n,{metadata:()=>i,default:()=>f,frontMatter:()=>l,contentTitle:()=>o,toc:()=>c,assets:()=>r});var i=JSON.parse('{"id":"valkey/valkey","title":"Valkey","description":"Release","source":"@site/storage_versioned_docs/version-firestore_v0.x.x/valkey/README.md","sourceDirName":"valkey","slug":"/valkey/","permalink":"/storage/firestore_v0.x.x/valkey/","draft":false,"unlisted":false,"editUrl":"https://github.com/gofiber/storage/edit/main/valkey/README.md","tags":[],"version":"firestore_v0.x.x","lastUpdatedAt":1791052031000,"frontMatter":{"id":"valkey","title":"Valkey"},"sidebar":"left_sidebar","previous":{"title":"Test Compatibility Kit (TCK) for Storage Implementations","permalink":"/storage/firestore_v0.x.x/testhelpers/tck/"}}'),s=t(474848),a=t(28453);let l={id:"valkey",title:"Valkey"},o,r={},c=[{value:"Table of Contents",id:"table-of-contents",level:3},{value:"Signatures",id:"signatures",level:3},{value:"Installation",id:"installation",level:3},{value:"Examples",id:"examples",level:3},{value:"Config",id:"config",level:3},{value:"Default Config",id:"default-config",level:3},{value:"Using an Existing Valkey Connection",id:"using-an-existing-valkey-connection",level:3}];function d(e){let n={a:"a",blockquote:"blockquote",code:"code",h3:"h3",img:"img",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,a.R)(),...e.components};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.img,{src:"https://img.shields.io/github/v/tag/gofiber/storage?filter=valkey*",alt:"Release"}),"\n",(0,s.jsx)(n.a,{href:"https://gofiber.io/discord",children:(0,s.jsx)(n.img,{src:"https://img.shields.io/discord/704680098577514527?style=flat&label=%F0%9F%92%AC%20discord&color=00ACD7",alt:"Discord"})}),"\n",(0,s.jsx)(n.img,{src:"https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-valkey.yml?label=Tests",alt:"Test"})]}),"\n",(0,s.jsxs)(n.p,{children:["A fast Valkey Storage that does auto pipelining and supports client side caching. Implementation is based on ",(0,s.jsx)(n.a,{href:"https://github.com/valkey-io/valkey-go",children:"valkey-io/valkey"}),"."]}),"\n",(0,s.jsx)(n.h3,{id:"table-of-contents",children:"Table of Contents"}),"\n",(0,s.jsxs)(n.ul,{children:["\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.a,{href:"#signatures",children:"Signatures"})}),"\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.a,{href:"#installation",children:"Installation"})}),"\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.a,{href:"#examples",children:"Examples"})}),"\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.a,{href:"#config",children:"Config"})}),"\n",(0,s.jsx)(n.li,{children:(0,s.jsx)(n.a,{href:"#default-config",children:"Default Config"})}),"\n"]}),"\n",(0,s.jsx)(n.h3,{id:"signatures",children:"Signatures"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-go",children:"func New(config ...Config) Storage\nfunc NewWithContext(ctx context.Context, config ...Config) *Storage\nfunc NewFromConnection(conn valkey.Client, config ...Config) *Storage\nfunc NewFromConnectionWithContext(ctx context.Context, conn valkey.Client, config ...Config) *Storage\nfunc (s *Storage) Get(key string) ([]byte, error)\nfunc (s *Storage) GetWithContext(ctx context.Context, key string) ([]byte, error)\nfunc (s *Storage) Set(key string, val []byte, exp time.Duration) error\nfunc (s *Storage) SetWithContext(ctx context.Context, key string, val []byte, exp time.Duration) error\nfunc (s *Storage) Delete(key string) error\nfunc (s *Storage) DeleteWithContext(ctx context.Context, key string) error\nfunc (s *Storage) Reset() error\nfunc (s *Storage) ResetWithContext(ctx context.Context) error\nfunc (s *Storage) Close() error\nfunc (s *Storage) Conn() valkey.Client\n"})}),"\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.strong,{children:"Note:"})," ",(0,s.jsx)(n.code,{children:"AlwaysPipelining"}),' defaults to true and this config reads a zero value as "not set", so setting it to false has no effect. Use ',(0,s.jsx)(n.code,{children:"DisableAlwaysPipelining: true"})," to turn it off, the same way ",(0,s.jsx)(n.code,{children:"DisableRetry"})," and ",(0,s.jsx)(n.code,{children:"DisableCache"})," work."]}),"\n",(0,s.jsx)(n.h3,{id:"installation",children:"Installation"}),"\n",(0,s.jsxs)(n.p,{children:["The valkey driver is tested on the latest two ",(0,s.jsx)(n.a,{href:"https://golang.org/dl/",children:"Go version"})," with support for modules. So make sure to initialize one first if you didn't do that yet:"]}
1),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"go mod init github.com/<user>/<repo>\n"})}),"\n",(0,s.jsx)(n.p,{children:"And then install the valkey implementation:"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-bash",children:"go get github.com/gofiber/storage/valkey\n"})}),"\n",(0,s.jsx)(n.h3,{id:"examples",children:"Examples"}),"\n",(0,s.jsx)(n.p,{children:"Import the storage package."}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-go",children:'import "github.com/gofiber/storage/valkey"\n'})}),"\n",(0,s.jsx)(n.p,{children:"You can use the one of the following options to create a Valkey Storage:"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-go",children:'// Initialize default config (localhost:6379)\nstore := valkey.New()\n\n// Initialize custom config \nstore := valkey.New(valkey.Config{\n InitAddress: []string{"localhost:6380"},\n Username: "",\n Password: "",\n Database: 0,\n Reset: false,\n TLSConfig: nil,\n})\n\n// Initialize using Redis-style URL\nstore := valkey.New(valkey.Config{\n URL: "redis://localhost:6379",\n})\n\n// Initialize Valkey Cluster Client\nstore := valkey.New(valkey.Config{\n InitAddress: []string{":6379", ":6380"},\n})\n\n// Create a client with support for TLS\ncer, err := tls.LoadX509KeyPair("./client.crt", "./client.key")\nif err != nil {\n log.Println(err)\n return\n}
1\ntlsCfg := &tls.Config{\n MinVersion: tls.VersionTLS12,\n InsecureSkipVerify: true,\n Certificates: []tls.Certificate{cer},\n}\nstore = valkey.New(valkey.Config{\n InitAddress: []string{"localhost:6380"},\n Username: "<user>",\n Password: "<password>",\n SelectDB: 0,\n TLSConfig: tlsCfg,\n})\n\n'})}),"\n",(0,s.jsx)(n.h3,{id:"config",children:"Config"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-go",children:'type Config struct {\n // Server username\n //\n // Optional. Default is ""\n Username string\n\n // Server password\n //\n // Optional. Default is ""\n Password string\n\n // ClientName will execute the `CLIENT SETNAME ClientName` command for each conn.\n //\n // Optional. Default is ""\n ClientName string\n\n // URL standard format Redis-style URL. If this is set all other config options, InitAddress, Username, Password, ClientName, and SelectDB have no effect.\n //\n // Example: redis://<user>:<pass>@localhost:6379/<db>\n // Optional. Default is ""\n URL string\n\n // SelectDB to be selected after connecting to the server.\n //\n // Optional. Default is 0\n SelectDB int\n\n // Either a single address or a seed list of host:port addresses, this enables FailoverClient and ClusterClient\n //\n // Optional. Default is []string{"127.0.0.1:6379"}\n InitAddress []string\n\n // TLS Config to use. When set TLS will be negotiated.\n //\n // Optional. Default is nil\n TLSConfig *tls.
1Config\n\n // CacheSizeEachConn is valkey client side cache size that bind to each TCP connection to a single valkey instance.\n //\n // Optional. The default is DefaultCacheBytes: 128 * (1 << 20)\n CacheSizeEachConn int\n\n // RingScaleEachConn sets the size of the ring buffer in each connection to (2 ^ RingScaleEachConn).\n //\n // Optional. The default is RingScaleEachConn, which results into having a ring of size 2^10 for each connection.\n RingScaleEachConn int\n\n // ReadBufferEachConn is the size of the bufio.NewReaderSize for each connection, default to DefaultReadBuffer (0.5 MiB).\n //\n // Optional. The default is DefaultReadBuffer: 1 << 19\n ReadBufferEachConn int\n\n // WriteBufferEachConn is the size of the bufio.NewWriterSize for each connection, default to DefaultWriteBuffer (0.5 MiB).\n //\n // Optional. The default is DefaultWriteBuffer: 1 << 19\n WriteBufferEachConn int\n\n // BlockingPoolSize is the size of the connection pool shared by blocking commands (ex BLPOP, XREAD with BLOCK).\n //\n // Optional. The default is DefaultPoolSize: 1000\n BlockingPoolSize int\n\n // PipelineMultiplex determines how many tcp connections used to pipeline commands to one valkey instance.\n //\n // Optional. The default for single and sentinel clients is 2, which means 4 connections (2^2).\n PipelineMultiplex int\n\n // DisableRetry disables retrying read-only commands under network errors\n //\n // Optional. The default is False\n DisableRetry bool\n\n // DisableCache falls back Client.DoCache/Client.DoMultiCache to Client.Do/Client.DoMulti\n //\n // Optional. The default is false\n DisableCache bool\n\n // AlwaysPipelining makes valkey.Client always pipeline valkey commands even if they are not issued concurrently.\n //\n // Optional. The default is true\n AlwaysPipelining bool\n\n // DisableAlwaysPipelining turns AlwaysPipelining off. That field defaults to\n // true and a zero value reads as "not set", so setting it false does nothing;\n // this is the way to disable it, matching DisableRetry and DisableCache.\n //\n // Optional. Default is false\n DisableAlwaysPipelining bool\n\n // Reset clears any existing keys in existing Collection\n //\n // Optional. Default is false\n Reset bool\n\n // CacheTTL TTL\n //\n // Optional. Default is time.Minute\n CacheTTL time.Duration\n}\n'})}),"\n",(0,s.jsx)(n.h3,{id:"default-config",children:"Default Config"}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-go",children:'var ConfigDefault = Config{\n Username: "",\n Password: "",\n ClientName: "",\n SelectDB: 0,\n InitAddress: []string{"127.0.0.1:6379"},\n TLSConfig: nil,\n CacheSizeEachConn: valkey.DefaultCacheBytes,\n RingScaleEachConn: valkey.DefaultRingScale,\n ReadBufferEachConn: valkey.DefaultReadBuffer,\n WriteBufferEachConn: valkey.DefaultWriteBuffer,\n BlockingPoolSize: valkey.DefaultPoolSize,\n PipelineMultiplex: 2,\n DisableRetry: false,\n DisableCache: false,\n AlwaysPipelining: true,\n DisableAlwaysPipelining: false,\n Reset: false,\n CacheTTL: time.Minute,\n}\n'})}),"\n",(0,s.jsx)(n.h3,{id:"using-an-existing-valkey-connection",children:"Using an Existing Valkey Connection"}),"\n",(0,s.jsxs)(n.p,{children:["If your application already holds a ",(0,s.jsx)(n.code,{children:"valkey.Client"}),", you can build the storage on it instead of creating a second one. Only ",(0,s.jsx)(n.code,{children:"CacheTTL"})," and ",(0,s.jsx)(n.code,{children:"Reset"})," are read from the config; the connection settings come from the client, and nothing touches the network unless ",(0,s.jsx)(n.code,{children:"Reset"})," is set."]}),"\n",(0,s.jsxs)(n.p,{children:["The client stays yours to close: ",(0,s.jsx)(n.code,{children:"Close"})," on a storage built this way leaves it open, so the rest of your application keeps working. The storage itself is closed, and any operation on it afterwards returns ",(0,s.jsx)(n.code,{children:"ErrClosed"}),"."]}),"\n",(0,s.jsxs)(n.blockquote,{children:["\n",(0,s.jsxs)(n.p,{children:[(0,s.jsx)(n.strong,{children:"Warning:"})," ",(0,s.jsx)(n.code,{children:"Reset"})," \u2014 the config option and the method \u2014 issues ",(0,s.jsx)(n.code,{children:"FLUSHDB"})," on the client's database, deleting every key in it, not just this storage's entries."]}),"\n"]}),"\n",(0,s.jsx)(n.pre,{children:(0,s.jsx)(n.code,{className:"language-go",children:'import (\n "github.com/gofiber/storage/valkey"\n valkeylib "github.com/valkey-io/valkey-go"\n)\n\nfunc main() {\n client, err := valkeylib.NewClient(valkeylib.ClientOption{\n InitAddress: []string{"127.0.0.1:6379"},\n })\n if err != nil {\n panic(err)\n }\n defer client.Close()\n\n store := valkey.NewFromConnection(client)\n defer store.Close()\n}\n'})})]})}function f(e={}){let{wrapper:n}={...(0,a.R)(),...e.components};return n?(0,s.jsx)(n,{...e,children:(0,s.jsx)(d,{...e})}):d(e)}},28453(e,n,t){t.d(n,{R:()=>l,x:()=>o});var i=t(296540);let s={},a=i.createContext(s);function l(e){let n=i.useContext(a);return i.useMemo(function(){return"function"==typeof e?e(n):{...n,...e}},[n,e])}function o(e){let n;return n=e.disableParentContext?"function"==typeof e.components?e.components(s):e.components||s:l(e.components),i.createElement(a.Provider,{value:n},e.children)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.