简体   繁体   English

node.js客户端的Aerospike同步get方法

[英]Aerospike synchronous get method for node.js client

在Aerospike for Node.js客户端中是否有任何同步数据库读写方法?

All the API calls in the Aerospike client client use an async. Aerospike客户端客户端中的所有API调用都使用异步。 pattern to connect, read data etc, this is to be expected in Node.js. 连接,读取数据等模式,这在Node.js中是可以预期的。

You can use the new (since Node 7.6) async/await keywords to allow code to be written in a more readable way though. 您可以使用新的(自Node 7.6)async / await关键字来允许以更易读的方式编写代码。 It is not synchronous (since testRead does not block) but it reads much more like synchronous code. 它不是同步的(因为testRead不会阻塞),但它更像是同步代码。

const Aerospike = require('aerospike')
var batchRecords = [
  { key: new Aerospike.Key('test', 'demo', 'key1'), bins: ['i', 's'] },
  { key: new Aerospike.Key('test', 'demo', 'key2'), read_all_bins: true },
  { key: new Aerospike.Key('test', 'demo', 'key3') }
];

async function testRead()
{
    var result = await readFromAerospike(batchRecords);
    console.log(result);
}

function readFromAerospike(batchRecords) {
   return new Promise((resolve, reject) => {
       Aerospike.connect((err, client) => {
          if (err) {
              reject(err);
          } else {
              client.batchRead(batchRecords, (err, results) => {
                  if (err) {
                      reject(err);
                  } else {
                      resolve(results);
                  }
              })
          }
       });
   });
}

testRead();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM