Posted onEdited onInRedisViews: Disqus: Symbols count in article: 1.6kReading time ≈3 mins.
Intro Redis DataStructure
這篇將介紹Redis的幾個dataStructure。
INCRBY key integer
1 2 3 4 5 6 7 8 9
TIME COMPLEXITY: O(1)
DESCRIPTION: Increment or decrement the number stored at key by one. If the key does not exist or contains a value of a wrong type, set the key to the value of "0" before to perform the increment or decrement operation.
INCRBY and DECRBY work just like INCR and DECR but instead to increment/decrement by 1 the increment/decrement is integer.
INCR commands are limited to 64 bit signed integers.
RETURN VALUE: Integer reply, this commands will reply with the new value of key after the increment or decrement.
HMSET key field value [field value …]
1 2 3 4 5
TIME COMPLEXITY: O(N) where N is the number of fields being set.
DESCRIPTION: Sets the specified fields to their respective values in the hash stored at key. This command overwrites any existing fields in the hash. If key does not exist, a new key holding a hash is created.
RETURN VALUE: Status code reply
SPOP key
1 2 3 4 5 6 7
TIME COMPLEXITY: O(1)
DESCRIPTION: Remove a random element from a Set returning it as return value. If the Set is empty or the key does not exist, a nil object is returned.
The SRANDMEMBER command does a similar work but the returned element is not removed from the Set.
RETURN VALUE: Bulk reply
LPUSH key string
1 2 3 4 5 6
TIME COMPLEXITY: O(1)
DESCRIPTION: Add the string value to the head (RPUSH) or tail (LPUSH) of the list stored at key. If the key does not exist an empty list is created just before the append operation. If the key exists but is not a List an error is returned.
RETURN VALUE: Status code reply
LLEN key
1 2 3 4 5 6
TIME COMPLEXITY: O(1)
DESCRIPTION: Return the length of the list stored at the specified key. If the key does not exist zero is returned (the same behaviour as for empty lists). If the value stored at key is not a list an error is returned.
RETURN VALUE: Integer reply of the length of the list.