sAdd 命令/方法/函數 Adds a value to the set value stored at key. If this value is already in the set, FALSE is returned. 添加一個VALUE到SET容器中,若是這個VALUE已經存在於SET中,那麼返回FLASE。 Parameters key value Return value BOOL TRUE if value didn't exist and was added successfully, FALSE if the value is already present. 若是VALUE不存在於SET中,那麼ADDED成功,返回TRUE,負責返回FALSE。 Example $redis->sAdd('key1' , 'member1'); /* TRUE, 'key1' => {'member1'} */ $redis->sAdd('key1' , 'member2'); /* TRUE, 'key1' => {'member1', 'member2'}*/ $redis->sAdd('key1' , 'member2'); /* FALSE, 'key1' => {'member1', 'member2'}*/
sRem 命令/方法/函數 Removes the specified member from the set value stored at key. 移除指定的VALUE從SET容器中 Parameters key member Return value BOOL TRUE if the member was present in the set, FALSE if it didn't. Example $redis->sAdd('key1' , 'member1'); $redis->sAdd('key1' , 'member2'); $redis->sAdd('key1' , 'member3'); /* 'key1' => {'member1', 'member2', 'member3'}*/ $redis->sRem('key1', 'member2'); /* 'key1' => {'member1', 'member3'} */
sMove 命令/方法/函數 Moves the specified member from the set at srcKey to the set at dstKey. 移動一個指定的MEMBER從源SET到指定的另外一個SET中。 Parameters srcKey dstKey member Return value BOOL If the operation is successful, return TRUE. If the srcKey and/or dstKey didn't exist, and/or the member didn't exist in srcKey,FALSE is returned. 若是操做成功返回TRUE,若是源SET或者目標SET不存在,或者MEMBER不存在於源SET,那麼返回FLASE。 Example $redis->sAdd('key1' , 'member11'); $redis->sAdd('key1' , 'member12'); $redis->sAdd('key1' , 'member13'); /* 'key1' => {'member11', 'member12', 'member13'}*/ $redis->sAdd('key2' , 'member21'); $redis->sAdd('key2' , 'member22'); /* 'key2' => {'member21', 'member22'}*/ $redis->sMove('key1', 'key2', 'member13'); /* 'key1' => {'member11', 'member12'} */ /* 'key2' => {'member21', 'member22', 'member13'} */
sIsMember 命令/方法/函數 Checks if value is a member of the set stored at the key key. 檢查VALUE是不是SET容器中的成員。 Parameters key value Return value BOOL TRUE if value is a member of the set at key key, FALSE otherwise. Example $redis->sAdd('key1' , 'member1'); $redis->sAdd('key1' , 'member2'); $redis->sAdd('key1' , 'member3'); /* 'key1' => {'member1', 'member2', 'member3'}*/ $redis->sIsMember('key1', 'member1'); /* TRUE */ $redis->sIsMember('key1', 'memberX'); /* FALSE */
sCard 命令/方法/函數 Returns the cardinality of the set identified by key. 返回SET容器的成員數 Parameters key Return value LONG the cardinality of the set identified by key, 0 if the set doesn't exist. Example $redis->sAdd('key1' , 'member1'); $redis->sAdd('key1' , 'member2'); $redis->sAdd('key1' , 'member3'); /* 'key1' => {'member1', 'member2', 'member3'}*/ $redis->sCard('key1'); /* 3 */ $redis->sCard('keyX'); /* 0 */
sPop 命令/方法/函數 Removes and returns a random element from the set value at Key. 隨機返回一個元素,而且在SET容器中移除該元素。 Parameters key Return value String "popped" value Bool FALSE if set identified by key is empty or doesn't exist. Example $redis->sAdd('key1' , 'member1'); $redis->sAdd('key1' , 'member2'); $redis->sAdd('key1' , 'member3'); /* 'key1' => {'member3', 'member1', 'member2'}*/ $redis->sPop('key1'); /* 'member1', 'key1' => {'member3', 'member2'} */ $redis->sPop('key1'); /* 'member3', 'key1' => {'member2'} */
sRandMember 命令/方法/函數 Returns a random element from the set value at Key, without removing it. 取得指定SET容器中的一個隨機元素,但不會在SET容器中移除它。 Parameters key Return value String value from the set Bool FALSE if set identified by key is empty or doesn't exist. Example $redis->sAdd('key1' , 'member1'); $redis->sAdd('key1' , 'member2'); $redis->sAdd('key1' , 'member3'); /* 'key1' => {'member3', 'member1', 'member2'}*/ $redis->sRandMember('key1'); /* 'member1', 'key1' => {'member3', 'member1', 'member2'} */ $redis->sRandMember('key1'); /* 'member3', 'key1' => {'member3', 'member1', 'member2'} */
sInter 命令/方法/函數 Returns the members of a set resulting from the intersection of all the sets held at the specified keys. If just a single key is specified, then this command produces the members of this set. If one of the keys is missing, FALSE is returned. 返回指定SETS集合的交集結果。若是隻是指定了一個SET集合,那麼返回該SET集合。若是在參數中有參數錯誤,那麼則返回FLASE。 Parameters key1, key2, keyN: keys identifying the different sets on which we will apply the intersection. 參數列表,表明不一樣的SET集合。 Return value Array, contain the result of the intersection between those keys. If the intersection beteen the different sets is empty, the return value will be empty array. 返回數組,數組中的結果爲全部SET集合的交集。若是所涉及到的SET集合沒有交集結果,那麼將返回一個空數組。 Examples $redis->sAdd('key1', 'val1'); $redis->sAdd('key1', 'val2'); $redis->sAdd('key1', 'val3'); $redis->sAdd('key1', 'val4'); $redis->sAdd('key2', 'val3'); $redis->sAdd('key2', 'val4'); $redis->sAdd('key3', 'val3'); $redis->sAdd('key3', 'val4'); var_dump($redis->sInter('key1', 'key2', 'key3')); Output: array(2) { [0]=> string(4) "val4" [1]=> string(4) "val3" }
sInterStore 命令/方法/函數 Performs a sInter command and stores the result in a new set. 執行一個交集操做,並把結果存儲到一個新的SET容器中。 Parameters Key: dstkey, the key to store the diff into. key 儲存結果的SET容器KEY Keys: key1, key2... keyN. key1..keyN are intersected as in sInter. 求交集的KEYS Return value INTEGER: The cardinality of the resulting set, or FALSE in case of a missing key. Example $redis->sAdd('key1', 'val1'); $redis->sAdd('key1', 'val2'); $redis->sAdd('key1', 'val3'); $redis->sAdd('key1', 'val4'); $redis->sAdd('key2', 'val3'); $redis->sAdd('key2', 'val4'); $redis->sAdd('key3', 'val3'); $redis->sAdd('key3', 'val4'); var_dump($redis->sInterStore('output', 'key1', 'key2', 'key3')); var_dump($redis->sMembers('output')); Output: int(2) array(2) { [0]=> string(4) "val4" [1]=> string(4) "val3" }
sUnion 命令/方法/函數 Performs the union between N sets and returns it. 執行一個並集操做在N個SET容器之間,並返回結果。 Parameters Keys: key1, key2, ... , keyN: Any number of keys corresponding to sets in redis. Return value Array of strings: The union of all these sets. 返回一個數組 Example $redis->delete('s0', 's1', 's2'); $redis->sAdd('s0', '1'); $redis->sAdd('s0', '2'); $redis->sAdd('s1', '3'); $redis->sAdd('s1', '1'); $redis->sAdd('s2', '3'); $redis->sAdd('s2', '4'); var_dump($redis->sUnion('s0', 's1', 's2')); Return value: all elements that are either in s0 or in s1 or in s2. array(4) { [0]=> string(1) "3" [1]=> string(1) "4" [2]=> string(1) "1" [3]=> string(1) "2" }
sUnionStore 命令/方法/函數 Performs the same action as sUnion, but stores the result in the first key 執行一個並集操做就和sUnion()同樣,可是結果儲存在第一個參數中。 Parameters Key: dstkey, the key to store the diff into. 存儲結果的SET集合KEY Keys: key1, key2, ... , keyN: Any number of keys corresponding to sets in redis. 求並集的KEYS Return value INTEGER: The cardinality of the resulting set, or FALSE in case of a missing key. 返回整數值:並集結果的個數。 Example $redis->delete('s0', 's1', 's2'); $redis->sAdd('s0', '1'); $redis->sAdd('s0', '2'); $redis->sAdd('s1', '3'); $redis->sAdd('s1', '1'); $redis->sAdd('s2', '3'); $redis->sAdd('s2', '4'); var_dump($redis->sUnionStore('dst', 's0', 's1', 's2')); var_dump($redis->sMembers('dst')); Return value: the number of elements that are either in s0 or in s1 or in s2. int(4) array(4) { [0]=> string(1) "3" [1]=> string(1) "4" [2]=> string(1) "1" [3]=> string(1) "2" }
sDiff 命令/方法/函數 Performs the difference between N sets and returns it. 執行差集操做在N個不一樣的SET容器之間,並返回結果。這個操做取得結果是第一個SET相對於其餘參與計算的SET集合的差集。(Result = SET0 - (SET1 UNION SET2 UNION ....SET N)) Parameters Keys: key1, key2, ... , keyN: Any number of keys corresponding to sets in redis. Return value Array of strings: The difference of the first set will all the others. 返回數組,返回的是第一個SET集合相對於其餘集合的差集(first set - (N sets)) Example $redis->delete('s0', 's1', 's2'); $redis->sAdd('s0', '1'); $redis->sAdd('s0', '2'); $redis->sAdd('s0', '3'); $redis->sAdd('s0', '4'); $redis->sAdd('s1', '1'); $redis->sAdd('s2', '3'); var_dump($redis->sDiff('s0', 's1', 's2')); Return value: all elements of s0 that are neither in s1 nor in s2. array(2) { [0]=> string(1) "4" [1]=> string(1) "2" }
sDiffStore 命令/方法/函數 Performs the same action as sDiff, but stores the result in the first key 與sDiff函數功能一直,只是結果爲一個新的SET集合,存儲到dstkey。 Parameters Key: dstkey, the key to store the diff into. Key:存儲結果的SET集合KEY Keys: key1, key2, ... , keyN: Any number of keys corresponding to sets in redis 參與操做的SET集合 Return value INTEGER: The cardinality of the resulting set, or FALSE in case of a missing key. 返回整數:爲結果集的個數。 Example $redis->delete('s0', 's1', 's2'); $redis->sAdd('s0', '1'); $redis->sAdd('s0', '2'); $redis->sAdd('s0', '3'); $redis->sAdd('s0', '4'); $redis->sAdd('s1', '1'); $redis->sAdd('s2', '3'); var_dump($redis->sDiffStore('dst', 's0', 's1', 's2')); var_dump($redis->sMembers('dst')); Return value: the number of elements of s0 that are neither in s1 nor in s2. int(2) array(2) { [0]=> string(1) "4" [1]=> string(1) "2" }
sMembers 命令/方法/函數 Returns the contents of a set. 返回SET集合中的全部元素。 Parameters Key: key Return value An array of elements, the contents of the set. Example $redis->delete('s'); $redis->sAdd('s', 'a'); $redis->sAdd('s', 'b'); $redis->sAdd('s', 'a'); $redis->sAdd('s', 'c'); var_dump($redis->sMembers('s')); Output: array(3) { [0]=> string(1) "c" [1]=> string(1) "a" [2]=> string(1) "b" }