Build TOP Environments

For developer

Common

Synchronous and Asynchronous
About Classes

k2hash Class

k2hash::Create()
k2hash::Open()
k2hash::OpenRW()
k2hash::OpenRO()
k2hash::OpenTempfile()
k2hash::OpenMem()
k2hash::Close()
k2hash::GetValue()
k2hash::GetSubkeys()
k2hash::SetValue()
k2hash::AddSubkey()
k2hash::AddSubkeys()
k2hash::Remove()
k2hash::RemoveAll()
k2hash::PrintState()
k2hash::PrintVersion()
k2hash::DumpHead()
k2hash::DumpKeytable()
k2hash::DumpFullKeytable()
k2hash::DumpElementtable()
k2hash::DumpFull()
k2hash::Transaction()
k2hash::EnableTransaction()
k2hash::DisableTransaction()
k2hash::UnsetTransactionThreadPool()
k2hash::GetTransactionThreadPool()
k2hash::SetTransactionThreadPool()
k2hash::LoadArchive()
k2hash::PutArchive()
k2hash::SetCommonAttribute()
k2hash::CleanCommonAttribute()
k2hash::AddAttrPluginLib()
k2hash::AddAttrCryptPass()
k2hash::GetAttrVersionInfos()
k2hash::GetAttrInfos()
k2hash::GetAttrs()
k2hash::GetAttrValue()
k2hash::AddAttr()
k2hash::GetQueue()
k2hash::GetKeyQueue()

k2hqueue Class

k2hqueue::Init()
k2hqueue::Push()
k2hqueue::Count()
k2hqueue::IsEmpty()
k2hqueue::Read()
k2hqueue::Pop()
k2hqueue::Remove()
k2hqueue::Dump()

k2hkeyqueue Class

k2hkeyqueue::Init()
k2hkeyqueue::Push()
k2hkeyqueue::Count()
k2hkeyqueue::IsEmpty()
k2hkeyqueue::Read()
k2hkeyqueue::Pop()
k2hkeyqueue::Remove()
k2hkeyqueue::Dump()


Common

Synchronous and Asynchronous

The methods of the classes provided by K2HASH Node.js addon library support synchronous and asynchronous processing by specifying the callback function.
Methods that support asynchronous processing can accept the arguments of the callback function.
In addition, these can specify event handlers as on or onXXXXX as asynchronous processing.
Developers can perform asynchronous processing using callback functions or event handlers.
Callback function arguments and event handlers are not specified, these methods act as synchronization processes.

About Classes

K2HASH Node.js addon library provides k2hash class. The k2hqueue class and k2hKeyqueue class for manipulating the queue data provided by K2HASH are also provided. Objects of k2hqueue class and k2hKeyqueue class can be obtained from methods of k2hash class object using methods.


k2hash Class

This is the main class provided by K2HASH Node.js addon library. This class provides functions for manipulating K2HASH files and data in memory.

A sample to create this class object is shown below.

  var k2hobj = require('k2hash')();

or

  var k2hobj = new require('k2hash')();

Below are the methods of the k2hash class and those explanation.

k2hash::Create()

This method create and initialize a file of k2hash.

Format

bool Create(String   filename,
            int      maskbitcnt = 2,
            int      cmaskbitcnt = 4,
            int      maxelementcnt = 32,
            int      pagesize = 128,
            Callback cbfunc = null
)

Arguments

Return Values

This method returns success(true) or failure(false).
When callback function is specified, true value is always returned.

Examples

Event handlers

You can use asynchronous processing by implementing an event handler without using callback function.
Asynchronous processing can be described by the following two implementations.

k2hash::Open()

This method opens(attaches) a k2hash file.
If the k2hash file is not existed, this method creates it.

Format

bool Open(  String   filename,
            bool     readonly = false, 
            bool     removefile = false, 
            bool     fullmap = true, 
            int      maskbitcnt = 2, 
            int      cmaskbitcnt = 4, 
            int      maxelementcnt = 32, 
            int      pagesize = 128,
            Callback cbfunc = null
)

Arguments

Return Values

This method returns success(true) or failure(false).
When callback function is specified, true value is always returned.

Examples

Event handlers

You can use asynchronous processing by implementing an event handler without using callback function.
Asynchronous processing can be described by the following two implementations.

k2hash::OpenRW()

This method opens(attaches) a k2hash file for read/write mode.

Format

bool OpenRW(String   filename,
            bool     fullmap = true, 
            int      maskbitcnt = 2, 
            int      cmaskbitcnt = 4, 
            int      maxelementcnt = 32, 
            int      pagesize = 128,
            Callback cbfunc = null
)

Arguments

Return Values

This method returns success(true) or failure(false).
When callback function is specified, true value is always returned.

Examples

Event handlers

You can use asynchronous processing by implementing an event handler without using callback function.
Asynchronous processing can be described by the following two implementations.

k2hash::OpenRO()

This method opens(attaches) a k2hash file for read only mode.

Format

bool OpenRO(String   filename,
            bool     fullmap = true, 
            int      maskbitcnt = 2, 
            int      cmaskbitcnt = 4, 
            int      maxelementcnt = 32, 
            int      pagesize = 128,
            Callback cbfunc = null
)

Arguments

Return Values

This method returns success(true) or failure(false).
When callback function is specified, true value is always returned.

Examples

Event handlers

You can use asynchronous processing by implementing an event handler without using callback function.
Asynchronous processing can be described by the following two implementations.

k2hash::OpenTempfile()

This method opens(attaches) K2HASH file which is like temporary file.
The file is temporary, it means the file is removed automatically when close it.

Format

bool OpenTempfile(String   filename,
                  bool     fullmap = true, 
                  int      maskbitcnt = 2, 
                  int      cmaskbitcnt = 4, 
                  int      maxelementcnt = 32, 
                  int      pagesize = 128,
                  Callback cbfunc = null
)

Arguments

Return Values

This method returns success(true) or failure(false).
When callback function is specified, true value is always returned.

Examples

Event handlers

You can use asynchronous processing by implementing an event handler without using callback function.
Asynchronous processing can be described by the following two implementations.

k2hash::OpenMem()

This method opens(creates) K2HASH data in memory.

Format

bool OpenMem(	int      maskbitcnt = 2, 
                int      cmaskbitcnt = 4, 
                int      maxelementcnt = 32, 
                int      pagesize = 128,
                Callback cbfunc = null
)

Arguments

Return Values

This method returns success(true) or failure(false).
When callback function is specified, true value is always returned.

Examples

Event handlers

You can use asynchronous processing by implementing an event handler without using callback function.
Asynchronous processing can be described by the following two implementations.

k2hash::Close()

This method closes(detaches) the K2HASH file or data in memory.

Format

bool Close(Callback cbfunc = null)

Arguments

Return Values

This method returns success(true) or failure(false).
When callback function is specified, true value is always returned.

Examples

Event handlers

You can use asynchronous processing by implementing an event handler without using callback function.
Asynchronous processing can be described by the following two implementations.

k2hash::GetValue()

This method gets value for key.
If the subkey is specified, returns the value for subkey.
Then if the key does not have subkey, any value is returned.

Format

[bool/String] GetValue(  String   key,
                         String   subkey = "",
                         bool     attrcheck = true,
                         String   pass = "",
                         Callback cbfunc = null
)

Arguments

Return Values

Examples

Event handlers

You can use asynchronous processing by implementing an event handler without using callback function.
Asynchronous processing can be described by the following two implementations.

Notes

This method can specify keys and subkeys at the same time.
If you just read the value of the key, just specify the key name.
If you specify the key and subkey at the same time, you can read the value only when the subkey is tied to the key. If the subkey is not tied to a key, this method can not read the value and returns an error.

k2hash::GetSubkeys()

This method returns subkey list which are tied to the key.

Format

[bool/Array] GetSubkeys(String   key,
                        Callback cbfunc = null
)

Arguments

Return Values

Examples

Event handlers

You can use asynchronous processing by implementing an event handler without using callback function.
Asynchronous processing can be described by the following two implementations.

k2hash::SetValue()

This method sets a value to the key.

Format

bool SetValue(  String   key,
                String   value,
                String   subkey = null,
                String   pass = "",
                int      expire = 0,
                Callback cbfunc = null
)

Arguments

Return Values

This method returns success(true) or failure(false).
When callback function is specified, true value is always returned.

Examples

Event handlers

You can use asynchronous processing by implementing an event handler without using callback function.
Asynchronous processing can be described by the following two implementations.

k2hash::AddSubkey()

This method adds the subkey name into parent key’s subkey list.

Format

bool AddSubkey( String   key,
                String   subkey,
                String   value = null,
                Callback cbfunc = null
)

Arguments

Return Values

This method returns success(true) or failure(false).
When callback function is specified, true value is always returned.

Examples

Event handlers

You can use asynchronous processing by implementing an event handler without using callback function.
Asynchronous processing can be described by the following two implementations.

k2hash::AddSubkeys()

This method over writes parent key’s subkey list.
If the key has subkey list, the subkey list is removed and replaced by new subkey list.
Take care for that the replaced old subkey list, the old subkey is not removed from K2HASH, it is removed only the key’s subkey list.

Format

bool AddSubkeys(String   key,
                Array    subkeys,
                Callback cbfunc = null
)

Arguments

Return Values

This method returns success(true) or failure(false).
When callback function is specified, true value is always returned.

Examples

Event handlers

You can use asynchronous processing by implementing an event handler without using callback function.
Asynchronous processing can be described by the following two implementations.

k2hash::Remove()

This method removes the key or subkey.

Format

bool Remove(String   key,
            String   subkey,
            Callback cbfunc = null
)

Arguments

Return Values

This method returns success(true) or failure(false).
When callback function is specified, true value is always returned.

Examples

Event handlers

You can use asynchronous processing by implementing an event handler without using callback function.
Asynchronous processing can be described by the following two implementations.

Notes

This method can specify keys and subkeys at the same time.
If you specify only the key, that key will be removed.
If you specify a key and subkey, the subkey is removed and the key is not removed.
Then, the specified subkey is removed from the key subkey list.
If the specified subkey does not exist in the subkey list of the key, this method returns an error.

k2hash::RemoveAll()

This method removes the key and key’s all subkeys.
If the key has subkeys, all of the subkeys is removed.

Format

bool RemoveAll(String   key,
               Callback cbfunc = null
)

Arguments

Return Values

This method returns success(true) or failure(false).
When callback function is specified, true value is always returned.

Examples

Event handlers

You can use asynchronous processing by implementing an event handler without using callback function.
Asynchronous processing can be described by the following two implementations.

k2hash::PrintState()

This method puts the state of k2hash file or data in memory.

Format

bool PrintState(int fd = null)

Arguments

Return Values

This method returns success(true) or failure(false).

Examples

var k2hash = require('bindings')('k2hash');
var k2h = k2hash();

k2h.OpenMem();
k2h.PrintState();

k2h.Close();

k2hash::PrintVersion()

This method puts the version of k2hash libraries.

Format

bool PrintVersion(int fd = null)

Arguments

Return Values

This method returns success(true) or failure(false).

Examples

var k2hash = require('bindings')('k2hash');
var k2h = k2hash();

k2h.PrintVersion();

k2hash::DumpHead()

This method puts the result of dumpping head table of k2hash data.

Format

bool DumpHead(int fd = null)

Arguments

Return Values

This method returns success(true) or failure(false).

Examples

var k2hash = require('bindings')('k2hash');
var k2h = k2hash();

k2h.OpenMem();
k2h.DumpHead();

k2h.Close();

k2hash::DumpKeytable()

This method puts the result of dumpping key tables of k2hash data.

Format

bool DumpKeytable(int fd = null)

Arguments

Return Values

This method returns success(true) or failure(false).

Examples

var k2hash = require('bindings')('k2hash');
var k2h = k2hash();

k2h.OpenMem();
k2h.DumpKeytable();

k2h.Close();

k2hash::DumpFullKeytable()

This method puts the result of full dumpping key tables of k2hash data.

Format

bool DumpFullKeytable(int fd = null)

Arguments

Return Values

This method returns success(true) or failure(false).

Examples

var k2hash = require('bindings')('k2hash');
var k2h = k2hash();

k2h.OpenMem();
k2h.DumpFullKeytable();

k2h.Close();

k2hash::DumpElementtable()

This method puts the result of dumpping all elements data of k2hash data.

Format

bool DumpElementtable(int fd = null)

Arguments

Return Values

This method returns success(true) or failure(false).

Examples

var k2hash = require('bindings')('k2hash');
var k2h = k2hash();

k2h.OpenMem();
k2h.DumpElementtable();

k2h.Close();

k2hash::DumpFull()

This method puts the result of dumpping all data of k2hash data.

Format

bool DumpFull(int fd = null)

Arguments

Return Values

This method returns success(true) or failure(false).

Examples

var k2hash = require('bindings')('k2hash');
var k2h = k2hash();

k2h.OpenMem();
k2h.DumpFull();

k2h.Close();

k2hash::Transaction()

This method enables/disables transaction for k2hash.

Format

bool Transaction(bool   enable,
                 String transfile = "",
                 String prefix = "",
                 String param = "",
                 int    expire = 0
)

Arguments

Return Values

This method returns success(true) or failure(false).

Examples

var k2hash = require('bindings')('k2hash');
var k2h = k2hash();

k2h.OpenMem();
k2h.Transaction(true, 'my.tr', 'tr_prefix_', '', 10);

k2h.Close();

k2hash::EnableTransaction()

This method enables transaction.

Format

bool EnableTransaction(String transfile = "",
                       String prefix = "",
                       String param = "",
                       int    expire = 0
)

Arguments

Return Values

This method returns success(true) or failure(false).

Examples

var k2hash = require('bindings')('k2hash');
var k2h = k2hash();

k2h.OpenMem();
k2h.EnableTransaction('my.tr', 'tr_prefix_', '', 10);

k2h.Close();

k2hash::DisableTransaction()

This method disables transaction.

Format

bool DisableTransaction(void)

Arguments

n/a

Return Values

This method returns success(true) or failure(false).

Examples

var k2hash = require('bindings')('k2hash');
var k2h = k2hash();

k2h.OpenMem();
k2h.DisableTransaction();

k2h.Close();

k2hash::UnsetTransactionThreadPool()

This method clears transaction thread pool.

Format

bool UnsetTransactionThreadPool(void)

Arguments

n/a

Return Values

This method returns success(true) or failure(false).
If transactions are enabled, this method will fail.

Examples

var k2hash = require('bindings')('k2hash');
var k2h = k2hash();

k2h.OpenMem();
k2h.DisableTransaction();
k2h.UnsetTransactionThreadPool();
k2h.EnableTransaction('my.tr', 'tr_prefix_', '', 10);

k2h.Close();

k2hash::GetTransactionThreadPool()

This method returns transaction thread pool count.

Format

int GetTransactionThreadPool(void)

Arguments

n/a

Return Values

The count of transaction thread pool.

Examples

var k2hash = require('bindings')('k2hash');
var k2h = k2hash();

k2h.OpenMem();
var pools = k2h.GetTransactionThreadPool();

k2h.Close();

k2hash::SetTransactionThreadPool()

This method sets the thransaction thread count.

Format

bool SetTransactionThreadPool(int count)

Arguments

Return Values

This method returns success(true) or failure(false).
If transactions are enabled, this method will fail.

Examples

var k2hash = require('bindings')('k2hash');
var k2h = k2hash();

k2h.OpenMem();
k2h.DisableTransaction();
k2h.SetTransactionThreadPool(10);
k2h.EnableTransaction('my.tr', 'tr_prefix_', '', 10);

k2h.Close();

k2hash::LoadArchive()

This method loads K2HASH data from archive file.
If there is same key name in archive file, the key is over wrote.
The archive file is made by PutArchive() function.

Format

bool LoadArchive(String   filename,
                 bool     errskip = true,
                 Callback cbfunc = null
)

Arguments

Return Values

This method returns success(true) or failure(false).
When callback function is specified, true value is always returned.

Examples

Event handlers

You can use asynchronous processing by implementing an event handler without using callback function.
Asynchronous processing can be described by the following two implementations.

k2hash::PutArchive()

This method puts(serializes) all of K2HASH data to file.
The archive file which is made by this method can be loaded by LoadArchive()

Format

bool PutArchive(String   filename,
                 bool     errskip = true,
                 Callback cbfunc = null
)

Arguments

Return Values

This method returns success(true) or failure(false).
When callback function is specified, true value is always returned.

Examples

Event handlers

You can use asynchronous processing by implementing an event handler without using callback function.
Asynchronous processing can be described by the following two implementations.

k2hash::SetCommonAttribute()

This method sets builtin attributes for K2HASH.
The bultin attributes are mtime/history/expire/encrypt(and pass phrease)

Format

bool SetCommonAttribute(int    is_mtime = -1, 
                        int    is_history = -1, 
                        int    is_encrypt = -1, 
                        String passfile = "", 
                        int    is_expire = -1, 
                        int    expire = 0
)

Arguments

Return Values

This method returns success(true) or failure(false).

Examples

var k2hash = require('bindings')('k2hash');
var k2h = k2hash();

k2h.OpenMem();
k2h.setCommonAttribute(1, 1, 0, 'mypassphrase', 1, 100);

k2h.Close();

k2hash::CleanCommonAttribute()

This method clears bultin attribute setting(to default).

Format

bool SetCommonAttribute(void)

Arguments

n/a

Return Values

This method returns success(true) or failure(false).

Examples

var k2hash = require('bindings')('k2hash');
var k2h = k2hash();

k2h.OpenMem();
k2h.cleanCommonAttribute();

k2h.Close();

k2hash::AddAttrPluginLib()

This method loads custom attribute lugin(library).

Format

bool AddAttrPluginLib(String libfile)

Arguments

Return Values

This method returns success(true) or failure(false).

Examples

var k2hash = require('bindings')('k2hash');
var k2h = k2hash();

k2h.OpenMem();
k2h.addAttrPluginLib('myattrlib.so');

k2h.Close();

k2hash::AddAttrCryptPass()

This method sets pass phrase for builtin attribute encrypting.

Format

bool AddAttrCryptPass(String encpass,
                      bool   is_default_encrypt = false
)

Arguments

Return Values

This method returns success(true) or failure(false).

Examples

var k2hash = require('bindings')('k2hash');
var k2h = k2hash();

k2h.OpenMem();
k2h.k2h.addAttrCryptPass('passphrase', true);

k2h.Close();

Notes

Set pass phrase and enable/disable the default encrypting.
If the default encrypting is disabled with pass phrase, it means that do only decrypting.

k2hash::GetAttrVersionInfos()

This method puts Attribute plugin version(with builtin attribute).

Format

bool GetAttrVersionInfos(int fd = null)

Arguments

Return Values

This method returns success(true) or failure(false).

Examples

var k2hash = require('bindings')('k2hash');
var k2h = k2hash();

k2h.OpenMem();
k2h.GetAttrVersionInfos();

k2h.Close();

k2hash::GetAttrInfos()

This method puts builtin attribute information.

Format

bool GetAttrInfos(int fd = null)

Arguments

Return Values

This method returns success(true) or failure(false).

Examples

var k2hash = require('bindings')('k2hash');
var k2h = k2hash();

k2h.OpenMem();
k2h.GetAttrInfos();

k2h.Close();

k2hash::GetAttrs()

This method gets attribute keys.
If the callback function is specified, or on callback handles for this,
this method works asynchronization and calls callback function at finishing.

Format

Array GetAttrs(String   key,
               Callback cbfunc = null
)

Arguments

Return Values

This method returns success(true) or failure(false).
When callback function is specified, true value is always returned.

Examples

Event handlers

You can use asynchronous processing by implementing an event handler without using callback function.
Asynchronous processing can be described by the following two implementations.

k2hash::GetAttrValue()

This method gets value by attribute key.
If the callback function is specified, or on callback handles for this, this method works asynchronization and calls callback function at finishing.

Format

Array GetAttrValue(String   key,
                   String   attrkey,
                   Callback cbfunc = null
)

Arguments

Return Values

This method returns success(true) or failure(false).
When callback function is specified, true value is always returned.

Examples

Event handlers

You can use asynchronous processing by implementing an event handler without using callback function.
Asynchronous processing can be described by the following two implementations.

k2hash::AddAttr()

This method adds the attribute to the key.
If the callback function is specified, or on callback handles for this, this method works asynchronization and calls callback function at finishing.

Format

Array AddAttr(String   key,
              String   attrkey,
              String   attrval = null,
              Callback cbfunc = null
)

Arguments

Return Values

This method returns success(true) or failure(false).
When callback function is specified, true value is always returned.

Examples

Event handlers

You can use asynchronous processing by implementing an event handler without using callback function.
Asynchronous processing can be described by the following two implementations.

k2hash::GetQueue()

This method returns k2hqueue class object which accesses this object.
You can specify the type of queue(FIFO/LIFO) and prefix of queue key name.

Format

object GetQueue(bool   is_fifo = true
              String prefix = null
)

Arguments

Return Values

If success, k2hqueue class object is returned.
If an error occurs, null is returned.

Examples

var k2hash = require('bindings')('k2hash');
var k2h = k2hash();

k2h.OpenMem();
var k2hq = k2h.GetQueue();

k2h.Close();

k2hash::GetKeyQueue()

This method returns k2hkeyqueue class object which accesses this object.
You can specify the type of queue(FIFO/LIFO) and prefix of queue key name.

Format

object GetKeyQueue(bool   is_fifo = true
                   String prefix = null
)

Arguments

Return Values

If success, k2hkeyqueue class object is returned.
If an error occurs, null is returned.

Examples

var k2hash = require('bindings')('k2hash');
var k2h = k2hash();

k2h.OpenMem();
var k2hkq = k2h.GetKeyQueue();

k2h.Close();

k2hqueue Class

This class object can be obtained from the k2hash class object of the main class provided by K2HASH Node.js addon library.
This class allows you to manipulate the queue data in K2HASH files or in memory.

To create this class, specify it as follows.

  var k2hash = require('bindings')('k2hash');
  var k2h = k2hash();
  
  k2h.OpenMem();
  var k2hq = k2h.GetQueue();
  
  k2h.Close();

Below are the methods of the k2hqueue class and their explanation.

k2hqueue::Init()

This method initializes k2hqueue object with k2hash object.

Format

bool Init(object k2hhash,
          bool   is_fifo = true,
          String prefix = null,
)

Arguments

Return Values

This method returns success(true) or failure(false).

Examples

var k2hash = require('bindings')('k2hash');
var k2h = k2hash();

k2h.Create('test.k2h');
var k2hq = k2h.GetQueue();

k2hq.Init(k2h, true, 'queue_prefix_');

k2h.Close();

k2hqueue::Push()

This method pushs data to queue.

Format

bool Push(String    data,
          String    pass = "",
          int       expire = 0,
          Callback cbfunc = null
)

Arguments

Return Values

This method returns success(true) or failure(false).
When callback function is specified, true value is always returned.

Examples

Event handlers

You can use asynchronous processing by implementing an event handler without using callback function.

k2hqueue::Count()

This method gets queue count.

Format

int Count(Callback cbfunc = null)

Arguments

Return Values

The count of queue is returned, if something error occurred, returns 0. When callback function is specified, true value is always returned.

Examples

Event handlers

You can use asynchronous processing by implementing an event handler without using callback function.

k2hqueue::IsEmpty()

This method tests for the queue is empty.

Format

bool IsEmpty(void)

Arguments

なし

Return Values

This method returns success(true) or failure(false).

Examples

var k2hash = require('bindings')('k2hash');
var k2h = k2hash();

k2h.Create('test.k2h');
var k2hq = k2h.GetQueue();
k2hq.Init(k2h, true, 'queue_prefix_');

k2hq.IsEmpty();

k2h.Close();

k2hqueue::Read()

This method reads queue data at queue position.
Not remove the data from queue after reading.
Take care for pareformance, because k2hash library uses liner search for this function.

Format

[bool/String] Read(int      pos = 0,
                   String   pass ="",
                   Callback cbfunc = null
)

Arguments

Return Values

Returns the data which are queued.
If there is no data in queue or something error is occurred, returns null.
When callback function is specified, true value is always returned.

Examples

Event handlers

You can use asynchronous processing by implementing an event handler without using callback function.

k2hqueue::Pop()

The method pops queue data and removes the data from queue after popping.

Format

[bool/String] Pop(String   pass ="",
                  Callback cbfunc = null
)

Arguments

Return Values

Returns the data which are queued.
If there is no data in queue or something error is occurred, returns null.
When callback function is specified, true value is always returned.

Examples

Event handlers

You can use asynchronous processing by implementing an event handler without using callback function.

k2hqueue::Remove()

This method removes count of queue datas, and not return any datas which are removed.

Format

int Remove(int      count
           String   pass ="",
           Callback cbfunc = null
)

Arguments

Return Values

If success, returns removed queue count.
If failure, returns -1.
If the count is specified over queuing count, the queue is empty and returns removing count.
When callback function is specified, true value is always returned.

Examples

Event handlers

You can use asynchronous processing by implementing an event handler without using callback function.

k2hqueue::Dump()

This method dumps all queue data.

Format

int Dump(int fd = null)

Arguments

Return Values

This method returns success(true) or failure(false).

Examples

var k2hash = require('bindings')('k2hash');
var k2h = k2hash();

k2h.Create('test.k2h');
var k2hq = k2h.GetQueue();
k2hq.Init(k2h, true, 'queue_prefix_');

k2hq.Dump();

k2h.Close();

k2hkeyqueue Class

This class object can be obtained from the k2hash class object of the main class provided by K2HASH Node.js addon library.
This class allows you to manipulate the key queue data in K2HASH files or in memory.

To create this class, specify it as follows.

  var k2hash = require('bindings')('k2hash');
  var k2h = k2hash();
  
  k2h.OpenMem();
  var k2hkq = k2h.GetKeyQueue();
  
  k2h.Close();

Below are the methods of the k2hkeyqueue class and their explanation.

k2hkeyqueue::Init()

This method initializes k2hkeyqueue object with k2hash object.

Format

bool Init(object k2hhash,
          bool   is_fifo = true,
          String prefix = null,
)

Arguments

Return Values

This method returns success(true) or failure(false).

Examples

var k2hash = require('bindings')('k2hash');
var k2h = k2hash();

k2h.Create('test.k2h');
var k2hkq = k2h.GetKeyQueue();

k2hkq.Init(k2h, true, 'keyqueue_prefix_');

k2h.Close();

k2hkeyqueue::Push()

This method pushs data to queue.

Format

bool Push(String    key,
          String    val,
          String    pass = "",
          int       expire = 0,
          Callback cbfunc = null
)

Arguments

Return Values

This method returns success(true) or failure(false).
When callback function is specified, true value is always returned.

Examples

Event handlers

You can use asynchronous processing by implementing an event handler without using callback function.

k2hkeyqueue::Count()

This method gets queue count.

Format

int Count(Callback cbfunc = null)

Arguments

Return Values

The count of queue is returned, if something error occurred, returns 0. When callback function is specified, true value is always returned.

Examples

Event handlers

You can use asynchronous processing by implementing an event handler without using callback function.

k2hkeyqueue::IsEmpty()

This method tests for the queue is empty.

Format

bool IsEmpty(void)

Arguments

なし

Return Values

This method returns success(true) or failure(false).

Examples

var k2hash = require('bindings')('k2hash');
var k2h = k2hash();

k2h.Create('test.k2h');
var k2hkq = k2h.GetKeyQueue();
k2hkq.Init(k2h, true, 'keyqueue_prefix_');

k2hkq.IsEmpty();

k2h.Close();

k2hkeyqueue::Read()

This method reads queue data at queue position.
Not remove the data from queue after reading.
Take care for pareformance, because k2hash library uses liner search for this function.

Format

[bool/Array] Read(int      pos = 0,
                  String   pass ="",
                  Callback cbfunc = null
)

Arguments

Return Values

Returns the array for key and value which are queued. If there is no data in queue or something error is occurred, returns null.
When callback function is specified, true value is always returned.

Examples

Event handlers

You can use asynchronous processing by implementing an event handler without using callback function.

k2hkeyqueue::Pop()

The method pops queue data and removes the data from queue after popping.

Format

[bool/Array] Pop(String   pass ="",
                 Callback cbfunc = null
)

Arguments

Return Values

Returns the array for key and value which are queued. If there is no data in queue or something error is occurred, returns null.
When callback function is specified, true value is always returned.

Examples

Event handlers

You can use asynchronous processing by implementing an event handler without using callback function.

k2hkeyqueue::Remove()

This method removes count of queue datas, and not return any datas which are removed.

Format

int Remove(int      count
           String   pass ="",
           Callback cbfunc = null
)

Arguments

Return Values

If success, returns removed queue count.
If failure, returns -1.
If the count is specified over queuing count, the queue is empty and returns removing count.
When callback function is specified, true value is always returned.

Examples

Event handlers

You can use asynchronous processing by implementing an event handler without using callback function.

k2hkeyqueue::Dump()

This method dumps all queue data.

Format

int Dump(int fd = null)

Arguments

Return Values

This method returns success(true) or failure(false).

Examples

var k2hash = require('bindings')('k2hash');
var k2h = k2hash();

k2h.Create('test.k2h');
var k2hkq = k2h.GetKeyQueue();
k2hkq.Init(k2h, true, 'keyqueue_prefix_');

k2hkq.Dump();

k2h.Close();
Build TOP Environments