In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Redis is the data structure of key-value. Each piece of data is a key-value pair.
The type of key is a string, so no quotation marks are required because the default 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
# string string key
Add if the key set by set key value # does not exist, or modify it if the key already exists
Set name daiby
Set key value [NX | XX] # NX: succeed if key does not exist, otherwise fail (do not overwrite the old value)! XX: succeed if key exists, otherwise fail (be sure to overwrite the old value)!
Set aaa 222 nx # failed if aaa exists
Set aaa 222 xx # failed if aaa does not exist
Setnx key value # sets the value of key to value, which is equivalent to set key value nx, only if key does not exist
Msetnx key value key value # set the value of key to value only if all key does not exist
Getset key new-value # sets the value of the string key to the new value and returns the old value
Getset aaa 444
Get key # get key value
Get name
Mset key1 value1 key2 value2. # set multiple key values
Mset gender M age 18 addr SH
Mget key1 key2 key3... # get multiple key values
Mget gender age addr
Append key value # add value to append the content to the end of the string
Append name 123-> "daiby123"
Strlen key # returns the length of the value stored by the string key key. Redis records the length of each string value, time complexity O (1)
Strlen aaa
Setrange key index value # starts with the index index, overrides the string value stored by the key with value, and accepts only positive indexes
Setrange aaa 1222-- > 4222
Getrange key start stop # range value, returns the value between the start and end indexes. The closed interval. The index can be positive or negative.
Getrange aaa 0 2
Getrange aaa 0-2
# commands for numeric values can be executed on a string key as long as the value stored in the string key can be interpreted as a 64-bit integer or an IEEE-754 standard 64-bit floating-point number
# append,strlen,setrange,getrange can be performed even if the string key stores a numeric value
Incrby key increment # add the value stored by key to the incremental increment
Incrby aaa 100
Decrby key decrement # subtracts the value stored in key by subtracting decrement
Decrby aaa 1000
Incr key # plus one, equivalent to incrby key 1
Incr ccc
Decr key # minus one, equivalent to decrby key 1
Decr ccc
Incrbyfloat key increment # floating point number self-increasing and self-decreasing, without decrbyfloat, the corresponding effect can be achieved by giving a negative value
Incrbyfloat ccc 1.11
Incrbyfloat ccc-23.45
Commands such as # set,get,setnx,append can also be used to set binary data
# unlike the index when storing files, the index of storing binary numbers is decreasing from left to right
> import redis
> r = redis.StrictRedis ()
> r.set ('bites', 0b10010100)
>
> r.append ('bites',0b111) # decimal number 7
>
Setbit key index value # sets the value of binary bits and sets the value of secondary bits on a given index to value
Setbit bites 2 1
Getbit key index # returns the value of the binary bits on a given index
Getbit bites 6
Bitcount key start end # calculates and returns the number of binary bits set to 1 in the value stored in the string
Bitcount bites 0-1
# strlen,setrange,getrange is not applicable to Chinese
# hash is used to store objects. The structure of objects is attributes and values, and the basic type of values is string.
# Hash keys and values can be text, integer, floating point, or binary data
# try to use hash keys to store key-value pairs instead of string keys to avoid naming conflicts and save memory
Hset key field value # set a single property
Hset py1 name daiby
Hsetnx key field value # if field does not exist in the hash key key, the command succeeds
Hsetnx message addr sh
Hmset key field1 value1 field2 value2. # set multiple properties
Hmset py3 name daiby age 18 addr SH
Hexists key field # check whether a given field exists
Hexists message addr
Hkeys key # gets all the attributes of the specified key
Hkeys py3
Hvals key # gets the values of all properties of the specified key
Hvals py3
Hget key field # gets the value of an attribute of the specified key
Hget py1 name
Hgetall key # returns all field value pairs contained in the hash key key
Hgetall message
Hmget key field1 field2... # gets the values of multiple attributes of the specified key
Hmget py3 name age addr
Hdel key field1 field2. # Delete the attribute, and the corresponding value of the attribute will be deleted together. If you want to delete the hash key, delete all the attributes.
Hdel name age addr
Hlen key # returns the number of field value pairs contained in the hash key key
Hlen message
Hincrby key field increment # adds or subtracts the integer increment from the value of field in the hash key key
Hincrby message id-10
Hincrbyfloat key filed increment # is the value of field in the hash key key, plus or minus the floating point increment
Hincrbyfloat message id + 1.1
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.