Getting Started with Redis Basics

Learning the original intention of redeis, the concurrency of the system is increasing. Due to the need to develop distributed applications, the front end is distributed by nginx reverse proxy to the upstream service node. The node is deployed in a separate tomcat, and the session needs to be managed uniformly . The redis plugin caches the session to the redis container.
The following are the basic instructions related to getting started with redis, which is convenient for everyone to get started and learn.
The main source of the tutorial content is "Yiibai Tutorial": http://www.yiibai.com/redis/redis_environment.html
I strongly recommend "Yiibai Tutorial" to everyone, suitable for getting started with development, address: http://www.yiibai.com/
 
1. Environment installation
    Start redis: redis-server;
    Check if it works: redis-cli, enter ping;
 
2.redis configuration, the configuration file can be found in the redis root directory redis.conf
    Basic syntax: CONFIG GET CONFIG_SETTING_NAME
    All configuration: CONFIG GET *;
 
3. Data Type
    字符串:SET name "yiibai";GET name;
    Hashes哈希值:HMSET user:1 username yiibai password 123;HGETALL user:1;
    List列表:lpush totorList redis;lpush totorList mongodb;lpush totorList rebitmq;
                    lrange totorList 0 10;
    Set集合:sadd totorList redis;sadd tutorList mongodb;sadd tutorList rebitmq;
                     smembers totorList;
    Collection sorting: zadd totorList 0 redis; zaddtutorList 0 mongodb; zaddtutorList 0 rebitmq;
 
4. redis command
    Start the redis client: redis-cli;
    The remote server runs the command: redis-cli -h  host  -p  port  -a  passowrd
 
5.keys management keys
    Syntax: COMMAND KEYNAME;
    Delete key: DEL key;
    Judgment key: EXISTS KEY;
    Find keys: KEYS pattern;
    The data value of the key: TYPE key;
 
6. Publish Subscribe
    pending
 
7. Affairs
    start, transaction starts: MULTI;
    Execute: EXEC;
8. Script, support Lua parser for calculating scripts, built-in since 2.6.0
    Command: EVAL script numkeys key ... arg ...
9.redis connection
    Verify connection to redis server: AUTH "password";ping; (output pong)
    Close the connection: QUIT;
    Change the selected database for the current connection: SELECT index;
 
10. redis server
    Server statistics and information: INFO;
    kill client connection: CLIENT KILL [ip,port];
    Connection list: CLIENT LIST;
11. Redis backup
    Backup, create dump.rdb in the Redis directory: SAVE;
    Restore: CONFIG get dir;
    Background automatic backup: BGSAVE;
12. Redis security, client authentication, ensure that the password of the redis configuration file is consistent
    Get password: CONFIG get requirepass;
    Set password: CONFIG set requestpass "yiibai";
    AUTH verification: AUTH password;
 
13. Redis Benchmarks
    Syntax: redis-benchmark [option] [option value];
    Example: redis-benchmark -h 127.0.0.1 -p 6379 -t set,lpush -n 100000 -q
 
14. Client Connection
    Maximum number of clients: config get maxclients;
    Server maximum connection settings: redis-server --maxclients 100000;
 
15. Pipeline transmission, execute commands in batches, and improve the response;
 
16. Partition, data is divided into multiple redis, each instance contains a subset of keywords
 
17.java connection operation
    jedis.jar;
 
 
Extension:
Synchronous and asynchronous : the focus is on the message communication mechanism
Synchronization: When a "call" is issued, the "call" does not return until the result is obtained;
Asynchronous: the "caller" actively waits for the result of this "call";
example:
    You call and ask the bookstore owner if he has the book "Distributed Systems". If it is a synchronous communication mechanism, the bookstore owner will say, wait a moment, "I'll check",
Then start checking and checking, and after checking (may be 5 seconds, it may be a day), I will tell you the result (return the result).
As for the asynchronous communication mechanism, the bookstore owner directly told you to check it out, called you after checking, and then hung up the phone directly (without returning the result). Then
After checking, he will take the initiative to call you. Here the boss calls back by "calling back".
 
Blocking and non-blocking: the state of the program while waiting for the result of a call (message, return value).
Blocking: The current thread will be suspended until the call result returns. The calling thread does not return until it has the result
Non-blocking: means that the call will not block the current thread until the result cannot be obtained immediately
example:
    You call the bookstore owner to ask if the book "Distributed Systems" is available. If you make a blocking call, you will always "suspend" yourself.
Until you get the result of this book, if it is a non-blocking call, you don't care whether the boss tells you or not, you go to play by yourself first, 
Of course, you should also occasionally check whether the boss has returned a result in a few minutes.
Here blocking and non-blocking have nothing to do with whether it is synchronous or asynchronous. It has nothing to do with how your boss answers your results.
About the design advantages of redis single thread
1) The vast majority of requests are pure memory operations (very fast)
2) Single thread is used to avoid unnecessary context switching and race conditions
3) The internal implementation of non-blocking IO 
uses epoll, which uses epoll + simple events implemented by itself frame. Read, write, close, and connect in epoll are converted into events, and then use the multiplexing feature of epoll to never waste a little time on io
4) A single thread is sometimes faster than a multi-thread, and the concurrency and locks that need to be considered will not increase the context switching code. The code is more concise, and the problem is handled centrally;
Personal opinion: Under the multi-core architecture, I am still optimistic about the multi-threaded model, but Redis's persistence, snapshots, and rich data structures and computing functions are more powerful. But Redis's persistence, snapshots, and rich data structures and operations are more powerful.
Refer to the explanation of redis single-line architecture: http://www.zhihu.com/question/19764056

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326876003&siteId=291194637