Class: Aerospike::Client
- Inherits:
-
Object
- Object
- Aerospike::Client
- Defined in:
- lib/aerospike/client.rb
Overview
Examples:
# connect to the database client = Client.new(‘192.168.0.1’)
#=> raises Aerospike::Exceptions::Timeout if a :timeout is specified and :fail_if_not_connected set to true
Instance Attribute Summary collapse
-
#default_admin_policy ⇒ Object
Returns the value of attribute default_admin_policy.
-
#default_policy ⇒ Object
Returns the value of attribute default_policy.
-
#default_query_policy ⇒ Object
Returns the value of attribute default_query_policy.
-
#default_scan_policy ⇒ Object
Returns the value of attribute default_scan_policy.
-
#default_write_policy ⇒ Object
Returns the value of attribute default_write_policy.
Instance Method Summary collapse
-
#add(key, bins, options = {}) ⇒ Object
Examples:.
-
#append(key, bins, options = {}) ⇒ Object
Examples:.
-
#batch_exists(keys, options = {}) ⇒ Object
Check if multiple record keys exist in one batch call.
-
#batch_get(keys, bin_names = [], options = {}) ⇒ Object
Read multiple record headers and bins for specified keys in one batch call.
-
#batch_get_header(keys, options = {}) ⇒ Object
Read multiple record header data for specified keys in one batch call.
-
#change_password(user, password, options = {}) ⇒ Object
Change user’s password.
-
#close ⇒ Object
Closes all client connections to database server nodes.
-
#connect ⇒ Object
Connect to the cluster.
-
#connected? ⇒ Boolean
Determines if there are active connections to the database server cluster.
-
#create_index(namespace, set_name, index_name, bin_name, index_type, collection_type = nil, options = {}) ⇒ Object
Create secondary index.
-
#create_user(user, password, roles, options = {}) ⇒ Object
Create user with password and roles.
-
#delete(key, options = {}) ⇒ Object
Examples:.
-
#drop_index(namespace, set_name, index_name, options = {}) ⇒ Object
Delete secondary index.
-
#drop_user(user, options = {}) ⇒ Object
Remove user from cluster.
-
#execute_udf(key, package_name, function_name, args = [], options = {}) ⇒ Object
Execute user defined function on server and return results.
-
#execute_udf_on_query(statement, package_name, function_name, function_args = [], options = {}) ⇒ Object
execute_udf_on_query applies user defined function on records that match the statement filter.
-
#exists(key, options = {}) ⇒ Object
Determines if a record key exists.
-
#get(key, bin_names = [], options = {}) ⇒ Object
Read record header and bins for specified key.
-
#get_header(key, options = {}) ⇒ Object
Read record generation and expiration only for specified key.
-
#grant_roles(user, roles, options = {}) ⇒ Object
Add roles to user’s list of roles.
-
#initialize(hosts = nil, policy: ClientPolicy.new, connect: true) ⇒ Client
constructor
A new instance of Client.
-
#list_udf(options = {}) ⇒ Object
ListUDF lists all packages containing user defined functions in the server.
-
#node_names ⇒ Object
Returns list of active server node names in the cluster.
-
#nodes ⇒ Object
Returns array of active server nodes in the cluster.
-
#operate(key, operations, options = {}) ⇒ Object
Perform multiple read/write operations on a single key in one batch call.
-
#prepend(key, bins, options = {}) ⇒ Object
Examples:.
-
#put(key, bins, options = {}) ⇒ Object
Examples:.
-
#query(statement, options = {}) ⇒ Object
Query executes a query and returns a recordset.
-
#query_user(user, options = {}) ⇒ Object
Retrieve roles for a given user.
-
#query_users(options = {}) ⇒ Object
Retrieve all users and their roles.
-
#register_udf(udf_body, server_path, language, options = {}) ⇒ Object
Register package containing user defined functions with server.
-
#register_udf_from_file(client_path, server_path, language, options = {}) ⇒ Object
Register package containing user defined functions with server.
-
#remove_udf(udf_name, options = {}) ⇒ Object
RemoveUDF removes a package containing user defined functions in the server.
- #request_info(*commands) ⇒ Object
-
#revoke_roles(user, roles, options = {}) ⇒ Object
Remove roles from user’s list of roles.
-
#scan_all(namespace, set_name, bin_names = [], options = {}) ⇒ Object
——————————————————- Scan Operations ——————————————————-.
-
#scan_node(node, namespace, set_name, bin_names = [], options = {}) ⇒ Object
ScanNode reads all records in specified namespace and set, from one node only.
- #supports_feature?(feature) ⇒ Boolean
-
#touch(key, options = {}) ⇒ Object
Examples:.
-
#truncate(namespace, set_name = nil, before_last_update = nil, options = {}) ⇒ Object
Removes records in the specified namespace/set efficiently.
Constructor Details
#initialize(hosts = nil, policy: ClientPolicy.new, connect: true) ⇒ Client
Returns a new instance of Client.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/aerospike/client.rb', line 44 def initialize(hosts = nil, policy: ClientPolicy.new, connect: true) @default_policy = Policy.new @default_write_policy = WritePolicy.new @default_scan_policy = ScanPolicy.new @default_query_policy = QueryPolicy.new @default_admin_policy = QueryPolicy.new hosts = ::Aerospike::Host::Parse.(hosts || ENV['AEROSPIKE_HOSTS'] || 'localhost') policy = create_policy(policy, ClientPolicy) @cluster = Cluster.new(policy, hosts) @cluster.add_cluster_config_change_listener(self) self.connect if connect self end |
Instance Attribute Details
#default_admin_policy ⇒ Object
Returns the value of attribute default_admin_policy.
41 42 43 |
# File 'lib/aerospike/client.rb', line 41 def default_admin_policy @default_admin_policy end |
#default_policy ⇒ Object
Returns the value of attribute default_policy.
41 42 43 |
# File 'lib/aerospike/client.rb', line 41 def default_policy @default_policy end |
#default_query_policy ⇒ Object
Returns the value of attribute default_query_policy.
41 42 43 |
# File 'lib/aerospike/client.rb', line 41 def default_query_policy @default_query_policy end |
#default_scan_policy ⇒ Object
Returns the value of attribute default_scan_policy.
41 42 43 |
# File 'lib/aerospike/client.rb', line 41 def default_scan_policy @default_scan_policy end |
#default_write_policy ⇒ Object
Returns the value of attribute default_write_policy.
41 42 43 |
# File 'lib/aerospike/client.rb', line 41 def default_write_policy @default_write_policy end |
Instance Method Details
#add(key, bins, options = {}) ⇒ Object
Examples:
client.add key, {'bin', -1}, :timeout => 0.001
180 181 182 183 184 |
# File 'lib/aerospike/client.rb', line 180 def add(key, bins, ={}) policy = create_policy(, WritePolicy) command = WriteCommand.new(@cluster, policy, key, hash_to_bins(bins), Aerospike::Operation::ADD) execute_command(command) end |
#append(key, bins, options = {}) ⇒ Object
Examples:
client.append key, {'bin', 'value to append'}, :timeout => 0.001
138 139 140 141 142 |
# File 'lib/aerospike/client.rb', line 138 def append(key, bins, ={}) policy = create_policy(, WritePolicy) command = WriteCommand.new(@cluster, policy, key, hash_to_bins(bins), Aerospike::Operation::APPEND) execute_command(command) end |
#batch_exists(keys, options = {}) ⇒ Object
Check if multiple record keys exist in one batch call.
The returned array bool is in positional order with the original key array order.
The policy can be used to specify timeouts.
273 274 275 276 277 278 279 280 281 282 283 284 285 286 |
# File 'lib/aerospike/client.rb', line 273 def batch_exists(keys, ={}) policy = create_policy(, Policy) # same array can be used without sychronization; # when a key exists, the corresponding index will be marked true exists_array = Array.new(keys.length) key_map = BatchItem.generate_map(keys) batch_execute(keys) do |node, bns| BatchCommandExists.new(node, bns, policy, key_map, exists_array) end exists_array end |
#batch_get(keys, bin_names = [], options = {}) ⇒ Object
Read multiple record headers and bins for specified keys in one batch call.
The returned records are in positional order with the original key array order.
If a key is not found, the positional record will be nil.
The policy can be used to specify timeouts.
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 |
# File 'lib/aerospike/client.rb', line 319 def batch_get(keys, bin_names=[], ={}) policy = create_policy(, Policy) # wait until all migrations are finished # TODO: implement # @cluster.WaitUntillMigrationIsFinished(policy.timeout) # same array can be used without sychronization; # when a key exists, the corresponding index will be set to record records = Array.new(keys.length) key_map = BatchItem.generate_map(keys) batch_execute(keys) do |node, bns| BatchCommandGet.new(node, bns, policy, key_map, bin_names.uniq, records, INFO1_READ) end records end |
#batch_get_header(keys, options = {}) ⇒ Object
Read multiple record header data for specified keys in one batch call.
The returned records are in positional order with the original key array order.
If a key is not found, the positional record will be nil.
The policy can be used to specify timeouts.
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 |
# File 'lib/aerospike/client.rb', line 342 def batch_get_header(keys, ={}) policy = create_policy(, Policy) # wait until all migrations are finished # TODO: Fix this and implement # @cluster.WaitUntillMigrationIsFinished(policy.timeout) # same array can be used without sychronization; # when a key exists, the corresponding index will be set to record records = Array.new(keys.length) key_map = BatchItem.generate_map(keys) batch_execute(keys) do |node, bns| BatchCommandGet.new(node, bns, policy, key_map, nil, records, INFO1_READ | INFO1_NOBINDATA) end records end |
#change_password(user, password, options = {}) ⇒ Object
Change user’s password. Clear-text password will be hashed using bcrypt before sending to server.
750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 |
# File 'lib/aerospike/client.rb', line 750 def change_password(user, password, ={}) raise Aerospike::Exceptions::Aerospike.new(INVALID_USER) unless @cluster.user && @cluster.user != "" policy = create_policy(, AdminPolicy) hash = AdminCommand.hash_password(password) command = AdminCommand.new if user == @cluster.user # Change own password. command.change_password(@cluster, policy, user, hash) else # Change other user's password by user admin. command.set_password(@cluster, policy, user, hash) end @cluster.change_password(user, hash) end |
#close ⇒ Object
Closes all client connections to database server nodes.
70 71 72 |
# File 'lib/aerospike/client.rb', line 70 def close @cluster.close end |
#connect ⇒ Object
Connect to the cluster.
63 64 65 |
# File 'lib/aerospike/client.rb', line 63 def connect @cluster.connect end |
#connected? ⇒ Boolean
Determines if there are active connections to the database server cluster.
Returns +true+ if connections exist.
78 79 80 |
# File 'lib/aerospike/client.rb', line 78 def connected? @cluster.connected? end |
#create_index(namespace, set_name, index_name, bin_name, index_type, collection_type = nil, options = {}) ⇒ Object
Create secondary index.
This asynchronous server call will return before command is complete.
The user can optionally wait for command completion by using the returned
IndexTask instance.
This method is only supported by Aerospike 3 servers.
index_type should be :string, :numeric or :geo2dsphere (requires server version 3.7 or later)
collection_type should be :list, :mapkeys or :mapvalues
548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 |
# File 'lib/aerospike/client.rb', line 548 def create_index(namespace, set_name, index_name, bin_name, index_type, collection_type=nil, ={}) if .nil? && collection_type.is_a?(Hash) , collection_type = collection_type, nil end policy = create_policy(, WritePolicy) str_cmd = "sindex-create:ns=#{namespace}" str_cmd << ";set=#{set_name}" unless set_name.to_s.strip.empty? str_cmd << ";indexname=#{index_name};numbins=1" str_cmd << ";indextype=#{collection_type.to_s.upcase}" if collection_type str_cmd << ";indexdata=#{bin_name},#{index_type.to_s.upcase}" str_cmd << ";priority=normal" # Send index command to one node. That node will distribute the command to other nodes. response = send_info_command(policy, str_cmd).upcase if response == 'OK' # Return task that could optionally be polled for completion. return IndexTask.new(@cluster, namespace, index_name) end if response.start_with?('FAIL:200') # Index has already been created. Do not need to poll for completion. return IndexTask.new(@cluster, namespace, index_name, true) end raise Aerospike::Exceptions::Aerospike.new(Aerospike::ResultCode::INDEX_GENERIC, "Create index failed: #{response}") end |
#create_user(user, password, roles, options = {}) ⇒ Object
Create user with password and roles. Clear-text password will be hashed using bcrypt before sending to server.
735 736 737 738 739 740 |
# File 'lib/aerospike/client.rb', line 735 def create_user(user, password, roles, ={}) policy = create_policy(, AdminPolicy) hash = AdminCommand.hash_password(password) command = AdminCommand.new command.create_user(@cluster, policy, user, hash, roles) end |
#delete(key, options = {}) ⇒ Object
Examples:
existed = client.delete key, :timeout => 0.001
202 203 204 205 206 207 |
# File 'lib/aerospike/client.rb', line 202 def delete(key, ={}) policy = create_policy(, WritePolicy) command = DeleteCommand.new(@cluster, policy, key) execute_command(command) command.existed end |
#drop_index(namespace, set_name, index_name, options = {}) ⇒ Object
Delete secondary index.
This method is only supported by Aerospike 3 servers.
577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 |
# File 'lib/aerospike/client.rb', line 577 def drop_index(namespace, set_name, index_name, ={}) policy = create_policy(, WritePolicy) str_cmd = "sindex-delete:ns=#{namespace}" str_cmd << ";set=#{set_name}" unless set_name.to_s.strip.empty? str_cmd << ";indexname=#{index_name}" # Send index command to one node. That node will distribute the command to other nodes. response = send_info_command(policy, str_cmd).upcase return if response == 'OK' # Index did not previously exist. Return without error. return if response.start_with?('FAIL:201') raise Aerospike::Exceptions::Aerospike.new(Aerospike::ResultCode::INDEX_GENERIC, "Drop index failed: #{response}") end |
#drop_user(user, options = {}) ⇒ Object
Remove user from cluster.
743 744 745 746 747 |
# File 'lib/aerospike/client.rb', line 743 def drop_user(user, ={}) policy = create_policy(, AdminPolicy) command = AdminCommand.new command.drop_user(@cluster, policy, user) end |
#execute_udf(key, package_name, function_name, args = [], options = {}) ⇒ Object
Execute user defined function on server and return results.
The function operates on a single record.
The package name is used to locate the udf file location:
udf file = <server udf dir>/<package name>.lua
This method is only supported by Aerospike 3 servers.
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 |
# File 'lib/aerospike/client.rb', line 482 def execute_udf(key, package_name, function_name, args=[], ={}) policy = create_policy(, WritePolicy) command = ExecuteCommand.new(@cluster, policy, key, package_name, function_name, args) execute_command(command) record = command.record return nil if !record || record.bins.empty? result_map = record.bins # User defined functions don't have to return a value. key, obj = result_map.detect{ |k, _| k.include?('SUCCESS') } return obj if key key, obj = result_map.detect{ |k, _| k.include?('FAILURE') } = key ? obj.to_s : "Invalid UDF return value" raise Aerospike::Exceptions::Aerospike.new(Aerospike::ResultCode::UDF_BAD_RESPONSE, ) end |
#execute_udf_on_query(statement, package_name, function_name, function_args = [], options = {}) ⇒ Object
execute_udf_on_query applies user defined function on records that match the statement filter. Records are not returned to the client. This asynchronous server call will return before command is complete. The user can optionally wait for command completion by using the returned ExecuteTask instance.
This method is only supported by Aerospike 3 servers. If the policy is nil, the default relevant policy will be used.
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 |
# File 'lib/aerospike/client.rb', line 511 def execute_udf_on_query(statement, package_name, function_name, function_args=[], ={}) policy = create_policy(, QueryPolicy) nodes = @cluster.nodes if nodes.empty? raise Aerospike::Exceptions::Aerospike.new(Aerospike::ResultCode::SERVER_NOT_AVAILABLE, "Executing UDF failed because cluster is empty.") end # TODO: wait until all migrations are finished statement.set_aggregate_function(package_name, function_name, function_args, false) # Use a thread per node nodes.each do |node| Thread.new do Thread.current.abort_on_exception = true begin command = QueryCommand.new(node, policy, statement, nil) execute_command(command) rescue => e Aerospike.logger.error(e) raise e end end end ExecuteTask.new(@cluster, statement) end |
#exists(key, options = {}) ⇒ Object
Determines if a record key exists.
The policy can be used to specify timeouts.
263 264 265 266 267 268 |
# File 'lib/aerospike/client.rb', line 263 def exists(key, ={}) policy = create_policy(, Policy) command = ExistsCommand.new(@cluster, policy, key) execute_command(command) command.exists end |
#get(key, bin_names = [], options = {}) ⇒ Object
Read record header and bins for specified key.
The policy can be used to specify timeouts.
294 295 296 297 298 299 300 |
# File 'lib/aerospike/client.rb', line 294 def get(key, bin_names=[], ={}) policy = create_policy(, Policy) command = ReadCommand.new(@cluster, policy, key, bin_names) execute_command(command) command.record end |
#get_header(key, options = {}) ⇒ Object
Read record generation and expiration only for specified key. Bins are not read.
The policy can be used to specify timeouts.
304 305 306 307 308 309 |
# File 'lib/aerospike/client.rb', line 304 def get_header(key, ={}) policy = create_policy(, Policy) command = ReadHeaderCommand.new(@cluster, policy, key) execute_command(command) command.record end |
#grant_roles(user, roles, options = {}) ⇒ Object
Add roles to user’s list of roles.
769 770 771 772 773 |
# File 'lib/aerospike/client.rb', line 769 def grant_roles(user, roles, ={}) policy = create_policy(, AdminPolicy) command = AdminCommand.new command.grant_roles(@cluster, policy, user, roles) end |
#list_udf(options = {}) ⇒ Object
ListUDF lists all packages containing user defined functions in the server.
This method is only supported by Aerospike 3 servers.
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 |
# File 'lib/aerospike/client.rb', line 446 def list_udf(={}) str_cmd = 'udf-list' # Send command to one node. That node will distribute it to other nodes. response_map = @cluster.request_info(@default_policy, str_cmd) _, response = response_map.first vals = response.split(';') vals.map do |udf_info| next if udf_info.strip! == '' udf_parts = udf_info.split(',') udf = UDF.new udf_parts.each do |values| k, v = values.split('=', 2) case k when 'filename' udf.filename = v when 'hash' udf.hash = v when 'type' udf.language = v end end udf end end |
#node_names ⇒ Object
Returns list of active server node names in the cluster.
92 93 94 |
# File 'lib/aerospike/client.rb', line 92 def node_names @cluster.nodes.map(&:name) end |
#nodes ⇒ Object
Returns array of active server nodes in the cluster.
85 86 87 |
# File 'lib/aerospike/client.rb', line 85 def nodes @cluster.nodes end |
#operate(key, operations, options = {}) ⇒ Object
Perform multiple read/write operations on a single key in one batch call.
An example would be to add an integer value to an existing record and then
read the result, all in one database call. Operations are executed in
the order they are specified.
370 371 372 373 374 375 376 |
# File 'lib/aerospike/client.rb', line 370 def operate(key, operations, ={}) policy = create_policy(, WritePolicy) command = OperateCommand.new(@cluster, policy, key, operations) execute_command(command) command.record end |
#prepend(key, bins, options = {}) ⇒ Object
Examples:
client.prepend key, {'bin', 'value to prepend'}, :timeout => 0.001
157 158 159 160 161 |
# File 'lib/aerospike/client.rb', line 157 def prepend(key, bins, ={}) policy = create_policy(, WritePolicy) command = WriteCommand.new(@cluster, policy, key, hash_to_bins(bins), Aerospike::Operation::PREPEND) execute_command(command) end |
#put(key, bins, options = {}) ⇒ Object
Examples:
client.put key, {'bin', 'value string'}, :timeout => 0.001
115 116 117 118 119 |
# File 'lib/aerospike/client.rb', line 115 def put(key, bins, ={}) policy = create_policy(, WritePolicy) command = WriteCommand.new(@cluster, policy, key, hash_to_bins(bins), Aerospike::Operation::WRITE) execute_command(command) end |
#query(statement, options = {}) ⇒ Object
Query executes a query and returns a recordset. The query executor puts records on a channel from separate goroutines. The caller can concurrently pops records off the channel through the record channel.
This method is only supported by Aerospike 3 servers. If the policy is nil, a default policy will be generated.
699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 |
# File 'lib/aerospike/client.rb', line 699 def query(statement, ={}) policy = create_policy(, QueryPolicy) new_policy = policy.clone nodes = @cluster.nodes if nodes.empty? raise Aerospike::Exceptions::Aerospike.new(Aerospike::ResultCode::SERVER_NOT_AVAILABLE, "Scan failed because cluster is empty.") end recordset = Recordset.new(policy.record_queue_size, nodes.length, :query) # Use a thread per node nodes.each do |node| Thread.new do Thread.current.abort_on_exception = true command = QueryCommand.new(node, new_policy, statement, recordset) begin execute_command(command) rescue => e Aerospike.logger.error(e.backtrace.join("\n")) unless e == QUERY_TERMINATED_EXCEPTION recordset.cancel(e) ensure recordset.thread_finished end end end recordset end |
#query_user(user, options = {}) ⇒ Object
Retrieve roles for a given user.
783 784 785 786 787 |
# File 'lib/aerospike/client.rb', line 783 def query_user(user, ={}) policy = create_policy(, AdminPolicy) command = AdminCommand.new command.query_user(@cluster, policy, user) end |
#query_users(options = {}) ⇒ Object
Retrieve all users and their roles.
790 791 792 793 794 |
# File 'lib/aerospike/client.rb', line 790 def query_users(={}) policy = create_policy(, AdminPolicy) command = AdminCommand.new command.query_users(@cluster, policy) end |
#register_udf(udf_body, server_path, language, options = {}) ⇒ Object
Register package containing user defined functions with server.
This asynchronous server call will return before command is complete.
The user can optionally wait for command completion by using the returned
RegisterTask instance.
This method is only supported by Aerospike 3 servers.
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 |
# File 'lib/aerospike/client.rb', line 399 def register_udf(udf_body, server_path, language, ={}) content = Base64.strict_encode64(udf_body).force_encoding('binary') str_cmd = "udf-put:filename=#{server_path};content=#{content};" str_cmd << "content-len=#{content.length};udf-type=#{language};" # Send UDF to one node. That node will distribute the UDF to other nodes. response_map = @cluster.request_info(@default_policy, str_cmd) res = {} response_map.each do |k, response| vals = response.to_s.split(';') vals.each do |pair| k, v = pair.split("=", 2) res[k] = v end end if res['error'] raise Aerospike::Exceptions::CommandRejected.new("Registration failed: #{res['error']}\nFile: #{res['file']}\nLine: #{res['line']}\nMessage: #{res['message']}") end UdfRegisterTask.new(@cluster, server_path) end |
#register_udf_from_file(client_path, server_path, language, options = {}) ⇒ Object
Register package containing user defined functions with server.
This asynchronous server call will return before command is complete.
The user can optionally wait for command completion by using the returned
RegisterTask instance.
This method is only supported by Aerospike 3 servers.
388 389 390 391 |
# File 'lib/aerospike/client.rb', line 388 def register_udf_from_file(client_path, server_path, language, ={}) udf_body = File.read(client_path) register_udf(udf_body, server_path, language, ) end |
#remove_udf(udf_name, options = {}) ⇒ Object
RemoveUDF removes a package containing user defined functions in the server.
This asynchronous server call will return before command is complete.
The user can optionally wait for command completion by using the returned
RemoveTask instance.
This method is only supported by Aerospike 3 servers.
429 430 431 432 433 434 435 436 437 438 439 440 441 442 |
# File 'lib/aerospike/client.rb', line 429 def remove_udf(udf_name, ={}) str_cmd = "udf-remove:filename=#{udf_name};" # Send command to one node. That node will distribute it to other nodes. # Send UDF to one node. That node will distribute the UDF to other nodes. response_map = @cluster.request_info(@default_policy, str_cmd) _, response = response_map.first if response == 'ok' UdfRemoveTask.new(@cluster, udf_name) else raise Aerospike::Exceptions::Aerospike.new(Aerospike::ResultCode::SERVER_ERROR, response) end end |
#request_info(*commands) ⇒ Object
593 594 595 |
# File 'lib/aerospike/client.rb', line 593 def request_info(*commands) @cluster.request_info(@default_policy, *commands) end |
#revoke_roles(user, roles, options = {}) ⇒ Object
Remove roles from user’s list of roles.
776 777 778 779 780 |
# File 'lib/aerospike/client.rb', line 776 def revoke_roles(user, roles, ={}) policy = create_policy(, AdminPolicy) command = AdminCommand.new command.revoke_roles(@cluster, policy, user, roles) end |
#scan_all(namespace, set_name, bin_names = [], options = {}) ⇒ Object
Scan Operations
601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 |
# File 'lib/aerospike/client.rb', line 601 def scan_all(namespace, set_name, bin_names=[], ={}) policy = create_policy(, ScanPolicy) # wait until all migrations are finished # TODO: implement # @cluster.WaitUntillMigrationIsFinished(policy.timeout) # Retry policy must be one-shot for scans. # copy on write for policy new_policy = policy.clone nodes = @cluster.nodes if nodes.empty? raise Aerospike::Exceptions::Aerospike.new(Aerospike::ResultCode::SERVER_NOT_AVAILABLE, "Scan failed because cluster is empty.") end recordset = Recordset.new(policy.record_queue_size, nodes.length, :scan) if policy.concurrent_nodes # Use a thread per node nodes.each do |node| Thread.new do Thread.current.abort_on_exception = true command = ScanCommand.new(node, new_policy, namespace, set_name, bin_names, recordset) begin execute_command(command) rescue => e Aerospike.logger.error(e.backtrace.join("\n")) unless e == SCAN_TERMINATED_EXCEPTION recordset.cancel(e) ensure recordset.thread_finished end end end else Thread.new do Thread.current.abort_on_exception = true nodes.each do |node| command = ScanCommand.new(node, new_policy, namespace, set_name, bin_names, recordset) begin execute_command(command) rescue => e Aerospike.logger.error(e.backtrace.join("\n")) unless e == SCAN_TERMINATED_EXCEPTION recordset.cancel(e) ensure recordset.thread_finished end end end end recordset end |
#scan_node(node, namespace, set_name, bin_names = [], options = {}) ⇒ Object
ScanNode reads all records in specified namespace and set, from one node only. The policy can be used to specify timeouts.
657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 |
# File 'lib/aerospike/client.rb', line 657 def scan_node(node, namespace, set_name, bin_names=[], ={}) policy = create_policy(, ScanPolicy) # wait until all migrations are finished # TODO: implement # @cluster.WaitUntillMigrationIsFinished(policy.timeout) # Retry policy must be one-shot for scans. # copy on write for policy new_policy = policy.clone new_policy.max_retries = 0 node = @cluster.get_node_by_name(node) unless node.is_a?(Aerospike::Node) recordset = Recordset.new(policy.record_queue_size, 1, :scan) Thread.new do Thread.current.abort_on_exception = true command = ScanCommand.new(node, new_policy, namespace, set_name, bin_names, recordset) begin execute_command(command) rescue => e Aerospike.logger.error(e.backtrace.join("\n")) unless e == SCAN_TERMINATED_EXCEPTION recordset.cancel(e) ensure recordset.thread_finished end end recordset end |
#supports_feature?(feature) ⇒ Boolean
96 97 98 |
# File 'lib/aerospike/client.rb', line 96 def supports_feature?(feature) @cluster.supports_feature?(feature) end |
#touch(key, options = {}) ⇒ Object
Examples:
client.touch key, :timeout => 0.001
250 251 252 253 254 |
# File 'lib/aerospike/client.rb', line 250 def touch(key, ={}) policy = create_policy(, WritePolicy) command = TouchCommand.new(@cluster, policy, key) execute_command(command) end |
#truncate(namespace, set_name = nil, before_last_update = nil, options = {}) ⇒ Object
Removes records in the specified namespace/set efficiently.
This method is orders of magnitude faster than deleting records one at a time. It requires Aerospike Server version 3.12 or later. See www.aerospike.com/docs/reference/info#truncate for further information.
This asynchronous server call may return before the truncate is complete. The user can still write new records after the server call returns because new records will have last update times greater than the truncate cut-off (set at the time of the truncate call.)
If no policy options are provided, @default_info_policy will be used.
224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/aerospike/client.rb', line 224 def truncate(namespace, set_name = nil, before_last_update = nil, = {}) policy = create_policy(, WritePolicy) str_cmd = "truncate:namespace=#{namespace}" str_cmd << ";set=#{set_name}" unless set_name.to_s.strip.empty? str_cmd << ";lut=#{(before_last_update.to_f * 1_000_000_000.0).round}" if before_last_update # Send index command to one node. That node will distribute the command to other nodes. response = send_info_command(policy, str_cmd).upcase return if response == 'OK' raise Aerospike::Exceptions::Aerospike.new(Aerospike::ResultCode::SERVER_ERROR, "Truncate failed: #{response}") end |