如何解决 Aerospike::Exceptions::Aerospike:Ruby 客户端不支持的服务器功能?

How to resolve Aerospike::Exceptions::Aerospike: Unsupported Server Feature for Ruby Client?

当我尝试使用 ruby 客户端写入 aerospike 时,出现以下异常:-

Aerospike::异常::Aerospike:不支持的服务器功能

详情:-

Aerospike version:- 4.3
Client: [Ruby] aerospike - 2.4.0
namespaces: NS1, NS2, NS3 

注:NS2和NS3有single-bin true data-in-index true

代码(导致异常):-

client = Aerospike::Client.new('aerospike:3000')
key = Aerospike::Key.new('NS2', 'set name', 'this is the key')
data = { 'record'  => 1 }
client.put(key, data) # this line raises the exception
Aerospike::Exceptions::Aerospike: Unsupported Server Feature

如果我将密钥中的 NS2 更改为 NS1,则不会引发异常。

您收到的"Unsupported Server Feature"错误是因为Ruby客户端默认将用户密钥发送到服务器,但Aerospike服务器不支持存储数据的用户密钥-内存中和单仓设置。您应该会在服务器日志中看到这样的错误消息:

Sep 13 2018 02:42:20 GMT: WARNING (rw): (rw_utils.c:153) {sbin} can't store key if data-in-memory & single-bin

您需要通过将 send_key 写入策略设置为 false:

来禁用发送密钥作为放置请求的一部分
$ bundle exec irb
2.5.0 :001 > require 'aerospike'; include Aerospike;
 => Object
2.5.0 :002 > client = Client.new; key = Key.new('sbin', 'test', 'foo'); nil
 => nil
2.5.0 :003 > client.put(key, Bin.new('', 42), send_key: false)
 => nil
2.5.0 :004 > client.get(key).bins['']
 => 42