Start Contact Contact redis!
Redis is not a simple key-value storage, in fact he is a data structure server that supports different types of values, in addition to the string as the key point to the value, but also contains the following types:
Binary Secure String strings
Binary Secure String list
Binary Secure String Collection Setof string
Ordered set sorted set of string, where each element has a socre, sorted according to the Socre
Simple to use:
String type:
$ redis-cli Set MyKey ' My binary safe value '
OK
$ redis-cli get MyKey i
binary safe value
A value can be set and obtained by using the set get command;
$ redis-cli Set counter
OK $ redis-cli incr counter
(integer)
$ redis-cli incr counter
(integer) 1
$ redis-cli Incrby counter
(integer) 112
You can resolve a string to a numeric type by using the INCR command;
List type
Redis lists is implemented based on linked lists. This means that even if there are millions of elements in a list, the time complexity of adding an element to the head or tail is constant. Add new elements to the 10-element list header with the Lpush command, and add new elements to the head of the million-element list.
$ redis-cli Rpush Messages "Hello How are you?"
OK
$ redis-cli rpush messages "Fine. I ' m has fun with Redis "
OK
$ redis-cli rpush Messages" I should look into this NOSQL thing ASAP "
OK
$ r EDIS-CLI lrange Messages 0 2
1. Hello how are?
2. Fine. I ' m have fun with Redis
3. I should look into this NOSQL thing ASAP
The Rpush command can add a new element to the right (tail) of the list. The last Lrange command can take a certain range of elements from the list;
Collection type:
The Redis collection is an unordered collection whose elements are binary secure strings. Can be implemented to detect the existence of an element, as well as the implementation of intersection, and set, difference sets and so on
$ redis-cli sadd myset 1
(integer) 1
$ redis-cli sadd myset 2
(integer) 1
$ redis-cli sadd myset 3
(integer) 1
$ redis-cli smembers myset
1.3
2.1
3.2
Detect presence:
$ redis-cli sismember myset 3 (integer) 1$ redis-cli sismember myset (integer) 0
Ordered collections:
Redis1.2 introduced ordered set, Zrange only belong to ordered set;
For elements to get multiple sorts, an alternative is to add each element to multiple ordered collections at the same time.
This article is from the "Technology Achievement Dream" blog, please be sure to keep this source http://weipengfei.blog.51cto.com/1511707/1213464