Class: Couchbase::Cluster
- Inherits:
-
Object
- Object
- Couchbase::Cluster
- Defined in:
- lib/couchbase/cluster.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#create_bucket(name, options = {}) ⇒ Object
Create data bucket.
-
#delete_bucket(bucket) ⇒ Object
Delete the data bucket.
- #flush_bucket(bucket) ⇒ Object
-
#initialize(options) ⇒ Cluster
constructor
Establish connection to the cluster for administration.
-
#list_buckets ⇒ Object
List available buckets.
- #update_bucket(name, options) ⇒ Object
Constructor Details
#initialize(options) ⇒ Cluster
Establish connection to the cluster for administration
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/couchbase/cluster.rb', line 37 def initialize() if [:username].nil? || [:password].nil? raise ArgumentError, "username and password mandatory to connect to the cluster" end = { hostname: 'localhost', port: 8091 }.merge() cluster_uri = "http://#{[:hostname]}:#{[:port]}" uri_list = Array(URI.new(cluster_uri)) @manager = Java::ComCouchbaseClient::ClusterManager.new(uri_list, [:username], [:password]) end |
Class Method Details
.manage(cluster_uri, username, password, &block) ⇒ Object
108 109 110 111 112 113 |
# File 'lib/couchbase/cluster.rb', line 108 def self.manage(cluster_uri, username, password, &block) manager = new(cluster_uri, username, password) yield manager ensure manager.shutdown end |
Instance Method Details
#create_bucket(name, options = {}) ⇒ Object
Create data bucket
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/couchbase/cluster.rb', line 79 def create_bucket(name, = {}) ram_quota = [:ram_quota] || 100 replicas = [:replica_number] || 0 flush = .fetch(:flush) { true } password = [:password] proxy_port = [:proxy_port] auth_type = [:auth_type] || 'sasl' bucket_type = [:bucket_type] == 'memcached' ? BucketType::MEMCACHED : BucketType::COUCHBASE if name == 'default' @manager.createDefaultBucket(bucket_type, ram_quota, replicas, flush) elsif auth == 'sasl' @manager.createPortBucket(bucket_type, name, ram_quota, replicas, proxy_port, flush) else @manager.createNamedBucket(bucket_type, name, ram_quota, replicas, password, flush) end true rescue Java::JavaLang::RuntimeException => e raise ClusterError, e end |
#delete_bucket(bucket) ⇒ Object
Delete the data bucket
62 63 64 |
# File 'lib/couchbase/cluster.rb', line 62 def delete_bucket(bucket) @manager.deleteBucket(bucket) end |
#flush_bucket(bucket) ⇒ Object
100 101 102 |
# File 'lib/couchbase/cluster.rb', line 100 def flush_bucket(bucket) @manager.flushBucket(bucket) == FlushResponse::OK end |
#list_buckets ⇒ Object
List available buckets
54 55 56 |
# File 'lib/couchbase/cluster.rb', line 54 def list_buckets @manager.listBuckets end |
#update_bucket(name, options) ⇒ Object
104 105 106 |
# File 'lib/couchbase/cluster.rb', line 104 def update_bucket(name, ) # implement end |