redis study notes -04: redis five data structure types

redis command Daquan Web site: http://redisdoc.com/

A, redis five data types

1, String (String), Hash (hash, similar to Java in the Map), List (list), Set (collection) and Zset (sorted set, ordered set)

2, the command (command case insensitive):

(1) set / get / del Standing Orders

(2) append k1 12345 and 12345 vv1 put together into the original value of a string: vv112345

(3) strlen k1 k1 values ​​obtained length

(4) INCR / DECR k2 k2 if the value is a number, then execute a command plus 1 INCR, DECR execute a command minus 1.

(. 5) INCRBY / DECRBY k2 k2 3 if the value is a number, then execute a command INCRBY plus 3, Save command is performed once DECRBY 3.

(6) getrange k1 0 3 take the first four characters of the string value of k1, k1 corresponds GET so getrange k1 0 -1.

(7) setrange k1 0 xxx to (xxx length and the same) of the first three values ​​of k1 replaced xxx.

(8) setex k2 5 vv2 k2 of the survival time is 5 seconds.

(9) setnx k4 xxx k4 If this key already exists, it does not work, and if not, it is created, the value xxx.

(10) mset / mget k1 v1 k2 v2 k3 v3 mset while creating three key-value pair; mget obtained while k1, the value of k2, k3 of the.

(11) msetnx k4 v4 k5 v5 If both keys do not exist, we can create a successful, otherwise as long as one exists, can not create success.

 

Two, List (list)

1, lpush / rpush list01 1 2 3 4 5 creates a list, lpush sequence is created with the opposite value, rpush order value is for creating and displaying the same.

2, list01 first four values ​​taken 3 list lrange 0, lrange list01 0 -1 indicates all removed.

3, lpop rpop lpop and returns the number of the element 1, the maximum number of elements RPOP return and remove the element.

4, the value returned lindex list01 3 serial number (counting from 0) of the element 3.

5, llen list01 returns the number of elements in the list list01

6, lrem list03 2 3 2 is deleted from the element 3 in list03.

7, ltrim list01 0 3 4 elements list01 before replication in, and assigned to list01

8, lset list01 1 3 3 inserted in place of the digital second element of list01

9、linsert list01 before/after 6 10  在

 

Three, String (String)

String is redis basic types, as will be appreciated Memcahed exactly the same type, a key corresponding to a value.

String type is binary-safe, meaning that the redis string can contain any data, such as jpg image or serialized object.

String type is redis basic data types in a string redis value can be up to 512M.

 

Four, Hash (hash)

redis hash is a key pair set, redis hash field is a string type and the value of the mapping table, hash is particularly suited for storing objects. Similar to the java inside the Map <String, Object>.

 

Five, Set (collection) and Zset (ordered set)

redis Set of unordered collection of type String, is achieved through the HashTable.

Zset is an ordered set, and the difference is that a double set points are associated with each type of element, from small to large sort of set members through fraction. Members Zset is unique, but the scores can be repeated.

 

Six, redis key (key) command

1, keys * All key exists in the database

2、exists k1  判断某个key(比如k1)是否存在

3、move k3 2  把k3的键值对移动到3号数据库中

4、expire k1 5   为给定的key设置过期时间,比如k1只存活5秒

5、ttl k2  查看该key还有多少秒过期,返回-1表示永不过期,返回-2表示已过期

6、type key  查看key是什么类型的

7、key已经存在value的情况下,set key 新value:set k1 vv1  新的value会覆盖旧的value

 

 

 

 

Guess you like

Origin www.cnblogs.com/Luv-GEM/p/11506757.html