Redis is used A memory-based noSQL database written in C language that supports persistence and high-performance key-value. It mainly stores data with large access volume, frequent changes, and low security requirements.
2.NoSQL3.BSD protocol
4. Message middleware
5. Message queue
6.SOA
interfaces.
Second key namingThree common operations
3. Change
Starting from the end, the index starts from -1, -2. -3... setrange key index value: Replace starting from the index position. getrange key begin end: Get the value of the specified index range. getrange key 0 -1: Get all. 1. LinkedList, a doubly linked list, has low query efficiency and high addition and deletion efficiency. LPUSH key value01 value02: Push elements from the left. RPUSH key value02 value02: Push the element from the right. LPOP KEY: pop up an element from the left, quite To remove the element from the list. RPOP KEY: Pop up an element from the right. ltrim key start end: Delete elements outside the specified range. lrem key count value: Delete count elements with value in the linked list. count>0: Delete from the left. count<0: Delete from the right. count=0: Delete all. LINSERT key before/after oldValue newValue: Insert elements before and after the specified element, if specified If the element does not exist, no operation is performed. If there are multiple specified elements, only the first element will be operated. RPOPLPUSH key01 key02: Pop an element from the right side of key01 and push it to the left side of key02. llen key: The length is the number of elements in the list. From left to right, starting from 0; from right to left, starting from -1. LRANGE key start end: Get the elements in the specified index range. LRANGE key 0 -1: Get all elements. LINDEX key index: Get the value of the specified index position. LSET key index value: Set the value of the specified index position. The key value space stores not only the key value, but also other information, such as timeout Time, so the key takes up a lot of space. You should reduce the number of keys and store related data in the same key. This generates a data type hash, which is equivalent to a HashMap. In hash, the timeout duration can only be set on the key, not the field. hset key field value: Assign a value to a field in key. hmset key field01 value01 field02 value02: Assign values to multiple fields at the same time. hdel key field: Delete the specified field in key. ## hincrby key filed increment: Add an integer field. hincrbyfloat field increment: Increase the value of a floating point field. hgetall key: Get all fields and their corresponding values. hkeys key: Get all field names. # kvals key: Get the values of all fields. hexists key field: Determine whether the specified field exists in the key. # hlen key: Get the number of fields in the key. Unordered, non-repeatable. The so-called disorder means that the same collection is queried at different times, and the elements in the same sorting position are different. sadd key value01 vlaue02: Add element. srem key value01 value02: Delete element. # spop key: Randomly remove an element. smembers key: Get all elements srandmember key: Returns an element randomly. scard key: Returns the number of elements. sismember key value: Determine whether the value exists. The intersection and union operation will not delete the elements in the operated set . sdiff key01 key02: Find the difference set and delete the elements of key02 from key01. It is just an operation and will not delete the elements in key01. sdiffstore destination key01 key02: Store the difference set in the specified collection. suinon key01 key02: Find the union. sninonstore destination key01 key02: Store the union result in the specified collection. Sinter key01 key02: Find the intersection. Sinterstore destination key01 key02: Get the intersection and store it in the specified collection. Ordered set, the reason for ordering, each element is associated with a score , sorted according to score. zadd key score01 value01 score02 value02. zrem key value: Delete the specified element. zremrangebyrank key start end: Delete elements in the specified sort range. zremrangebyscore key min max: Delete elements in the specified score range. zincrby key increment value: Modify the score. zrank key value: Get the sorting, from small to large, starting from 0. zrevrank key value: Get the sorting, from large to small, starting from 0. ## zscore key value01: Get the score. zcard key: Get the number of elements in the collection. zrange key start end [with scores]: Get the value of the specified index range. You can add ( before min to indicate an open interval, and only min can be loaded. zcount key min max: Get the number of elements in the specified score range. destination: Union The collection in which the set results are stored. numKey: The number of collections participating in the operation. weights: Weights, that is, the percentage of scores participating in the calculation, are specified for each set separately. aggregate: integration strategy. zinterstore destination numKeys key[key...] weights weight aggregate max/min/sum: intersection operation. The process of saving data to the hard disk is called persistence. RDB: Redis DB, save all data to dump in binary form .rdb file, enabled by default. AOF: AppendOnlyFile, saves modifications to the database to a file, closed by default. RDB persistence will generate a dump.rdb file, overwriting the original file. RDB method The user issues a save operation: blocking the server. #The user issues a bgsave operation: it is executed in the background and will not block the server. The principle is to create a sub-thread to generate persistent files. #Configure in the configuration file and automatically persist when specified conditions are met. This is a common method. Configuration conditions: save RDB persistence method saves all the data in the database to the hard disk every time, consuming system resources and cannot be executed frequently. In order to ensure that the RDB interval is within For data security, AOF persistence can be used in parallel. ⑴The execution process of the system writing the data in the memory to the file: first write the data into the buffer, and then the buffer After the area is full, the contents of the buffer are written to the file. ⑵Append the modification operations to the database to the file, with the operations performed first coming first. #always: Every time a modification operation is performed, the file is written immediately. everysec: Write modification operations to the file once every 1 second, default value. #no: Determined by the system, the file will be written after the buffer is full. In order to avoid the AOP file being too large, you can rewrite the AOP file and add multiple operations are merged into one operation. Rewrite when the AOP file size reaches a certain value. 1. A Redis service can have multiple replicas of the service. This Redis service is called the master service, and other replicas The product is called slave service. 2. The master service will synchronize its data to the slave service. 3. The master service can both read and write, and the slave service can only read. 4. There are two ways to set a service as a slave service: The customer issues slaveof masterip masterport . #Configure in the configuration file: slaveof masterip masterport. 5. You can cancel the slave setting operation in the configuration file, or you can cancel it by the customer: slaveof no one 6. Problems with master-slave replication Configure a listener for the master server. This listener is called a sentry. When the master server fails, the sentinel automatically promotes a slave server to the master server. , thereby ensuring uninterrupted execution of the server. 1. In master-slave replication, the write task is still undertaken by one node, and the write pressure is not resolved. Therefore, the Twemproxy cluster mechanism was born. The user sends a request to the proxy, and the proxy allocates the write tasks to the nodes in the server pool. range the value falls in, which server is called. failure and the whole can still run. slaves. server to share the reading pressure. Integrated information from multiple other nodes. If it is judged that the node cannot work normally, promote a slave server of the node to the node. 2. Jedis is a client tool in java language that connects to the Redis server. 3. Jedis basically retains the command line method of accessing the Redis server. 4. Just as it is best to establish a connection pool to connect to a relational database, it is also best to establish a connection pool to connect to the Rdis database. The classes used when establishing a connection pool JedisPoolConfig/JedisPool.
Five LinkedList
2. Add
3. Delete
4. Change
5. Check
6. Index
六hash
1. Add
2. Delete
3. Modify
4. Check
Seven set
1. Add
2. Delete
3. Check
4. Intersection and union operation
八sortedset
1. Add
2. Delete
3. Change
4. Check
5. Union
zunionstore destination numKeys key[key...] weights weight aggregate max/min/sum
9 Rdis persistence
1. What is persistence?
2.Redis persistence method
3.RDB
4.AOF
⑶Several methods of AOP
⑷Rewriting of AOP files
Rewriting method:
The first method, BGREWRITEAOP: is used to send this operation and rewrite the AOP file.
The second method is to set configuration conditions and automatically rewrite when the conditions are met. The following are the rewriting conditions: auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
Ten clusters
Only one master server performs write operations. If the master server fails, the write operation cannot be performed. Eleven sentinal sentinel mechanism
1. What is the sentinel mechanism?
Twelve Twemproxy Cluster
Each server in the server pool has a receiving interval. After the client sends a request to the proxy, the proxy Get the hashcode of the key. Whichever
There is a central object, the proxy. If there is a problem with the proxy, the entire Redis service cannot be used. The solution is Decentralization allows a certain part to
1. What is native cluster mode?
Multiple Redis master servers form a cluster. Each Redis master server is called a node. The nodes communicate with each other. The nodes can have their own
Each node can communicate with all other nodes and act as a sentinel role to monitor other nodes. The operating status of the node. When a node fails
1. To access the Redis server in java, you need to import the shelf package jedis.jar.
The above is the detailed content of java: What does Redis do?. For more information, please follow other related articles on the PHP Chinese website!