In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Click "official" to view commands file http://redis.cn/commands.htmlRedis command operation: http://doc.redisfans.com/ data structure
Redis is the data structure of key-value. Each piece of data is a pair of keys and values.
The type of key is a string
Note: keys cannot be repeated
There are five types of values:
String string
Hash hash
List list
Set set
Ordered set zset
Data manipulation behavior
Save
Modify
Get
Delete
Click the "official" to view the commands file http://redis.cn/commands.html
RDB error reporting and its solution
MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. Commands that may modify the data set are disabled. Please check Redis logs for details about the error.
Redis is configured to hold database snapshots, but it cannot be persisted to the hard disk at this time. The command used to modify collection data cannot be used
Reason:
Force closing Redis snapshots so that they cannot be persisted. Solution:
After running the config set stop-writes-on-bgsave-error no command, close the configuration item stop-writes-on-bgsave-error to resolve the problem.
Key command
Find key, parameter hold regular expression
Keys pattern
Example 1: view all keys
Keys *
Example 2: view the key containing an in the name
Keys' aura'
Determine whether the key exists. If it exists, it returns 1, and 0 does not exist.
Exists key1
Example 3: judge whether the key A1 exists
Exists a1
Check the type of value corresponding to the key
Type key
Example 4: check the value type of key A1, which is one of the five types held by redis
Type a1
Delete keys and corresponding values
Del key1 key2...
Example 5: delete keys a2 and A3
Del a2 a3
Sets the expiration time in seconds
If no expiration time is specified, it will exist until the expiration DEL is removed.
Expire key seconds
Example 6: the expiration time of the setting key'A1'is 3 seconds
Expire 'a1' 3
View valid time in seconds
Ttl key
Example 7: check the validity time of the key 'bb'
Ttl bb
String Typ
String type is the most basic data storage type in Redis, and it is binary safe in Redis, which means that this type can accept data in any format, such as JPEG image data or Json object description information. The maximum length of data that a string type Value can hold in Redis is 512m.
Save
Add if the set key does not exist, or modify it if the set key already exists
Set key value
Set key value
Example 1: set the key to the data whose name value is itcast
Set name itcast
Set key value and expiration time in seconds
Setex key seconds value
Example 2: set key to data with AA value and aa expiration time of 3 seconds
Setex aa 3 aa
Set multiple key values
Mset key1 value1 key2 value2...
Example 3: set key to'A1', value to 'python', key to' a2', value to 'java', key to' A3', value to'c'
Mset a1 python a2 java a3 c
Added value
Append key value
Example 4: add the value '' to A1
Append 'a1' '
Get
Get: get the value according to the key, and return nil if the key does not exist
Get key
Example 5: get the value of the key 'name'
Get 'name'
Get multiple values based on multiple keys
Mget key1 key2...
Example 6: get the values of keys A1, a2, a3'
Mget a1 a2 a3
Delete
The value is deleted when the key is deleted
Hash Typ
Hash stores objects, whose structure is attributes and values.
The value is of type string
Add, modify
Set a single property
Hset key field value
Example 1: set the property name of the key user to libai
Hset user name libai
Set multiple properties
Hmset key field1 value1 field2 value2...
Example 2: set key U2's attribute name is itcast, attribute age is 11
Hmset u2 name laowang age 11
Get
Gets all the properties of the specified key
Hkeys key
Example 3: get all the attributes of key U2
Hkeys u2
Get the values of several attributes
Hget key field
Example 4: get the value of the key U2 attribute 'name'
Hget U2 'name'
Get the values of multiple attributes
Hmget key field1 field2...
Example 5: get the value of the key U2 attribute 'name',' age
Hmget u2 name age
Get the values of all attributes
Hvals key
Example 6: get the values of all attributes of the key 'U2'
Hvals u2
List Typ
The element type of the list is string
Sort by insertion order
Increase
Insert data on the left
Lpush key value1 value2...
Example 1: add additional data a, b, c from the left side of the list with key'A1'
Lpush a1 a b c
Insert data on the right
Rpush key value1 value2...
Example 2: add data 0 1 from the right side of the list with key'A1'
Rpush a1 0 1
Inserts a new element before or after the specified element
Linsert key before or after existing elements new elements
Example 3: add'3' before element'b' in the list with key'A1'.
Linsert a1 before b 3
Get
Returns the list of elements within the specified range
Lrange key start stop
Start and stop are the subscript indexes of the element
The index starts on the left, and the first element is 0
The index can be negative, indicating that the count starts at the tail, such as-1 for the last element
Example 4: get all the elements of the list with the key'A1'
Lrange a1 0-1
Sets the element value at the specified index location
The index starts on the left, and the first element is 0
The index can be negative, indicating the start of the tail count, such as-1 for the last element
Lset key index value
Example 5: the value of the element with subscript 1 in the list with the modification key'A1'is'z'.
Lset a 1 z
Delete
Delete the specified element
Lrem key count value
Remove the element whose value is value in the previous count occurrence in the list
Count > 0: remove from beginning to end
Count < 0: remove from tail to head
Count = 0: remove all
Example 6.1: add additional elements'a','b','a','b','a','b'to the list 'a2'
Lpush a2 a b a b a b
Example 6.2: delete 2'b' from the right side of the'a2 'list
Lrem a2-2 b
Example 6.3: view all the elements of the list 'py12'
Lrange a2 0-1
Set Typ
Ordered set
Element is of type string
Elements are unique and do not repeat.
Description: no modification operation for the collection
Increase
Add element
Sadd key member1 member2...
Example 1: add elements' zhangsan', 'lisi',' wangwu' to the collection of key 'A3'
Sadd a3 zhangsan sili wangwu
Get
Return all elements
Smembers key
Example 2: get all the elements in the collection of the key 'A3'
Smembers a3
Delete
Delete the specified element
Srem key
Example 3: delete the element 'wangwu' from the collection of key' A3'
Srem a3 wangwu
Zset Typ
Sorted set, ordered set
Element is of type string
Elements are unique and do not repeat.
Each element is associated with a score of type double, which represents weight, and elements are sorted from "to" by weight.
Description: no modification operation
Increase
Add
Zadd key score1 member1 score2 member2...
Example 1: adding elements' lisi', 'wangwu',' zhaoliu' and 'zhangsan', to the collection of key' a4' has weights of 4, 5, 6 and 3, respectively
Zadd a4 4 lisi 5 wangwu 6 zhaoliu 3 zhangsan
Get
Returns elements within the specified range
Start and stop are the subscript indexes of the element
The index starts on the left, and the first element is 0
The index can be negative, indicating that the count starts at the tail, such as-1 for the last element
Zrange key start stop
Example 2: get all the elements in the collection of the key 'a4'
Zrange a4 0-1
Returns the member whose score value is between min and max
Zrangebyscore key min max
Example 3: get members with permission values between 5 and 6 in the collection of key 'a4'
Zrangebyscore a4 5 6
Returns the score value of the member member
Zscore key member
Example 4: get the weight of the element 'zhangsan' in the collection of key' a4'
Zscore a4 zhangsan
Delete
Delete the specified element
Zrem key member1 member2...
Example 5: delete the element 'zhangsan' in the collection' a4'
Zrem a4 zhangsan
Delete elements with weights in the specified range
Zremrangebyscore key min max
Example 6: delete elements with permissions between 5 and 6 in the collection 'a4'
Zremrangebyscore a4 5 6
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.