Object built-in object

Object RedisSet

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

Set object used to manipulate Redis , creation method:

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

Inheritance

Member function

add

Add one or more member elements to the set key, the member elements that already exist in the set will be ignored

1
Integer RedisSet.add(Array members);

Call parameters:

  • members : Array, specify the array of elements to be added

Return result:

  • Integer , the number of new elements added to the set, excluding ignored elements

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
Integer RedisSet.add(...members);

Call parameters:

  • members : ..., specify the list of elements to be added

Return result:

  • Integer , the number of new elements added to the set, excluding ignored elements

remove

Remove one or more member elements from the collection

1
Integer RedisSet.remove(Array members);

Call parameters:

  • members : Array, specify the array of elements to be removed

Return result:

  • Integer , the number of elements successfully removed, excluding ignored elements

Remove one or more member elements from the collection

1
Integer RedisSet.remove(...members);

Call parameters:

  • members : ..., specify the list of elements to be removed

Return result:

  • Integer , the number of elements successfully removed, not including ignored elements

len

Returns the number of elements in the collection

1
Integer RedisSet.len();

Return result:

  • Integer , returns the length of the collection

exists

Determine whether the member element is a member of the collection

1
Boolean RedisSet.exists(Buffer member);

Call parameters:

  • member : Buffer , specify the member to check

Return result:

  • Boolean , if the member element is a member of the collection, return true

members

Return all members in the collection

1
NArray RedisSet.members();

Return result:

  • NArray , a list of all members in the collection

pop

Remove and return a random element in the set

1
Buffer RedisSet.pop();

Return result:

  • Buffer , the random element to be removed. When the set is empty, return null

randMember

Get a random element from the set

1
Value RedisSet.randMember();

Return result:

  • Value , returns an element; if the collection is empty, returns null

Get some random elements from the set

1
Value RedisSet.randMember(Integer count);

Call parameters:

  • count : Integer, specifies the number of elements returned. Positive number, return an array containing count elements; negative number, return an array, the elements in the array may repeat multiple times, and the length of the array is the absolute value of count

Return result:

  • Value , returns a list; if the collection is empty, returns an empty list

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 RedisSet.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 RedisSet.toJSON(String key = "");

Call parameters:

  • key : String, unused

Return result:

  • Value , returns a value containing JSON serializable