Before I often contact database is a relational database, where contact with the majority of MySQL. NoSQL rise in recent years, a variety of new databases have been born, redis is in a popular NoSQL database.
Note: This article only as the author of the accumulation of learning and reading, if wrong place, please understand.
A, redis data type
For the introduction redis database, can not say here, we are free to Baidu, in short, it is to redis "key on the" database stored data. First, as a database, for storing data, which must exist corresponding data storage type definition, types of data stored redis I start talking about.
There are five types of data redis database, are: String (String), a list (List), set (SET), a hash (the hash), ordered set (zset).
(1) String
Even in the major string redis database, as are the basic data types, including the value of the stored string, integer or floating point.
redis operation command string data used:
command | Explanation | Basic usage |
set | Setting a given key value storage | set [key] [value] |
get | Gets the value of the given key | get [key] |
of the | Delete the value of a given bond | del [key] |
(2) List
redis list may be viewed as a "double-ended queue", the data structure allows the front and rear ends thereof in the Add / Remove elements.
redis operation data list common commands:
command | Explanation | Basic usage |
lpush | Listing the given value insertion front end | lpush [key] [value] |
lpop | Is ejected from the front end of the list and returns a value | lpop [key] |
Rpus | The given value into the rear end of the list | rpush [key] [value] |
rpop | From the pop-up list of backend and returns a value | rpop [key] |
lindex | Get a list of individual elements of a given value of the index | lindex [key] [index] |
lrange | Get a list of all the elements in a given range of values | lrange [key] [startIndex] [endIndex] |
(3) collection
redis and can be stored a plurality of sets or lists strings, except that the list may store a plurality of the same string, the unique set of storage elements is guaranteed. A set of storage elements is way out of order.
redis operation data set of commands:
command | Explanation | Basic usage |
sadd | Element added to the given set | sadd [key] [value] |
srem | Delete the collection of a given element | srem [key] [value] |
sismember | Check whether a given element is present in the collection | sismember [key] [value] |
smembers | Returns all elements in the collection | smembers [key] |
(4) Hash
Redis hash value may be stored to a plurality of key-value mappings, and not repeatable random key.
redis hash operation command data commonly used:
command | Explanation | Basic usage |
hset | Given key value pair to the hash | hset [key] [field] [value] |
hget | Gets the value of the specified hash key | hget [key] [field] |
hdel | Delete the specified hash key (associated value) | hdel [key] [field] |
hgetall | Get all key-value pairs in the hash | hgetall [key] |
(5) an ordered collection
Ordered set and the same hash as the key requirements for storing information, and hash keys, except that the value of the ordered set is referred to as "score (Score)", value must be a floating point number . According to an ordered set of keys to access both members can also access the members according to the score. Ordered set of keys to be sorted by size score .
redis operation data ordered set of commands:
command | Explanation | Basic usage |
zadd | Given key-value pair to add to the collection | zadd [key] [score] [field] |
Zrem | Delete collection at the specified key (associated value) | zrem [key] [field] |
zrange | Gets a collection of key-value pairs specified index range | zrange [key] [startIndex] [endIndex] (optionally "withscores" parameter value outputs) |
zrangebyscore | Gets the collection of key-value range specified value | zrangebyscore [key] [minScore] [maxScore] |