Object built-in object

Object RedisHash

Redis database client Hash object, this object is the client that contains the specified key, and the database can be operated only by calling its method

The Hash object used to manipulate Redis , the creation method:

1 2 3
var db = require("db"); var rdb = new db.openRedis("redis-server"); var hash = rdb.getHash("test");

Inheritance

Member function

set

Set the value of the field field in the hash table to value. If the field field already exists in the hash table, the old value will be overwritten

1 2
RedisHash.set(Buffer field, Buffer value);

Call parameters:

  • field : Buffer , specify the field to be modified
  • value : Buffer , specify the data to be modified

setNX

Set the value of the field in the hash table to value if and only if the field does not exist. If the field already exists, this operation is invalid

1 2
RedisHash.setNX(Buffer field, Buffer value);

Call parameters:

  • field : Buffer , specify the field to be modified
  • value : Buffer , specify the data to be modified

mset

Set multiple field-value (domain-value) pairs to the hash table at the same time, this command will overwrite the existing fields in the hash table

1
RedisHash.mset(Object kvs);

Call parameters:

  • kvs : Object, specify the field/value object to be set

Set multiple field-value (domain-value) pairs to the hash table at the same time, this command will overwrite the existing fields in the hash table

1
RedisHash.mset(...kvs);

Call parameters:

  • kvs : ..., specify the field/value list to be set

get

Returns the value of the given field in the hash table

1
Buffer RedisHash.get(Buffer field);

Call parameters:

  • field : Buffer , specify the field to be queried

Return result:

  • Buffer , the value of the given field, when the given field does not exist or the given key does not exist, return null

mget

Returns the value of one or more given fields in the hash table

1
NArray RedisHash.mget(Array fields);

Call parameters:

  • fields : Array, specify the field array to be queried

Return result:

  • NArray , a list containing all the values ​​of a given field

Returns the value of one or more given fields in the hash table

1
NArray RedisHash.mget(...fields);

Call parameters:

  • fields : ..., specify the list of fields to be queried

Return result:

  • NArray , a list containing all the values ​​of a given field

incr

Add the increment to the value stored in the field

1 2
Long RedisHash.incr(Buffer field, Long num = 1);

Call parameters:

  • field : Buffer , specify the field to be modified
  • num : Long, specify the value to be added

Return result:

  • Long , after adding num, the value of the domain

getAll

Return all fields and values ​​in the hash table

1
NArray RedisHash.getAll();

Return result:

  • NArray , returns a list containing all fields in the hash table

keys

Return all fields in the hash table

1
NArray RedisHash.keys();

Return result:

  • NArray , in the return value, immediately after each field name is the value of the field, so the length of the return value is twice the size of the hash table

len

Returns the number of fields in the hash table

1
Integer RedisHash.len();

Return result:

  • Integer , returns the number of fields in the hash table

exists

Check whether the given field exists in the hash table

1
Boolean RedisHash.exists(Buffer field);

Call parameters:

  • field : Buffer , specify the field to be queried

Return result:

  • Boolean , if the hash table contains the given field, return true, if the hash table does not contain the given field, or the key does not exist, return false

del

Delete one or more specified domains in the hash table, domains that do not exist will be ignored

1
Integer RedisHash.del(Array fields);

Call parameters:

  • fields : Array, specify the field array to be deleted

Return result:

  • Integer , the number of deleted domains

Delete one or more specified domains in the hash table, domains that do not exist will be ignored

1
Integer RedisHash.del(...fields);

Call parameters:

  • fields : ..., specify the list of fields to be deleted

Return result:

  • Integer , the number of deleted domains

toString

Returns the string representation of the object, generally returns "[Native Object]", the object can be re-implemented according to its own characteristics

1
String RedisHash.toString();

Return result:

  • String , returns the string representation of the object

toJSON

Returns the JSON format representation of the object, generally returns a collection of readable attributes defined by the object

1
Value RedisHash.toJSON(String key = "");

Call parameters:

  • key : String, unused

Return result:

  • Value , returns a value containing JSON serializable