Catalog

  • One 、Redis Yes key The operation of
  • Two 、 Five types of data
    • String type
    • List( aggregate )
    • Set( aggregate )
    • Hash( Hash )
    • Zset( Ordered set )
  • 3、 ... and 、 Three special data types
    • geospatial( Location )
    • hyperloglog( advantage : It takes up little memory )
    • Bitmap( Bitmap )

One 、Redis Yes key The operation of

  • Judge key Whether there is :exists key_name
  • Set up key The expiration time of :expire key_name [ Expired time value ](number type )
  • see key The expiration time of :ttl key_name
  • Get all key: keys *

Two 、 Five types of data

String( character string )

String type operation :

  • Set the value :set key_name value
  • Get value :get key_name
  • Append string , If the current key If it doesn't exist, a new one will be created key: append key_name value
  • Get string length :strlen key_name
  • Intercepting string :getrange key_name [start index] [end index]
  • The specified string overlaps the given key String value stored , The position of the overlay is from the offset offset( Numeric type ) Start :setrange key_name offset value
  • For the specified key Set the value and its expiration time , If key Already exist ,setex The command will replace the old value : setex key_name [expiration time] value
  • First get the value and then set it :getset key_name value

Number type operation :

  • number The number type increases 1:incr key_name
  • number Number type minus 1:decr key_name
  • Increase the specified value :incrby key_name [ Specific value ]number type
  • Decrease the specified value :decrby key_name key_name [ Specific value ]number type

The batch operation :

  • Batch setting value :mset key_name1 value1 key_name2 value2 key_name3 value3
  • Batch fetch value :
    • The way 1: mget key_name1 key_name2 key_name3
    • The way 2:msetnx key_name1 key_name2 key_name3 // This is atomic manipulation , All or nothing , All or nothing .

List( aggregate )

  • Set the value :

    • On the left :lpush key_name value
    • On the right :rpush key_name value
  • Get value :
    • On the left :

      • lrange key_name [start index] [end index]
      • lrange key_name 0 -1 Get all the elements
  • Remove data :
    • On the left :lprop key_name
    • On the right :rprop key_name
  • According to the parameters count Value , Remove the list and parameters value Equal elements :
    • lrem key_name [count] value

      • count > 0: Search from header to footer , Remove and value Equal elements , The number of count.
      • count < 0: Search from the end of the table to the header , Remove and value Equal elements , The number of count The absolute value of .
      • count = 0: Remove all and from the table value Equal value .
  • Get elements from index :lindex key_name [index]
  • Get the length of the collection :llen key_name
  • Replace the value of the specified subscript in the list , If it doesn't exist, it will report an error :lset key_name [index] value
  • Insert an element before or after a list element . When the specified element does not exist in the list , Do nothing . When the list doesn't exist , Be treated as an empty list , Do nothing . If key It's not a list type , Return an error : linsert key_name [before] || [after] oldvalue newvalue

Set( aggregate )

  • Set the value :sadd key_name value
  • Get value :smembers key_name
  • Randomly extract data from a set :srandmember key_name
  • Randomly extract a specified number of data from a set :srandmemer key_name [number]
  • Remove elements :srem key_name value
  • Used to remove the specified key One or more random elements of , After removal, the removed element will be returned : spop key_name
  • Determine if the value is in the set :sismember key_name value
  • Gets the number of elements in the collection :scard key_name
  • Operations between sets :
    • Move values to another collection :smove oldlist newlist value
    • Difference set :sidff oldlist newlist
    • intersection :sinter oldlist newlist
    • Combine :sunion oldlist newlist

Hash( Hash )

  • Set the value :

    • The way 1:hset key_name filed1 value
    • The way 2:hsetnx key_name filed1 value // If it does not exist, it can be set
    • The way 3:hsetnx key_name filed1 value // If it exists, it cannot be set
  • Get value :hget key_name filed1
  • Get all values :hgetall key_name
  • Delete the value of a field in the collection :hdel key_name filed1
  • Gets the number of elements in the collection :hlen key_name
  • Judge key Whether there is :hexists key_name
  • Get all filed: hkeys key_name
  • Get all values :hvals key_name
  • Self increasing :hincrby key_name filed1 1
  • Self reduction :decrby key_name filed1 1
  • The batch operation :
    • Set the value :hmset key_name filed1 value1 filed2 value2
    • Get value :hmget key_name filed1 filed2

Zset( Ordered set )

  • Set the value (number: The identification bit of the sort , This can be repeated ):zadd key_name [number] value
  • Set multiple values (number: The identification bit of the sort , This can be repeated ): zadd key_name [number] value2 [number] value3
  • Get value :zrange key_name 0 -1
  • Sort :zrangebysocre key_name -inf +inf
  • Remove elements :zrem key_name value
  • Get the number of elements in the collection :zcard key_name
  • Gets the number of members in the specified interval :zcount key_name [start index] [end index]

3、 ... and 、 Three special data types

geospatial( Location )

  • Add the location of the city :geoadd china:city 116.40 39.90 beijing
  • Get the longitude and latitude of the specified city :geopos china:city beijing chongqing
  • Get the distance between two people :geodist china:city beijing shanghai km
  • Gets the coordinates within the specified radius :georadius china:city 110 30 1000 km
  • Looking for elements based on elements :georeadiusbymember china:city beijing 1000 km

hyperloglog( advantage : It takes up little memory )

  • Set the value :PFadd key_name value1 value2 value3 value4 value5 value6
  • Get quantity :PFCOUNT key_name
  • Merge two sets :PFMERGE New collection aggregate 2 aggregate 3

Bitmap( Bitmap )

  • Record clocks from Monday to Friday :setbit sign 0 1 // 0 What day is it 1 Whether to punch in or not
  • Check to see if you clock in on a day :gitbit sign 3
  • Count the days of clock in :bitcout sign

Redis- Chapter five -8 More articles on these data types

  1. redis The use of five data types (zz)

    redis The use of five data types redis The use of five data types ( Excerpt from :http://tech.it168.com/a2011/0818/1234/000001234478_all.shtml ) 1.S ...

  2. redis The use of five data types

    redis The use of five data types redis The use of five data types ( Excerpt from :http://tech.it168.com/a2011/0818/1234/000001234478_all.shtml ) 1.S ...

  3. redis Five types of data usage scenarios

    string 1.String Common commands : except get.set.incr.decr mget And so on ,Redis The following operations are also provided : Get string length To string append Content Set and get one of the strings ...

  4. Redis Five types of data - Set up key The expiration time of

    1.redis Command client [root@localhost bin]# ./redis-cli 127.0.0.1:6379> # Is it running 127.0.0.1:6379> ping PON ...

  5. Redis Installation and five data types

    redis It's a non relational database , Also called memory database . Data is in the form of key value pairs , adopt key lookup value install Radis:6379 sudo apt-get update sudo apt-get install r ...

  6. Redis: Redis Five data types are supported

    ylbtech-Redis: Redis Five data types are supported Redis Five data types are supported :string( character string ) ,hash( Hash ),list( list ),set( aggregate ) And zset(sorted set: Orderly ...

  7. Redis Five data types supported

    redis Five data types supported : 1.string( character string ) 2.hash( Hash ) Redis hash It's a key value (key=>value) The collection . Redis hash It's a string Type of f ...

  8. Redis Learning notes (3)—— Five types of data &amp;keys General operation of

    One .Redis Data structure introduction redis It's a kind of advanced key-value Storage system , Among them key It's a string type , Try to meet the following points : 1)key Don't be too long. , It's better not to operate 1024 Bytes , This not only consumes memory, it also reduces ...

  9. redis Five basic data types of

    redis Basic data type redis Divided into 5 Basic data type in :String,Hash,List,Set,ZSet The first one is String String Types are special types that contain many types , And binary security . such as ...

  10. ( turn ) Taotao mall series ——Redis Introduction to five data types

    http://blog.csdn.net/yerenyuan_pku/article/details/72855562 Redis Five data types are supported :string( character string ),hash( Hash ),list( ...

Random recommendation

  1. Basic sorting algorithm —— Bubble sort java Realization

    Bubble sort is the simplest sort algorithm , I won't say much about the specific ideas , The code is as follows : eclipse4.3 Compiled in package sort.basic; import java.util.Arrays; publi ...

  2. Microsoft Edge embedded JavaScript The engine is about to open up

    Microsoft today (2015 year 12 month 10 Japan ) Announced that it will open source soon Chakra Core controls , And changed his name to “ChakraCore”, This control contains all Edge JavaScript All the core functions of the engine .ChakraCore Next month ...

  3. uva 1629

    1629 - Cake slicing Time limit: 3.000 seconds A rectangular cake with a grid of m * n <tex2html_v ...

  4. gcc Problems with compilation

    /usr/include/c++/4.8/bits/c++0x_warning.h:32:2: error: #error terms of settlement :g++ -std=c++11

  5. UOJ 08 Quine I lost at the bottom

    #8. Quine Time Limit: 20 Sec Memory Limit: 256 MB Topic linking http://uoj.ac/problem/8 Description Write a program , Make it possible to ...

  6. SDWebImage Source code interpretation of SDWebImageDownloader

    SDWebImage Source code interpretation of SDWebImageDownloader Chapter eight Preface SDWebImageDownloader This class is very simple , The author's design idea is also very clear , But I want to make a little digression here . If someone ...

  7. JS Common operations

    // The first blog post , I hope you can support me more /***** BasePage.js Public Script files Some methods need to be referenced jquery library *****/ //#region Date of operation // String to time . functi ...

  8. JavaScript –type

    JavaScript – The type of me is dizzy Every time I write a blog, I find it more difficult to get a proper topic than the whole article , When the number of words is limited, I suddenly think of JavaScript Pick up should be a very literary and eye-catching blog topic , But I'm not in a rush to use , Experience tells me that I should ...

  9. Jmeter---- Basic introduction (1)

    1.Jmeter Basic introduction To put it simply , Namely Jmeter Do   A functional test   and   Performance testing . It can be to HTTP and FTP The server performs stress and performance tests , You can do the same for any database , It can also present test results in many forms . ...

  10. [Codeforces 933A]A Twisty Movement

    Description Question bank link Give you a length of \(n\) It only contains \(1,2\) Sequence . You can choose one of them \([l,r]\) , Flip the interval , After flipping, the monotone non descending sequence is the longest . Find the longest length . \( ...