redis basic configuration and use

redis Know

First look at mysql, mysql is stored in the machine / server's hard disk, so that mysql is read and written to be read from the hard disk, hard disk capacity, bandwidth size will affect the reading speed, reading can also affect the way the overall read speed, when visited, concurrent large, mysql will barely, according to statistics, the number of concurrent mysql connection pool of 500 to 1000, then by the slow query optimization, cdn, static pages, then, Nginx load balancing strategy, or to optimize distributed database, of course, can also be used in this way redis cache.
redis- high concurrency, height Cache memory, concurrent read and write io high tolerance
redis those commonly used to cache frequently accessed data in the memory
redis supports multiple data types, including k / v, list, set, zset storage, hash and other data structures
redis support master-slave mode applications, highly available system cache, support data synchronization between clustered servers
redis support persistent data storage, the available data in memory saved to disk, reboot again load can be used

redis common data structure
structure type Structure stored value Structure literacy
string It can be a string, integer, float Wherein a portion of the operations performed on the entire string or strings, performing increment or decrease of the integer and floating point
list A linked list, each node in the linked list contains a character string Add, Get, remove the individual elements; check whether there is an element in the set; calculating intersection, union, difference sets; obtaining random element from the collection inside.
set Each string comprises a string without a collector, and are contained it is unique, different from each other Add, Get, remove a single element, to check whether the elements in the set, computing the intersection, collection, and set, obtain a random element from the collection
token Mapping between the order ordered string member (Member) and floating-point score (score), is determined by the size of the element score Add, Get, delete individual items; according to the score range (range) or may be a member of the element.
hash Unordered hash table that contains key-value pairs Add, Get, remove a single key-value pairs; get all the pairs.

Simple redis generally ask the difference between the results of the data, processes caching, clustering mechanism, redis read cache and database differences

redis installation

Refer to the following article to install
https://www.jianshu.com/p/e90317668ae2
https://redis.readthedocs.io/en/2.4/sorted_set.html

redis start

Redis in local debugging, then you need to start redis server, and then operate on redis
1. Start redis service

redis-server

2. Connect redis

redis-cli
#redis-cli -h host -p port -a password
127.0.0.1:6379>

127.0.0.1 as the default for the host ip, 6379 is the default port
after China Unicom redis, we can carry out normal read and write capabilities of redis

string operation
set name yeyeyeyey
set age 22
get name
get age

keys *
1) "age"
2) "name"
"yeyeyeyey"
"22"
hash operation

redis hash field is a string type and the value of the mapping table, hash is particularly suited for storing objects.

Each hash may be stored Redis 232--1 key-value pair (40 million)

127.0.0.1:6379> HMSET key name 'lsj' age '25' sex "male"
127.0.0.1:6379> HGETALL key
1) "name"
2) "lsj"
3) "age"
4) "25"
5) "sex"
6) "male"
127.0.0.1:6379> HGET key name
"lsj"
127.0.0.1:6379> HGET key age
"25"
127.0.0.1:6379> HGET key sex
"male"

May be provided by the value corresponding to HMSET, values ​​can be obtained by name HGET key name, or HGETALL key to get values ​​for all

Operation list
LPUSH listkey age name 10 0
127.0.0.1:6379> LRANGE listkey 0 10
1) "age"
2) "name"
3) "10"
4) "0"

By lpush key value corresponding to the inserted data listkey, lrange 0 10 taken through a range of values
herein simply describes the basic usage, reference to the following more detailed tutorial can
https://www.runoob.com/redis/redis- lists.html

Set operations
127.0.0.1:6379> sadd testset redis
(integer) 1
127.0.0.1:6379> sadd testset mongodb
(integer) 1
127.0.0.1:6379> sadd testset sql
(integer) 1
127.0.0.1:6379> smembers testset
1) "sql"
2) "mongodb"
3) "redis"

sadd be a collection of new operations, smembers see the collection of all elements

Ordered set of operations
127.0.0.1:6379> zadd azset 1 redis
(integer) 1
127.0.0.1:6379> zadd azset 3 redisee
(integer) 1
127.0.0.1:6379> zadd azset 2 mysql
(integer) 1
127.0.0.1:6379> zadd azset 6 mongdb
(integer) 1
127.0.0.1:6379> ZRANGE azset 0 10
1) "redis"
2) "mysql"
3) "redisee"
4) "mongdb"

Adding an ordered set of data, the range of data sets showing zrange zadd

redis command comes with performance testing
#以下实例同时执行 10000 个请求来检测性能
redis-benchmark -n 10000  -q

For more information see the following links course
https://www.runoob.com/redis/redis-tutorial.html

Guess you like

Origin www.cnblogs.com/yeyeyeyey/p/12121185.html