Redis learning notes 1-Redis basics and integration

Redis learning notes-Redis basics and integration

  1. NoSQL classification

    NoSQL (referring to non-relational databases in general) is divided into the following four categories:

    • Key-Value storage database: Redis
    • Column store database
    • Document database
    • Graph database
  2. Getting started with Redis

    1. What is Redis

      Redis (Remote Dictionary Server), the remote dictionary service, is an open source log-based, Key-Value database written in ANSI C language, supporting the network, memory-based or persistent, and providing APIs in multiple languages.

    2. What can Redis do

      1. Memory storage, persistence (rdb, aof)
      2. High efficiency, can be used for cache
      3. Publish and Subscribe System
      4. Map information analysis
      5. Timer, counter (views 1)
    3. characteristic

      1. Various data types
      2. Endurance
      3. Cluster
      4. Affairs

    Official website: https://redis.io/

    Recommend to develop on linux

  3. Redis installation

    • window github:https://github.com/tporadowski/redis/releases
    • linux abbreviation
  4. Redis use

    1. Switch database | SELECT 1 There are 16 databases by default
    2. View database size | DBSIZE [-n]
    3. View all keys in the database| KEYS *
    4. Clear the database | FLUSHDB /FLUSHALL
    5. Check if the key exists | EXISTS [key name]
    6. Move key to a database | MOVE KEY -n
    7. Set the expiration time of the key | EXPIRE [key name] -s
    8. View key expiration time | TTL [key name]
    9. View the type of key | TYPE [key name]
    10. Set expiration time-EXPIRE Set expiration time
  5. Redis five data types

    • strings
      • APPEND NAME VALUE append string
      • STRLEN string length
      • INCR | DECR KEY2 (integer only)
      • RANGE intercept string GETRANGE replace SETRANGE
      • setex ,setnx set the expiration time, the setting does not exist to create
      • MSET MGET
      • Object
    • hashes
      • HSET HGET HGETALL Set to get data
      • HMGET HMSET
      • HDEL delete the specified key
      • HLEN gets the field constant of the hash
      • HEXISTS HASH FIELD Determine whether the field exists
      • HKEYS / HVALS get all key / values
      • HINCRBY
      • HSET
    • lists
      • LINDEX positioning
      • [L/R]PUSH POP add delete
      • LREM remove
      • LTRIM trim
      • LRANGE range
      • LSET replaces the value of the specified subscript
      • LINSERT insert
    • sets
      • SADD increase
      • SMEMBERS View set members
      • SMOVE moves the value of a set to another set
      • SISMEMBER determines whether the value is in the set
      • SDIFF SET1 SET difference set
      • SINTER SET1 SET intersection
      • SUNION SET1 SET union
      • SCARD gets the number of collection elements
    • Zset adds a value on the basis of set
      • ZADD
      • ZRANGE MYSET 0 -1
      • ZRANGEBYSCORE MYSET -INF +INF WITHSCORES Sort from small to large
      • ZREVRANGE MYSET 0 -1 WITHSCORES Sort from high to low
      • Remove the specified element ZREM
      • ZCARD gets the number of elements in an ordered set
      • ZCOUNT MYSET 0 1 Get the specified number of intervals
  6. Three special data types

    1. geospatial zset

      • GEOADD Add geographic location (longitude, latitude, name) to the specified key

      GEOADD chia:city 116.40 30.90 beijin

      GEOPOS gets the longitude and latitude of the specified city

      GEODIST chia:city beijin shanghai km

      • m for meters.
      • km for kilometers.
      • mi for miles.
      • ft for feet.

      GEORADIUS chia:city 100 30 400 km

    2. hyperloglogs base

      • PFADD KEY A B C D
      • PFCOUNT KEY
      • PFMERGE KEY1 KEY KEY2 merged into KEY1
    3. Bitmaps bit storage

      • SETBIT GETBIT
      • BITCOUNT
  7. Redis transaction

    • Redis single instruction guarantees atomicity, transaction does not guarantee atomicity

    • Essence: a set of commands Exec

    • redis transaction

      • Open transaction multi
      • Order to join the team. .
      • Execute transaction exec
    • Discard transaction

    • Compilation type exception code error, the command of the transaction will not be executed if the compilation fails

    • Abnormal during runtime, other commands are executed normally

    • Monitoring watch

      • Pessimistic lock
        • Lock anytime
      • Optimistic lock
        • Will not be locked when updating data
        • Get version
        • Compare version when updating, using watch can be used as redis optimistic lock operation
  8. Jedis

    • java connect redis tool
    <!-- jedis-->
            <!-- https://mvnrepository.com/artifact/redis.clients/jedis -->
            <dependency>
                <groupId>redis.clients</groupId>
                <artifactId>jedis</artifactId>
                <version>3.5.1</version>
            </dependency>
            <!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>fastjson</artifactId>
                <version>1.2.75</version>
            </dependency>
    
  9. springboot integration

    • Import launcher dependencies
            <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        	</dependency>
    

Guess you like

Origin blog.csdn.net/weixin_47490310/article/details/114239642