Key operation
Keys *
*: Wildcard with any number of characters
?: Pass a single character
[]: 1 characters in parentheses
Exists key exists return 1, no return 0
Type key
Rename Oldkey Newkey
Common data types:
The most commonly used data types for Redis are the following:
- String
- Hash
- List
- Set
- Sorted Set
String:
Set key value
Get key
Append key Value # Appends a string, returning the new string length
substr key start end # intercepts a string and does not modify the value of key
List:
Lpush Key Value # header added
Rpush key Value # trailing add
Llen Key # View list length
Lrange start End # View a list Lrange key 0-1 returns all data
Lpop Key # Removes elements from the left
Rpop Key # remove element from right
LSet Key index Value # Specifies subscript element
Set:
Sadd Key Member # add element
Srem Key Member # delete element
Spop Key # Delete and return elements
Sismember Key member # to determine if member is in set, return 1 means there
Sinter key1 Key2 Key3 # Returns the intersection of a given set
Sunion key1 Key2 Key3 # Returns the set of a given set
Sdiff key1 Key2 Key3 # Returns the difference set for a given set
Smembers Key # Returns all elements of the collection
Sorted set:
Zadd Key Score member # add element
Zrem Key Member # delete element
Zrange Key Start end # Returns ordered result, ascending
Zcard Key # Returns the number of elements in the collection
Zscore key Element # returns the score corresponding to the given element
Hash:
Hset key field Value # Set hash value
Hget key Field # get hash value
hexists key Field # TEST Specifies whether the field exists
Hdel key Field # Deletes the specified hash field
Hlen Key # Gets the number of domains
Hkeys Key # Get all the domain names
Hgetall # Get all domain names and values
Key design:
Users table user, convert to key-value storage:
UserID Username Password Email
9 Lisi 1111111 [email protected]
Set User:userid:9:username Lisi
Set User:userid:9:password 111111
Set user:userid:9:email [email protected]
Redis from getting started to forgetting