Redis Learning Record

Source: Internet
Author: User
Tags object serialization

Redis is a key-value storage system. Similar to memcached, it supports storing more value types, including string (string), list (linked list), set (set), Zset (sorted set-ordered collection), and hash (hash type). These data types support Push/pop, Add/remove, and intersection-set and difference sets, and richer operations, and these operations are atomic. Based on this, Redis supports sorting in a variety of different ways. As with memcached, data is cached in memory to ensure efficiency. The difference is that Redis periodically writes the updated data to disk or writes the modified operation to the appended record file, and Master-slave (Master-Slave) synchronization is implemented on this basis. Redis is a high-performance Key-value database. The emergence of Redis, to a large extent, compensates for the lack of memcached such key/value storage, in some cases can be a good complement to the relational database. It provides clients such as Java,c/c++,c#,php,javascript,perl,object-c,python,ruby,erlang, which is convenient to use.[1]Redis supports master-slave synchronization. Data can be synchronized from the primary server to any number of slave servers, from the server to the primary server that is associated with other slave servers. This enables Redis to perform single-layer tree replication. You can write to the data intentionally or unintentionally. Because of the full implementation of the publish/subscribe mechanism, you can subscribe to a channel and receive a complete message release record from the master server when the tree is synchronized anywhere from the database. Synchronization is helpful for the scalability and data redundancy of read operations. Redis's official address, very good remember, is Redis.io. (specifically checked, the domain name suffix io belongs to the national domain name, is British Indian ocean Territory, namely British Indian Ocean Territory)

Currently, VMware is funding the development and maintenance of REDIS projects.

5 Basic type:string Hash list set zsetstringsstring is the simplest type, is binary security containing any data than slice and object serialization set name Helloget Keysetnx if K exists back plus 0 NX Note EX The IST does not overwrite, does not exist to set the new value Setnx name Hellosetex sets the value of K to a string type of value and specifies the validity period Setex Namex jak 10 seconds validity setrange Setting the substring of the value of the specified key GE T name[email protected]setrange name 8 aaaaaa Replace the specified length from the subscript the same as the replace. Get Namemset set multiple key values at once failed all unsuccessful Mset K1 xiaoming K2 Xiaohon  GMSETNX Note Exis does not overwrite the value of the existing Keygetset setting key and returns the old value of key Getset K1 Hellogetrange gets the substring of key's value GetRange K1 0 3 returns from 0 to 3rd Mget Bulk get mget K1 k2incr increment set K3 10incr k3incrby K4 10 plus specified value key does not exist set key to think the original value is 0incrby K4-10DECR to the value of the key to make the decrement Decrby specify minus AP Pend appends a string to the specified key valueappend K1 world  return length strlen return value length strlen K1

The HashSet type is a string-type field and value mapping table, and its addition, delete operations are 0 (1) (average) hash is particularly suitable for storing objects, compared to each word of the object Gencun into a single string Type will have an object in the hash will take up very little inside, and can easily access the entire object Hset set hash field for the specified value  if key does not exist first create Hset myhash field Hellohset user:001 name Jakhget user:001 namehsetnx user:002 name hellohmset Batch Set value hmset myhash field Hello field2 worldhmget get all kin hmget user:002 na Me age x Bulk return Hincrby user:002 ages 10 hexists hash table field exists hexists user:002 Agehlen returns the key number of the specified hash hlen user:002hdel delete the specified hash Field field Hdel Myhash agehkeys return hash all fields Hkeys user:002hvals return hash all valuehvals User:002hgetall get all fields and values in a hash hgetall user:002


============ ======list Start===========================list is a linked list structure, the main function is Push,pop, get all the values of a range and so on, the operation of key is understood as the name of the list. The Redis list type is actually a doubly linked list in which each child element is a string type. We can add delete elements from the head or tail of the linked list by push pop operation so that the list can be used as a stack and as a queue. Push presses an element pop pops up an element lpush from the head into an element advanced out of Lpush mylist worldlpush mylist hellolrange mylist 0-1 take element Hello Worldrpush from the rear pressure into the meta Vegetarian FIFO queue Rpush list2 jakrpush list2 tomlrange list2 0-1jaktomlinsert add string before or after key corresponds to a specific position of list Linsert list2 before Jak su MlSet Settings list specify subscript element to replace LSet List2 1 updatevlrem Remove N and value elements from key corresponding list (n<0 delete from tail, n=0 delete all) Lrem list2 2 jak Delete Several elements LTrim retain data within the value range of the specified key LTrim list2 1-1 Delete the No. 0 one lpop remove the element from the head of the list and return the delete element Lpop List2 Rpop from the tail an element Rpop List2lpoplpush from the first The tail of the list removes the element and adds it to the second list's head Lpoplpush list2 List3lindex returns the element with the index position in the list named key Linex list2 0lindex List2 1llen Returns the key corresponding to the list length Sllen list2==================list end=========================== 

===========sets unordered collection ================sadd myset1 onesadd myset1 twosadd myset1  Double cannot increment duplicate value smembers myset1 view element Srem Delete Srem myset1 onespop random pop-up element Sdiff returns the difference between all given key and first key Sdiff Myset1 myset2sdiffstore Storage Difference Set value Sdiffstore myset3 Myset1 Myset2sinter intersection sinter Myset1 myset2sinterstore  Stores the value of the intersection sunion returns the set of all the given keys sunion Myset1 Myset2sunionstore Save and set Smove Remove the element from the set corresponding to the first key and add it to the second set in Mockers smove Myset1 Myset2 Three move three from 1 to 2 SCard returns the number of sets for the name key Sismember Tests whether an element is a set element named key Sismember Myset1 1 represents a sismember Myset1 Twox returns 0 represents an element that is not srandmember randomly returns a collection, but does not delete the element srandmember myset1====================



=============sorted sets ordered set =========================== is an upgraded version of Set plus a sequential attribute Zset is automatically reordered and can be understood as a column with two columns of MySQL table with value In the order of a column, the key can be understood as the name Zadd to add elements to the Zset named key member,score for sorting if the element exists, then update its order zadd myzset 1 onezadd myzset 2 twozadd myzset 3 Two will update the order to 3zrange Myzset 0-1 withscores 0 First position-1 the last Zrem delete the element in Zset named key Memberzrem myzset1 Onezincrby to specify a value increment if the name is called The element memebre is already present in the zset of the key, the score of the element is added incremernt otherwise adds the element to the collection, its score value is Incrementzincrby Myzset 4, and the order number is incremented-the number is reduced by Zrank Returns the rank of the MEMEBR element in Zset named key (sorted by score from small to large) that is subscript Zrank Myzset1



Redis Learning Record

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.