Is there a ping function to check the idle connection?

I did not found any api about this feature yet.
So if I need do it by myself, how to do it? Discover model method or ‘select 1 from *’ only work on RMDBS not on couchbase.

Hey @ChopperLee,

I’m a bit confused on what you’re trying to accomplish. Can you please tell me what your goals are and then I’ll try to help you further?

Best,

Sure. What I want is a api for check current connection instance status without create a new connection.
Example:
var bucket = cluster.openBucket();
now i have a connection in the memory, i want to have a api bucket.ping(cb) to get the connection status.
of course, i can do var checkBucketStatus = cluster.openBucket(); to open another connection in my memory to check the status, but it is not a good way, right?

I’m not entirely sure about the Node SDK, but IIRC IO links to the couchbase data service are only established when you get your Bucket instance.

So if you want to “check an existing connection status” then you’d have to have opened the bucket beforehand.
There’s not really an API to do that on Bucket, but you could try a get and see if it fails (eg. with a timeout)?

If you want to check that the node is reachable before opening the bucket, you’d have to resort to pinging the node(s) manually on port 8091 I guess…

Thanks for ur comments, i have considered of using ‘get()’ with current connection instance, but wondering to get what? In RMDBS i can do select 1 as result.

You could just get('1') (a “random” non-existing key). If it is reachable, the server will be able to quickly tell that no such document exist so the cost isn’t too high.

Some SDKs implement the exist(key) operation (which can be optimized over a fire-and-forget get(key)) but the Node SDK doesn’t seem to have it.

There is also a NOOP operation in the memcached protocol but it is not exposed in any way in the public API of the SDKs…

@brett is the exist operator planned in Node SDK? (maybe that could be a RFC, I think we may have just added it to .NET and Java)

Thanks a lot. BTW i use get(‘1’) instead of get(’’), cause get(’’) seem alway return ‘% empty key %’ staff. And my code work well now.

Great, I’ll edit my initial response to use a non-empty key and mark it as solution.