|
Recent Items To use Redis, especially during this time will be Redis learning experience to share with you, this time as a way to learn the outcome of the review and refine technology, inadequacies also hope you criticism.
Background of the project:
Some small changes and data (such as the system in the drop-down list data) often use the system frequently and SqlServer database for data exchange, greatly increased the burden on the server and SqlServer data, databases and servers in order to reduce the burden of SqlServer improve program efficiency, considering the solid separate out some of the data used to run faster database performance optimization, all memory database Redis is the best choice.
Select Redis project purpose:
(1) Redis respect memcached supports more data types (string string, list doubly linked lists, hash tables, set and zset).
(2) Redis supports data persistence.
(3) to facilitate the expansion of the cluster.
Use Redis targets to be achieved:
(1) reduce the pressure SqlServer server relational database, less interactive system with Sql database.
(2) improve the efficiency program.
(1) Linux system Redis installation (Linux beginners can use the remote connection Xshell5 Linux, execute the following command)
1) Download the tar package (Redis current latest version is 3.0.6, updated: 2015-12-18)
# Wget http://download.redis.io/releases/redis-2.8.24.tar.gz
After executing the command, execute the command ls -la
2) extracting
# Tar xzf redis-2.8.17.tar.gz
Run this command you will find that success has been unpacked, the current more than a redis-2.8.24 folder directory
3) Open the folder redis-2.8.24
# Cd redis-2.8.24
4) Run make command
# Make
Step 4) after the implementation, redis has been successfully downloaded to the local, the next step is to run open redis redis-server service
5) run Redis, open Redis-server
# Cd redis-2.8.24
# Src / redis-server
After running the above command, it appears as follows, explained that it had opened properly redis-server service (default port number: 6379), this time redis client will be able to access and appropriate action Redis
Has successfully opened a Redis-server, the client has to redis normal for normal operation.
However, redis-server open at the same time, there is also a big black doc is on, the next on to explain how to make redis-server runs in the background on the Linux system (the equivalent of running the service station after the windows system)
(1) Open redis.conf profile
#vim redis.conf
(2) open, I press the keyboard keys to redis.conf file for editing
Parameter 1: Set yes, let redis-server process running to protect, which is equivalent to background services running under the windows system (the parameter default no)
Parameter 2: Set redis-server daemon process ID number to save the file
Parameter 3: Set redis-server port number
(3) After editing, press the Escape key, enter: wq (save changes and close the current document redis.conf)
(4) Let redis-server configuration file to set up, run, after the command as shown below
# Src / redis-server redis.conf
note:
1) must ensure that the file has been opened redis-2.8.24
2) redis.conf To file directory, for example: If you save a file redis.conf under / home file, then it should be # src / redis-server /home/redis.conf
Details redis.conf profile refer to essays --Redis profile (redis.conf) Description
Redis configuration
Redis Redis configuration file located in the installation directory under the file name redis.conf.
You can CONFIG command to view or set the configuration items.
Syntax 3>
Redis CONFIG command format is as follows:
redis 127.0.0.1:6379> CONFIG GET CONFIG_SETTING_NAME
Examples
redis 127.0.0.1:6379> CONFIG GET loglevel
1) "loglevel"
2) "notice"
Press * to get all configuration items:
Examples
redis 127.0.0.1:6379> CONFIG GET *
1) "dbfilename"
2) "dump.rdb"
3) "requirepass"
4) ""
5) "masterauth"
6) ""
7) "unixsocket"
8) ""
9) "logfile"
10) ""
11) "pidfile"
12) "/var/run/redis.pid"
13) "maxmemory"
14) "0"
15) "maxmemory-samples"
16) "3"
17) "timeout"
18) "0"
19) "tcp-keepalive"
20) "0"
21) "auto-aof-rewrite-percentage"
22) "100"
23) "auto-aof-rewrite-min-size"
24) "67108864"
25) "hash-max-ziplist-entries"
26) "512"
27) "hash-max-ziplist-value"
28) "64"
29) "list-max-ziplist-entries"
30) "512"
31) "list-max-ziplist-value"
32) "64"
33) "set-max-intset-entries"
34) "512"
35) "zset-max-ziplist-entries"
36) "128"
37) "zset-max-ziplist-value"
38) "64"
39) "hll-sparse-max-bytes"
40) "3000"
41) "lua-time-limit"
42) "5000"
43) "slowlog-log-slower-than"
44) "10,000"
45) "latency-monitor-threshold"
46) "0"
47) "slowlog-max-len"
48) "128"
49) "port"
50) "6379"
51) "tcp-backlog"
52) "511"
53) "databases"
54) "16"
55) "repl-ping-slave-period"
56) "10"
57) "repl-timeout"
58) "60"
59) "repl-backlog-size"
60) "1048576"
61) "repl-backlog-ttl"
62) "3600"
63) "maxclients"
64) "4064"
65) "watchdog-period"
66) "0"
67) "slave-priority"
68) "100"
69) "min-slaves-to-write"
70) "0"
71) "min-slaves-max-lag"
72) "10"
73) "hz"
74) "10"
75) "no-appendfsync-on-rewrite"
76) "no"
77) "slave-serve-stale-data"
78) "yes"
79) "slave-read-only"
80) "yes"
81) "stop-writes-on-bgsave-error"
82) "yes"
83) "daemonize"
84) "no"
85) "rdbcompression"
86) "yes"
87) "rdbchecksum"
88) "yes"
89) "activerehashing"
90) "yes"
91) "repl-disable-tcp-nodelay"
92) "no"
93) "aof-rewrite-incremental-fsync"
94) "yes"
95) "appendonly"
96) "no"
97) "dir"
98) "/home/deepak/Downloads/redis-2.8.13/src"
99) "maxmemory-policy"
100) "volatile-lru"
101) "appendfsync"
102) "everysec"
103) "save"
104) "3600130010060 10000"
105) "loglevel"
106) "notice"
107) "client-output-buffer-limit"
108) "normal 0 0 0 slave 268435456 67108864 60 pubsub 33554432 8388608 60"
109) "unixsocketperm"
110) is "0"
111) "slaveof"
112) ""
113) "notify-keyspace-events"
114) ""
115) "bind"
116) ""
Edit Configuration
You can modify redis.conf file or use the CONFIG set command to modify the configuration.
grammar
CONFIG SET command basic syntax:
redis 127.0.0.1:6379> CONFIG SET CONFIG_SETTING_NAME NEW_CONFIG_VALUE
Examples
redis 127.0.0.1:6379> CONFIG SET loglevel "notice"
OK
redis 127.0.0.1:6379> CONFIG GET loglevel
1) "loglevel"
2) "notice"
Parameter Description
redis.conf configuration items are described below:
1. Redis default is not running in daemon mode, you can modify the configuration item, use yes Enable daemon
daemonize no
2. When Redis when running in daemon mode, the default Redis will write /var/run/redis.pid pid file, you can specify pidfile
pidfile /var/run/redis.pid
3. Specify Redis monitor port, the default port of 6379, the author in his own blog post explains why the choice of 6379 as the default port as 6379 on the phone keypad MERZ corresponding number, and MERZ taken from the name of Italian showgirl Alessia Merz
port 6379
4. The host address binding
bind 127.0.0.1
5. When the client is idle long after closing the connection, if you specify zero disables the function
timeout 300
6. Specify the logging level, Redis supports a total of four levels: debug, verbose, notice, warning, the default is verbose
loglevel verbose
7. logging mode, the default is standard output, if you configure Redis to run in daemon mode, but this is also configured for logging to standard output mode, the log will be sent to / dev / null
logfile stdout
8. Set the number of the database, the default database is 0, you can use the SELECT < dbid > command on the connection specified database id
databases 16
9. Specify how long, how many times the update operation, the data will be synchronized to the data file, you can meet a number of conditions
save < seconds > < changes >
Redis default configuration file provides three conditions:
save 900 1
save 300 10
save 60 10000
Respectively, have a change 900 seconds (15 minutes), 300 seconds (5 minutes), there are 10 changes, and there are 10 000 Change in 60 seconds.
10. Is compression when storing data to a local database, the default is yes, Redis using LZF compression, if the CPU in order to save time, you can turn this option off, but will cause the database file becomes huge
rdbcompression yes
11. Specify the file name of the local database, the default value dump.rdb
dbfilename dump.rdb
12. Specify local database storage directory
dir ./
13. Set when the unit is slav service, set master service IP address and port when Redis starts, it will automatically synchronize the data from the master
slaveof < masterip > < masterport >
14. When the master service is password-protected, slav service connection master password
masterauth < master-password >
15. Set Redis connection password, if you configure the connection password, the client needs to provide the password when connecting Redis via AUTH < password > command, off by default
requirepass foobared
16. Set the same time the maximum number of client connections, the default limit, the maximum number of file descriptors client connections Redis Redis can be open simultaneously for the process can be opened, if set maxclients 0, indicates no restrictions. When the number of client connections reaches the limit, Redis will close a new connection to the client returns the max number of clients reached an error message
maxclients 128
17. Specify Redis maximum memory limit, Redis will be loaded at startup data into memory, after the maximum memory, Redis will first try to clear Key has expired or about to expire, when this method worked, still reach the maximum memory settings will no longer write operations, but can still be read. Redis new vm mechanism, Key will be stored memory, Value will be stored in the swap area
maxmemory < bytes >
18. Specify whether or after each update operation logging, Redis default is asynchronous to write data to disk, if not open, it may result in data over time lost during a power outage. Because redis itself synchronize data files are synchronized by the above save conditions, so some data over a period of time exists only in memory. The default is no
appendonly no
19. Specify the update log file name, the default is appendonly.aof
appendfilename appendonly.aof
20. Specify the update log criteria, there are three possible values:
no: indicates the operating system and other data synced to disk cache (fast)
always: after every operation indicates the update manually call fsync () writes data to disk (slower, security)
everysec: represents a second synchronous (compromise, the default value)
appendfsync everysec
21. Specify whether the virtual memory mechanism is enabled, the default is no, a brief look, VM paging mechanism to store data by Redis will visit less-page C13 swap data to disk, the disk access multiple pages automatically swapped out to the memory (in a later article I will carefully analyze the Redis VM mechanism)
vm-enabled no
22. The virtual memory file path, the default value /tmp/redis.swap, can not share multiple instances of Redis
vm-swap-file /tmp/redis.swap
23. In all more than vm-max-memory data into virtual memory, regardless vm-max-memory settings how small, all index data is stored in memory (Redis index data is keys), that is, when vm -max-memory is set to 0 when the value is actually all are present in the disk. The default value is 0
vm-max-memory 0
24. Redis swap file into a lot of page, an object can be stored in multiple page above, but can not be shared by multiple objects on a page, vm-page-size is to be based on the stored data set size, the authors If you store a lot of recommendations for small objects, page size is preferably set to 32 or 64bytes; if the storage lot large objects, you can use a larger page, if you are unsure, use the default values
vm-page-size 32
25. The number of swap file page, since the page table (page idle or a representation using bitmap) is placed in memory on the disk ,, every eight pages 1byte will consume memory.
vm-pages 134217728
26. Set the number of threads to access the swap file, it is best not to exceed the number of core machine, if set to 0, then all operations on the swap file is serial, it may cause relatively long delays. The default value is 4
vm-max-threads 4
27. set when the response to the client, whether the smaller packets into one package, is enabled by default
glueoutputbuf yes
28. specified when more than a certain amount, or the largest element exceeds a critical value, using a special hash algorithm
hash-max-zipmap-entries 64
hash-max-zipmap-value 512
29. Specify whether to reset the activation hash, is enabled by default (specifically described later when the hashing algorithm described Redis)
activerehashing yes
30. Specifies that contains other configuration files, you can use the same configuration files between multiple Redis instances on the same host, while each instance has its own specific profile
include /path/to/local.conf |
|
|
|