Redis Summary-Redis installation, redis summary Installation
Redis needs to be used in recent projects. We will record the installation of Redis and how to use Redis in. NET within the past two days.
# Volatile-ttlRemove the expiring key (minor TTL)# noeviction not remove any can, just return a write error##Note: For the above policy, if no appropriate key can be removed, Redis will return an error when writing## Write commands include: Set SETNXSetex Append# incr DECR rpush lpush rpushx lpushx linsert LSetRpoplpush Sadd# sinter Sinterstore sunion sunionstore sdiff sdiffstoreZadd Zincrby# zunionstore Zi
the least recently used key from the key space.It is recommended. This is currently used in projects.3) allkeys-random: When the memory is insufficient to accommodate newly written data, a key is randomly removed from the key space.There should be no one to use. If you do not delete at least keys, delete them randomly.4) volatile-LRU: When the memory is insufficient to accommodate newly written data, remove the least recently used key from the key space with an expiration time.In this case,
Assume that the two redis servers have ip addresses 192.168.1.101 and 192.168.1.103 respectively. How can I access redis on redis 101 through redis-cli on redis 103? Before remotely connecting to redis 103, let's talk about severa
does Redis Delete the key. You can choose from the following five policies:## Volatile-lru-> delete an instance based on the expiration time generated by the LRU algorithm.# Allkeys-lru-> delete any key based on the LRU algorithm.# Volatile-random-> Delete keys randomly based on expiration settings.# Allkeys-> random deletion without difference.# Volatile-ttl-> Delete (supplemented by
true; ///In seconds, returns the remaining lifetime of the given key $TTL = $this-gt;redisstring-gt;ttl ($redisKey); A TTL of less than 0 indicates that no lifetime is set on the key (key does not exist because the previous setnx is created automatically)//If this happens, it is an instance of the process Setnx successful crash causes the followed expire to not
connection reaches the specified value and returns ' Max number of clients reached ' error message;# maxmemory: Set Redis maximum available memory. When the maximum memory is reached, Redis attempts to delete the key values according to the set recycle policy. If the key value cannot be deleted, or if the retention policy is set to not clear, Redis returns an er
avalanche effect, Then you can control that there is only one request to update the cache, and the other requests are either waiting or using an expired cache
$ok = $redis->setnx ($key, $value);
if ($ok) {
$cache->update ();
$redis->del ($key);
}
Issue 1: The effective time of the lock
If the setnx succeeds, but because the unexpected reason did not execute to the DEL program on the problem, or because
Redis is a storage service that supports structures such as K-V and data can be implemented (memcache data is memory data and cannot be implemented)
Let's enter the redis world to find out.
Enter redis through the command line:
Use PS aux | grep redis to check whether the redis
(). c_str (); freeReplyObject (reply); return redis_sorted_list_key; // return the LIST key, so that other functions can obtain the content in the LIST.
Obviously, sorting hash keys in the result set is more intuitive and convenient than sorting string keys. The sorting function allows you to conveniently query the sorted result set in Redis. The Code is as follows:
// This function queries and sorts corresponding result sets in
to synchronize data once per second.(3) In order to Speed Master-slave replication and connection stability, it is best for master and slave to be in the same LAN(4) try to avoid adding slave databases to the master database with great pressure(5) do not use a graph structure for master-slave replication. The one-way linked list structure is more stable, that is, master This structure is convenient for solving single point of failure (spof) and implementing slave's replacement of master. If the
reaches the maximum memory.#Redis also removes empty list objects##When this method is processed, the maximum memory setting is still reached and the write operation is no longer available, but the read operation is still possible##Note: Redis's new VM mechanism will store the key in memory, and value will be stored in the swap area.##The MaxMemory setting is more appropriate for using Redis as a memcached
First, design ideas:
When Master and Slave are operating normally, Master is responsible for service, Slave is responsible for standby;
When Master hangs out, Slave Normal, Slave takes over the service, has the Write permission, simultaneously closes the master-slave copy function;
When Master returns to normal, the data is synchronized from the slave, the master-slave copy function is turned off after the data is synchronized, and the master is restored, while sla
Redis Common Command set
1 Connection operation Command quit: Close the connection (connection) Auth: simple password Authentication help cmd: View cmd assistance, for example: helping quit
2 Persistent Save: Synchronize data to disk Bgsave: Asynchronously save data to disk Lastsave: Returns the last Unix timestamp that successfully saved data to disk Shundown: Synchronize data to disk, and then turn off services
3 Remote Service Control info: Provid
of the key without deleting the key, so that the key becomes a persistent key again.
2. How to update the survival time
You can execute the expire command on a key with a life time. The new life time will replace the old one. The precision of the expiration time has been controlled within 1 ms. The complexity of the primary key expiration time is O (1). the expire and TTL commands can be used together to check the current survival time of the key. I
applicable.
3.2 Develop the Code of development
Slow queries, process CPU 100%, client requests slow, or even time out.
Avoid generating Hot-key, which causes the node to become the short board of the system.
Avoid generating big-key, resulting in network card explosion, slow query.
TTL, set a reasonable TTL, and free up memory. Avoid a large number of keys that expire at the same
that satisfy the given pattern>>> keys *>>> Keys r*exists confirm if a key exists 0 does not exist 1 exists>>> exists name>>> exists ageDel Delete a key 1 success>>> del AgeExpire setting the expiration time for a keyTTL gets the effective duration of a key>>> expire age 10>>> TTL ageMove moves the key of the current database to another librarySelect Database>>> Select 0>>> Set Age 30>>> Get Age>>> Move age 1>>> Get Age>>> Select 1>>> Get AgePersist
Suppose two redis servers, IP: 192.168.1.101 and 192.168.1.103, how do I access Redis on 101 through REDIS-CLI on the 103? before remote connection 103, let's talk about some key parameters of Redis-cli:Usage: redis-cli [OPTIONS] [cmd [arg [arg ...]]-H -p -A --help, display
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 Server accepts commands and command paramete
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.