module

CryBase::CouchBase::Services::KV

Implementation of the Couchbase KV (Data) service over Couchbase's memcached binary protocol, using plaintext or TLS sockets according to the endpoint or connection string.

The main public entry points are KV::Client.from_string for one authenticated connection, KV::Pool.from_string for a fixed-size pool, and KV::Cluster.from_string for seed failover across multiple KV hosts. They accept connection strings with credentials, bucket, explicit KV port, and TLS query options:

cluster = CryBase::CouchBase::KV::Cluster.from_string(
  "couchbases://user:pass@node1,node2:11217/default?tls_verify=false"
)
cluster.set("hello", "world")
cluster.get("hello") # => Bytes containing "world"
cluster.close

You can still construct an Endpoint explicitly or through CryBase::CouchBase::Endpoint.from_string and pass it to KV::Client.new or KV::Pool.new when credentials and bucket should stay separate from the endpoint address.

The namespace is structured as small composable pieces:

  • KV::Constants — protocol constants used by packet framing
  • KV::Request — value type describing one outbound packet
  • KV::RequestBuffer — serializes one outbound packet into bytes
  • KV::RequestWriter — mixin: writes and flushes a request buffer
  • KV::Response — value type describing one inbound packet
  • KV::ResponseReader — mixin: read decodes one packet from a socket
  • KV::Bucket — mixin: SELECT_BUCKET handshake
  • KV::Serializable — typed value codec
  • KV::Pool — fixed-size pool of authenticated clients
  • KV::Cluster — seed-failover client backed by KV::Pool

KV::Client composes the request/response/bucket mixins, performs HELLO, SASL_AUTH(PLAIN), and SELECT_BUCKET, then exposes document, expiry, counter, and typed JSON helper operations.

Class methods

collection_key(collection_id : UInt32, key : String) : Bytes
Source
counter_extras(delta : UInt64, initial : UInt64, expiry : UInt32) : Bytes
Source
counter_value(value : Bytes) : UInt64
Source
discover_vbucket_count(endpoints : Array(Endpoint), username : String, password : String, bucket : String, connect_timeout : Time::Span = 5.seconds, *, tls_verify : Bool = true, tls_hostname : String | Nil = nil, tls_context : OpenSSL::SSL::Context::Client | Nil = nil) : UInt16 | Nil
Source
expiry_extras(expiry : UInt32) : Bytes
Source
management_endpoints(connection_string : ConnectionString, port_override : Int32 | Nil = nil) : Array(Endpoint)
Source
management_endpoints(seed_endpoints : Array(Endpoint)) : Array(Endpoint)
Source
unsigned_leb128(value : UInt32) : Bytes
Source
vbucket_id(key : String, count : UInt16 = Constants::VBUCKET_COUNT) : UInt16
Source

Nested types