HTML tutorial
CSS3 tutorial
Bootstrap tutorial
JavaScript tutorial
JQuery tutorial
AngularJS tutorial
React tutorial
NodeJS tutorial
PHP tutorial
Python tutorial
Python3 tutorial
Django tutorial
Linux tutorial
Docker tutorial
Ruby tutorial
Java tutorial
C tutorial
C ++ tutorial
Perl tutorial
JSP tutorial
Lua tutorial
Scala tutorial
Go tutorial
ASP.NET tutorial
C # tutorial
Redis supports five data types: string (string), hash (hash), list (list), set (set) and zset (sorted set: ordered set).
redis string is the most basic type, you can understand exactly the same type as with Memcached, a key corresponding to a value.
string type is binary safe. Meaning redis the string can contain any data. Such as jpg image or a sequence of objects.
Redis string type is the basic data types, a key can be stored maximum 512MB.
redis 127.0.0.1:6379> SET name "w3resource" OK redis 127.0.0.1:6379> GET name "w3resource"
In the example above we use Redis ofSET and GETcommands. Key is name, the corresponding value w3resource.
Note: A key can store maximum 512MB.
Redis hash is a collection of key-value pairs.
Redis hash is a string type of field and value mapping table, hash is particularly suitable for storing objects.
127.0.0.1:6379> HMSET user:1 username w3resource password w3resource points 200 OK 127.0.0.1:6379> HGETALL user:1 1) "username" 2) "w3resource" 3) "password" 4) "w3resource" 5) "points" 6) "200"
Examples of the above data types stored in the hash of the user object that contains user scripts. Examples we use Redis HMSET, HGETALLcommand, user: 1 as key.
Each hash can store key-value pairs 232-1 (4000000000).Redis list is a simple list of strings sorted insertion order. You can add an element to the head of the list (left) or rear (on the right).
redis 127.0.0.1:6379> lpush w3resource redis (integer) 1 redis 127.0.0.1:6379> lpush w3resource mongodb (integer) 2 redis 127.0.0.1:6379> lpush w3resource rabitmq (integer) 3 redis 127.0.0.1:6379> lrange w3resource 0 10 1) "rabitmq" 2) "mongodb" 3) "redis" redis 127.0.0.1:6379>
List can store up 232--1 element (4,294,967,295 each list can store more than 4 billion).
Redis is an unordered collection of Set string type.
Set by the hash table to achieve, so add, delete, find the complexity is O (1).
Adding to a string element, key corresponding set collection, successful return 1 return 0 if the element already in the collection, key corresponding to the set does not exist an error is returned.
sadd key member
redis 127.0.0.1:6379> sadd w3resource redis (integer) 1 redis 127.0.0.1:6379> sadd w3resource mongodb (integer) 1 redis 127.0.0.1:6379> sadd w3resource rabitmq (integer) 1 redis 127.0.0.1:6379> sadd w3resource rabitmq (integer) 0 redis 127.0.0.1:6379> smembers w3resource 1) "rabitmq" 2) "mongodb" 3) "redis"
Note: The above example rabitmq added twice, but based on a unique set of elements within the second insertion element is ignored.
Set the maximum number of members 232--1 (4294967295 Each set can store more than 40 million members).
The difference is that are associated with each type of element of a double score. It is through redis scores for small to large order of collection members.
Zset member is unique, but the score (score) it can be repeated.
Add an element to the collection, the element is present in the collection updates the corresponding score
zadd key score member
redis 127.0.0.1:6379> zadd w3resource 0 redis (integer) 1 redis 127.0.0.1:6379> zadd w3resource 0 mongodb (integer) 1 redis 127.0.0.1:6379> zadd w3resource 0 rabitmq (integer) 1 redis 127.0.0.1:6379> zadd w3resource 0 rabitmq (integer) 0 redis 127.0.0.1:6379> ZRANGEBYSCORE w3resource 0 1000 1) "redis" 2) "mongodb" 3) "rabitmq"