current position:Home>redis6. 2.6 data type and configuration file interpretation

redis6. 2.6 data type and configuration file interpretation

2022-01-26 22:08:42 Love pocket sky

1、key Value key

1.1、key The operation of the value

  • keys * View all of the current library key
  • set key value Set up key Value and value
  • exists key Judge key Whether there is
  • type key see key What type is it
  • del key Delete specified key data
  • unlink key according to value Select non blocking delete
    ------ Only will keys from keyspace Delete from metadata , The real deletion will be done asynchronously later .
  • expire key 10 10 Second : For a given key Set expiration time
  • ttl key See how many seconds are left to expire ,-1 Never expire ,-2 Indicates that it has expired

1.2、 Library selection :

  • select  Command switch database
  • dbsize  Check the... Of the current database key Number
  • flushdb  Empty the current library
  • flushall  Kill all the warehouses

2、string character string

  • One key Corresponding to one value
  • Binary safe , Can contain any data
  • value At most 512m

Parameter setting :

  • set key value Set up key value
  • get key Inquire about key value
  • append key value Will be given value Append to the end of the original value
  • strlen key Get the length of the value
  • setnx key value Only in key When it doesn't exist , Set up key value
  • incr key take key The number of values stored is incremented 1, Operate on numeric values only , If it is empty , The new value added is 1
  • decr key take key Value stores the number minus 1, Operate on numeric values only , If it is empty , The new value added is 1
  • decr key take key Value stores the number minus 1
  • incrby/decrby key < step > take key Increase or decrease the number of values stored, such as step size

Add additional string parameters :

  • mset key value key value.. Set one or more at the same time key-value
  • mget key key... Get one or more at the same time value
  • msetnx key value key value.. Set one or more at the same time key-value. If and only if all given key It doesn't exist
  • getrange key < The starting position > < End position > obtain key The values of the start and end positions of
  • setrange key < The starting position > value take value The value of overwrites the starting position
  • setex key <> value While setting the key value , Set expiration time
  • getset key value Replace the old value with the new value

3、list list

Common commands :

  • lpush/rpush key value value... Insert one or more values from left or right ( Head and tail )
  • lpop/rpop key Spit out one or more values from left or right ( Value at key at , It's not worth it , No keys )
  • rpoplpush key1 key2 from key1 Spit a value on the right side of the list , Insert into key2 Left side
  • lrange key start stop Get elements by index subscript ( From left to right )
  • lrange key 0 -1 Get all values
  • lindex key index Get elements according to index subscript
  • llen key Get list length
  • linsert key before/after value newvalue stay value Insert a new value before
  • lrem key n value Delete from the left n individual value value
  • lset key index value In the list key Subscript in index Change the value value

4、set aggregate

Dictionaries , Hashtable
Automatic weight removal and disordered
Common commands :

  • sadd key value value... Put one or more member Add elements to the collection key in , What already exists member Element ignored
  • smembers key Take all the values of the set
  • sismember key value Judge the set key Whether the modified value is included
  • scard key Returns the number of elements in the collection
  • srem key value value Delete an element in the collection
  • spop key Randomly take an element from the set
  • srandmember key n From this collection n It's worth , Will not be removed from the collection
  • smove < A collection a>< A collection b>value Put a collection a One of the value Move to another collection b
  • sinter key1 key2 Returns the intersection element of two sets
  • sunion key1 key2 Returns the union element of two sets
  • sdiff key1 key2 Returns the difference set element of two sets (key1 yes , we have ,key2 No, )

5、hash Hash

Key value pair set , Especially suitable for storing object types
Common commands :

  • hset key field value to key In the collection filed Key assignment value
  • hget key1 field aggregate field Take out value
  • hmset key1 field1 value1 field2 value2 Batch settings hash Value
  • hexists key1 field Look at the hash table key in , Given domain field Whether there is
  • hkeys key List the hash All of the collection field
  • hvals key List the hash All of the collection value
  • hincrby key field increment Hash table key In the domain field Plus the increment 1 -1
  • hsetnx key field value Hash table key In the domain field Is set to value, If and only if domain field non-existent

6、Zset Ordered set

String collection without duplicate elements , Rank according to relevant scores , Ranking from low to high , Ranking repeatable

Ordered set zset With the common set set Very similar , Is a collection of strings without repeating elements

Common commands :

  • zadd key score1 value1 score2 value2 Put one or more member Elements and score Values are added to the order key in
  • zrange key start stop (withscores) Return to ordered set key, The subscript is start And stop Between the elements , belt withscores, You can return scores and values together to the result set .
  • zrangebyscore key min max(withscores) Return to ordered set key, all score The value is between min and max Between ( Including equal to min or max) Members of . Members of the ordered set press score The values of are arranged in ascending order
  • zrevrangebyscore key max min (withscores) ditto , Change to big to small
  • zincrby key increment value For the elements score Plus the increment
  • zrem key value Delete... Under this collection , The element that specifies the value
  • zcount key min max Count the set , The number of elements in the fraction range
  • zrank key value Returns the rank of the value in the collection , from 0 Start

7、 Configuration file details

#bind -::1 // Annotate local and remote , It can be remotely
protected-mode no // Protection mode changed to no, Remote access
daemonize yes // Background startup is yes
pidfile /var/run/ // The path to save the process number

View and cancel of access password
Take out the comments

 Insert picture description here

  Or use the command line

 Insert picture description here

After setting, you can enter it every time redis-cli When entering
Still need to knock auth 123456 To access

Restart after configuration
adopt kil Process restart


copyright notice
author[Love pocket sky],Please bring the original link to reprint, thank you.

Random recommended