easy to understand and parse. This is useful in some scenarios. For example, you cannot use the FLUSHALL command to clear all the data, and AOF logs are not overwritten, you can simply stop the Redis Server and remove the last FLUSHALL command in the log to restart the Redis Server to recover data.AOF disadvantagesThe same dataset AOF file is much larger than the RDB file.Based on the fsync method, AOF may
Write Redis client by yourself-Redis protocol (1), redis Client
Network Layer
The client interacts with the server over TCP connections. The default port number of the server is 6379.
All commands or data sent by the client and server end with \ r \ n (CRLF.Request
The Redis
timePersistRemove key that expires in lifetimeIf the key expires true if it does not expire falseMset (more than 1.1 Redis version can be used)Assigning multiple keys at the same time$redis-gt;mset (Array (' key0′=gt; ' value0′, ' key1′=gt; ' value1′));Multi, exec, discardEnter or exit Transaction modeParameter optional Redis::multi or
Redis Summary (4) Redis persistence, redis Summary
I have summarized the installation and use of Redis. Today I will talk about Redis persistence.
Similar to memcached, redis is a memory database. However,
://commons.apache.org/proper/commons-pool/download_pool.cgi
or http://download.csdn.net/detail/teamlet/8914319.Third, Redis client command
I've also said a REDIS-CLI command to execute, and here are some other commands.
#redis-cli-h 127.0.0.1-p 6379
The above command should be very nice to understand, the-h parameter s
Directory
1. redis Introduction 2. redis installation and configuration 3. Programming Using redis
1. redis Introduction
0x1: What is redis?
Redis is a nosql-type key-value-based high-speed cache system,
In terms of architecture
in the following ways:StringA Redis string is a sequence of bytes. Redis strings are binary safe, which means they have a known length without any special characters terminating, so you can store anything, 512 megabytes for the upper limit.ExampleRedis 127.0.0.1:6379> SET name "Yiibai" Okredis 127.0.0.1:6379> GET name "Yiibai"Above is an example of Redis's set and get
node, that is, the current node. The status of the entire cluster is fail.
4. Allocate hash slot
Through the above operations, we have planned three independent Redis nodes to the same cluster. Have we completed all the work of cluster construction now? None! By checking the cluster status in Figure 2, we can know that the current cluster status is still fail. At this time, the Redis cluster does not work
versions.Analysis Jedis source code, the request retries reached the upper limit, still no successful request. Two-way analysis: Redis connection is not on? Or is the cluster node information inconsistent?
Defect of survival detection mechanismThe Redis survival detection mechanism may be considered to be in the failed state and switch because of a slow query on the master node, blocking
duplicate, write value$redis->setnx (' key ', ' value ');$redis->setnx (' key ', ' value '); Delete Deletes the value of the specified keyReturns the number of keys that have been deleted (long integers)$redis->delete (' Key1 ', ' key2 ');$redis->delete (Array (' Key3 ', ' key4 ', ' key5 ')); TtlGet a key to the time
Deletes the value of the specified keyReturns the number of keys that have been deleted (long integers)$redis->delete (' Key1 ', ' key2 ');$redis->delete (Array (' Key3 ', ' key4 ', ' key5 ')); TtlGet a key to the time of survival PersistRemove key for lifetime expirationIf the key expires true if it does not expire false Mset (Redis version 1.1 or above only av
/redis-server cliexec=/usr/local/redis/bin/redis-cli PIDFILE=/var/run/ Redis_${redisport}.pid conf= "/etc/redis/${redisport}.conf" case "$" in start) if [-F $PIDFILE] t Hen echo "$PIDFILE exists, process is already running or crashed" else echo "Start ing Redis server ..
'); Delete Deletes the value of the specified keyReturns the number of keys that have been deleted (long integers)$redis->delete (' Key1 ', ' key2 ');$redis->delete (Array (' Key3 ', ' key4 ', ' key5 ')); TtlGet a key to the time of survival PersistRemove key for lifetime expirationIf the key expires true if it does not expire false Mset (Redis version 1.1 o
. The path and file name must be configured separately because Redis first writes the status of the current database to a temporary file during Backup. When the backup is complete, replace the temporary file with the file specified above,
# The temporary files and the backup files configured above are stored in the specified path.
Dir ./
# Master-Slave replication. Use slaveof to make a Redis instance a co
Order of 2
Zrange myzset 0-1 withscores # view all elements and sort them in ascending order by default ).
Zrem myzset "two" # Delete two
Zincrby myzset 2 "two" # add the two Sequence Value to 2
Zrank myzset "two" # Return the index value of the element in the set.
Zrevrank myzset two # The element is reversed and a new value is returned.
Zrevrange myzset 0-1 withscores # reverse in order (equivalent to descending order)
Zrangebyscore myzset 1 10 withscores # returns elements in the order of 1-
the value of the specified keyReturns the number of keys that have been deleted (long integers)$redis->delete (' Key1 ', ' key2 ');$redis->delete (Array (' Key3 ', ' key4 ', ' key5 '));TtlGet a key to the time of survivalPersistRemove key for lifetime expirationIf the key expires true if it does not expire falseMset (Redis version 1.1 or above only available)Ass
persistence
Master-slave settings
Asynchronous replication
Monitor sentpost, pass, and automatic troubleshooting
Transactions
Publish and subscribe to messages
Automatically reclaim the least frequently used key values
Automatically reclaim expired key values
Script (use Lua)
Basic Use Cases of Redis
Redis can be used for multiple purposes. It acts as an ultra-fast distributed buffer. However, it i
number of clients reached '. # limit the number of customers connected at the same time. When the number of connections exceeds this value, # redis no longer receives other connection requests, and the client will receive an error message when trying to connect # maxclients 12816. maxmemory
# Don't use more memory than the specified amount of bytes. # When the memory limit is reached Redis will try to remo
,# It is best to set this item in the production environment# Bind127.0.0.1# Specify the path for the unix socket that will be used to listen#Incoming connections. There is no default, so Redis will not listen# OnUnix socket when not specified.## Unixsocket/tmp/redis. sock#Unixsocketperm 755# Set the timeout time for client connection, in seconds. When the client does not send any
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.