Redis - set Operation Command

Collection types set

redis Set of unordered collection of type string, is the only member of the collection, that duplication of data collection can not appear

 

Collection type set - Common Commands

sadd /smembers /sismember /scard /srem /srandmember /spop

sadd

语法:sadd key member [member…]

effect:

One or more elements to a set of key member which,

Already exist in the member elements of the set will be ignored and will not join.

Return Value: the number of new elements added to the collection. It does not include the neglected element.

 

smembers

Syntax: smembers key

Role: Get all the members of key elements in the collection, regarded as non-existent key empty set

 

sismember

语法:sismember key member

Role: to determine whether the element is a member of a collection of key members

Return value: member is a set of member returns 1, else return 0

 

scard

Syntax: scard key

Action: Get the number of elements inside the collection

Return Value: the number of elements numbers, key in. Otherwise return 0

 

srem

语法:srem key member [member…]

Role: delete a collection of one or more member elements key in, there is no element is ignored.

Returns: the number of elements of digital, successfully removed, excluding overlooked element.

 

srandmember

Syntax: srandmember key [count]

effect:

Only key, random returns a collection element, the element is not deleted, still in the collection;

Providing a count, count the number of positive, returns the set count number of elements comprising a set element varies.

count is negative, returns a count of the absolute value of the set length, the collection element may be repeated several times.

Returns: an element; a plurality of collection elements

 

spop

Syntax: spop key [count]

Role: random delete an element from the collection, count is the number of elements that were removed.

Returns: deleted elements, key does not exist or empty collection returns nil

 

Guess you like

Origin www.cnblogs.com/dyd520/p/11480795.html