Redis Basic Introduction Building

Source: Internet
Author: User
Tags allkeys delete key system log

1.redis Basic Introduction 1.1 Redis Introduction
    • Redis is a non-relational database similar to memcached, and Redis is also a key-value-type storage System.
    • However, Redis supports more storage value types, including string (string), list, set (set), and Zset (ordered collections).
    • These data types support Push/pop, Add/remove, and intersection, set and difference sets, and richer operations, and these operations are atomic in nature. To ensure efficiency, REDIS data is cached in memory.
    • 区别是redis会周期性的把更新的数据写入磁盘或者把修改操作写入追加的记录文件,并且在基础上实现了master-slave(主从)同步。
1.2The difference between Redis and Memecache
    • Storage: Memecache all the data in memory, after power off will hang, the data can not exceed the size of the memory, Redis has a part of the hard disk, so as to ensure the persistence of data, support the persistence of data (the author note: There are RDB snapshot and aof log two persistent ways, In the actual application, pay special attention to the configuration file snapshot parameters, or it is likely that the server is frequently loaded dump)
    • Data support type: Redis has much more data support than Memecache.
    • Using the underlying model is different: The new version of Redis directly builds its own VM mechanism, because the general system calls system functions, it will waste a certain amount of time to move and request.
    • Operating environment is different: Redis is currently only supported by the Linux line, thus eliminating the support for other systems, so that can better focus on the system environment optimization, although later Microsoft has a team to write a patch for it. But not on the trunk.

Summary: For the choice of the two or to see the specific application scenario, if you need to cache the data is only key-value such a simple structure, I still use memcache in the project, it is stable and reliable enough. If you are involved in a series of complex operations such as storage, sorting, and so on, Redis is no doubt chosen.

1.3 Redis Application Scenario
The best Redis usage scenario is themost memcached alternative to all data in-Memoryredis more scenarios to usewhen you needmore data type support than key/value Using Redis is more appropriate when the stored data cannot be rejected.
1.4 Redis Supported key-value types
    • string literal type
    • Hash hash type
    • List type
    • Set Collection type
    • Zset有序集合类型
2. Installing Redis
[[email protected] ~]# cd/usr/local/src/[[email protected] src]# wget-q http://download.redis.io/releases /redis-3.2.8.tar.gz #-q hidden [[email protected] src]# tar XF redis-3.2.8.tar.gz[[email protected] src]# CD Redis-3.2.8/[[email protected] src]# make[[email protected] src]# make prefix=/usr/local/redis01 install[[ Email protected] redis01]# Tree/usr/local/redis01//usr/local/redis01/└──bin├──redis-benchmark #redis Performance reading and writing Test tool ├──redis-check-aof #对更新日志appenonly. AOF Check, similar to the MySQL Binlog├──redis-check-rdb #用于本地数据库r              db file Check ├──redis-cli #redis命令行客户端操作工具 ├──redis-sentinel-Redis-server└──redis-server #redis服务器daemon启动程序1 directory, 6 files[[email protected] redis01]# echo "Export path=/usr/local/redis01 /bin: $PATH ">>/etc/profile[[email protected] redis01]# source/etc/profile[[email protected] redis01]# Redis-server & #启动 [[Email protectEd] redis01]# redis-cli #进入到客户端127 .0.0.1:6379> keys * (empty list or set) 127.0.0.1:6379> Exit[[email prote CTED] redis01]# redis-cli shutdown #关闭
2.1 Specifying Profile Startup
[[email protected] redis01]# pwd/usr/local/redis01[[email protected] redis01]# mkdir-p conf[[email protected] redis01]# cp/usr/local/src/redis-3.2.8/redis.conf Conf/[[email protected] redis01]# redis-server/usr/local/redis01/conf/ Redis.conf &

To resolve the warning information of the startup report:

Selectable values: 0, 1, 2

0  内核将检查是否有足够的可用内存供应用进程使用;如果有足够的可用内存,内存申请允许;否则,内存申请失败,并把错误返回给应用进程。1  内核允许分配所有的物理内存,而不管当前的内存状态如何。2  内核允许分配超过所有物理内存和交换空间总和的内存

Three methods of setting:

  1. 编辑/etc/sysctl.conf ,改vm.overcommit_memory=1,然后sysctl -p 生效
  2. sysctl vm.overcommit_memory=1
  3. echo 1 > /proc/sys/vm/overcommit_memory
2.2 Redis configuration file Introduction
Daemonize Yes#whether the next process runsPidfile/var/run/redis/redis-server.pid#PID File LocationPort 6379#Listening PortBind 127.0.0.1#bind the address, such as the extranet needs to connect, set 0.0.0.0 space-delimitedTimeout 300#connection time-out, per secondLogLevel Notice#log levels, respectively, are:        #Debug: For development and testing        #verbose: More details        #Notice: Suitable for production environments        #Warning: Log only warnings or error messagesLogfile/var/log/redis/redis-server.log#Log File LocationSyslog-enabled No#whether to output the log to the system logDatabases 16#set the number of databases, the default database is 0############### Snapshot mode ###############Save 900 1#after 900s (15m), at least 1 keys have changed, the snapshotSave 300 10#after 300s (5m), at least 10 keys have changed, the snapshotSave 60 10000#after 60s (1m), at least 1000 keys have changed, the snapshotRdbcompression Yes#whether to compress data at dumpDir/var/lib/redis#Database (DUMP.RDB) file storage directory############### master-slave replication ###############Slaveof <masterip> <masterport>#Master -slave replication used for native Redis as slave to connect to primary RedisMasterauth <master-password>#when Master sets the password authentication, slave uses this option to specify the Master authentication passwordSlave-serve-stale-data Yes#When the connection between slave and master is disconnected or slave is synchronizing with master, if there is a slave request, when set to Yes, slave still responds to the request, there may be a problem, and if you set no, slave returns "Sync With Master in progress "error message. Except for the info and slaveof commands. ############### Safety ###############Requirepass foobared#Configure the Redis connection authentication password############### Limit ###############MaxClients 128#set the maximum number of connections, 0 is UnlimitedMaxMemory <bytes>#Memory Cleanup Policy, if this value is reached, the following actions are taken:        #VOLATILE-LRU: The default policy is to remove the LRU algorithm only for keys that set the expiration time        #ALLKEYS-LRU: Delete infrequently used keys        #volatile-random: Randomly delete the expiring key        #allkeys-random: Randomly delete a key        #Volatile-ttl: Delete key that is about to expire        #Noeviction: However, the write operation returns an errorMaxmemory-policy VOLATILE-LRU#if the MaxMemory value is reached, use this policyMaxmemory-samples 3#by default, 3 keys are randomly selected, which eliminates the most common############### Additional mode ###############AppendOnly No#aof Persistent, whether the update operation log is logged, the default Redis is asynchronous (snapshot) to write data to the local diskAppendfilename appendonly.aof#Specify the update log file name        #AOF Persistent Three synchronization strategies:        #Appendfsync always #每次有数据发生变化时都会写入appendonly. AoF        #Appendfsync everysec #默认方式, synchronized once per second to appendonly.aof        #Appendfsync No #不同步, data is not persistedNo-appendfsync-on-rewrite No#when the aof log file is about to grow to a specified percentage, Redis automatically rewrites the aof log file by calling Bgrewriteaof. ############### virtual Memory ###############Vm-enabled No#whether the virtual memory mechanism is enabled, the virtual memory machine paging the data, placing the rarely accessed pages on swap, memory consumption, preferably shutting down the virtual memoryVm-swap-file/var/lib/redis/redis.swap#virtual Memory File locationVm-max-memory 0#maximum memory limit used by Redis, protecting Redis from excessive use of physical memory affects performanceVm-page-size 32#the size of each page is 32 bytesVm-pages 134217728#set the number of pages in a swap fileVm-max-threads 4#number of threads accessing swap files############### Advanced Configuration ###############Hash-max-zipmap-entries 512#a linear compact format is used to save space when the total number of elements (entries) in a hash table does not exceed the set numberHash-max-zipmap-value 64#a linear compact format is used to save space when the length of each value in the hash table does not exceed the number of bytesList-max-ziplist-entries 512#list data type How many nodes below will use a compact storage format for pointersList-max-ziplist-value 64#The list data type node value size is less than how many bytes are in compact storage formatSet-max-intset-entries 512#Set Data type internal data if all are numeric, and how many nodes are included the following are stored in a compact formatactiverehashing Yes#whether to activate reset hash

Redis Basic Introduction Building

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.