Redis framework

1. Introduction to
Redis a) The concept of Redis is
a NoSQL database based on memory Key Value type.
b) NoSQL (Not Only SQL)
a specific database classification
1. Relational [structure] database (RDB) Oracle MySQL DB2 Postgre SQLServer.
2. NoSQL type database, non-relational database product.
c) NOSQL type database features
1. Schemaless weak structure (ignoring table rows and columns) 2. In
-Memory memory products
3. Weakened transaction (no transaction transaction Very simple) RDB+NOSQL
4. Suitable for Cluster environment
5. No complicated connection query operation
6. Script language support (javascript lua)
d) Common NOSQL products
1. Redis (key value) kv
2. MongoDB (document) JSON

3. HBASE (column type NOSQL)
4. Cassandra (no single node failure forever)
e) Features of Redis

  1. Redis is a high-performance Key/Value database

  2. Memory-based

  3. Rich data types

  4. Endurance

  5. Subscription/publishing model
    f) Difference between Redis and Memcache
    Redis is an in-memory database product, while Memcache is an in-memory caching product. Redis can
    persist data in memory, but Memcache cannot

  6. Redis installation

2. The basic command
flushall clears all key
keys in redis * Display all key values ​​in redis
set key value Store a data
get key Get the corresponding value according to the key

3.
Redis data type Note: Redis data type refers to the value type key type is string.
a) String type [emphasis]
Note: do not distinguish between string and number
set
get
mset
mget
strlen
getrange
setex key 10 value
setnx If the key does not exist, create a new value.
If the key does not exist, it does not cover
b) List type (ordered and repeatable)
lpush | lpushx
rpush | rpushx
lpop|rpop
lrange
llen
linsert names before suns3 suns0 [Understand]
c) Set type( disorder not repeat)
Sadd
smemebers
sismember
SCard
D) zset [important chart]
Zadd Key score value
Z Range the
zrangebyscore
zrank subscript
zscore obtaining a value of an element
zincrby key score elements
e) Hash [了解]
hset
hget
hkeys
Whale

4. Supplement to basic commands
a) keys *
b) select
select
the internal default design of the database redis, which is specified by the 16 database redis.conf configuration file

c) Flushall
clears all keys in the database
d) flushdb
clears the keys in the current database
e) expire
sets the validity period of a key
expire key time
account freeze
account_no 1
expire account_no time
spikes
ranking
f) ttl
query the remaining validity period of a key
g )del

5. Redis JavaClient
a) The method in the Jedis tool class has the same function as the redis shell command
b) JedisUtils

6. Redis persistence
a) Why do you need persistence?
Because Redis is a memory database, in order to ensure the safety of data when the memory is powered off, a persistence operation is required
b) Redis persistence (2 options)
1 .Snapshotting (RDB) full copy snapshot assignment

a) The completion process of the RDB mechanism
1 The main process of redis forks the child process to complete the RDB write operation
2 The main process of redis provides services, and the child process will write the data in the current database into a temporary file
3 When the temporary file is written, Overwrite the original RDB snapshot file
b) Run time of the RDB mechanism
1. Automatic RDB operation
Modify the
default configuration of the redis.conf file

2. Manual RDB operation
save:
Redis will use the main process to process the RDB file.
bgsave The main process forks the child process to complete the RDB processing
c) Problems with the RDB mechanism
1. Between the two save points, there may be data loss

2.AOF mechanism (incremental replication log replication)
Note: By default redis will use RDB for persistence.
Redis uses both RDB and AOF, and redis will apply AOF

a) AOF operating mechanism

AOF is more secure than RDB and records every write operation. However, if the power is lost during the writing process, a small amount of data will be lost
b) The use of
AOF 1. Automatic AOF
redis.conf configuration file

2. Attention details in AOF
a) File synchronization mechanism

b) Log file redo.
Combine the commands in the log file reasonably.
According to the current state of Redis data, write a new aop file
i.bgrewriteaof
ii. Automatic redis.conf

3. The pit of
Redis persistence. Assuming that the initial Redis uses RDB for persistence, switch AOF for persistence. The problem?
RDB — bgsave ---- dump.rdb
AOP — appendonly.aof Get data

Hot switch:

Change the redis.conf file appendonly yes

1. Redis memory management [tuning]
a) Memory fragmentation
Problem: Affects the utilization of memory

b) The purpose of memory management is to
reduce memory fragmentation. The
borrowed third-party tool (library) is completed

c) It is recommended to use jemalloc
1.yum jemalloc
2 provided by google .

2. The actual development scenario of
Redis (1) a) Redis is used to manage Session in a cluster environment

b) Redis is used for session management in a cluster environment, so how is Redis designed?
key (sessionid) value (session data binary)
c) development steps

3. The actual development scenario of
Redis (2) a) Redis acts
as a cache between Tomcat and DB b) Redis acts as a cache implementation ideas

c) Mybatis and Redis integrated application global cache
Customize the Redis cache Cache interface (Jedis) in MyBatis
d) How to serialize objects in java----byte[]
1.Java IO java_serliazble

2.Fastjson

e) Jedis implements the Cache interface

f) Apply RedisCache 1.
Mybatis-config.xml to enable global cache
2. Mapper settings <cache tag

3. Note:
1 Mybatis will store the data in the cache when the session is closed. 2 Mybatis will
clear the cache when the transaction is submitted to solve the problem of dirty data.

4. Redis cluster operation
a) Replication (Replica replica set master-slave replication master-slave replication)
1. Development of
Redis replica set configuration slave of masterip masterport in the
redis.conf file 2. Redis replica set running process

b) Sharding [Shard] (sub-database and sub-table) Sharding
1. Basic concepts of sub-database and sub-table (RDB)
a) Sharding

b) Sub-library

c) Sharing in Redis

1. Programmers complete client fragmentation through manual coding by jedis client

2.Jedis Client Sharding standard code

5.
Redis Supplement a) Build a self-starting system for Redis

b) Redis 3.x cluster features, server-side automatic sharding

Note: ruby

Guess you like

Origin blog.csdn.net/m0_38127487/article/details/114792660