Redis Data type operations

Source: Internet
Author: User

7. Data type

Set name ZSJ

Get Name

Setnx name: Does not overwrite the original value if there is no update if there is no option set

Setex: Set and specify the validity period

Setex Haircolor Red: 10 seconds to set the haircolor time

No set validity period is permanently valid

SetRange name 6 gmail.com: Replace with gmail.com "replace equivalent length" starting with sixth character

Mset key1 valus1 key2 value2: Set two values at a time

Msetnx

Getset: Get old value and set new value

Getset Key6 30

GetRange: Get substring

GetRange name 0 5: Returns the No. 0 to 5th string of name

Mget: Bulk Acquisition

INCR key: Self-increment

Incrby Key 6:6 per increment, no key is set to 0 by default

DECR: Self-reduction

Decrby

Append key value: Append value to key to return the final string length

Strlen: Gets the string length of the key "Strlen key"

Hset Key Property value

Hset user:001 name ZSJ

Hget user:001 Name

Hsetnx

Hmset user:001 name Hello age 10

Hmget user:001 name Age

Hincrby user:001 age 5

Hexist user:001 Age: Determine if the age field exists

Hlen user:001: Returns the number of keys in a hash

Hdel user:001 Age: Delete Age in a hash object

Hkeys user:001: Returns all fields in the hash object

Hvals user:001: Returns the value of all fields in the hash object

Hgetall user:001: Gets all the fields and their corresponding values in a hash object


The 8.lists type and operation [Push/pop] "itself is the way to put data in the stack"

Lists in Redis is a doubly linked list and can be used as a stack or as a queue, both from the beginning and the end of the data.

Lpush mylist "Hello" #从头部压入一个元素, returns the number of elements

Lrange mylist 0-1 #从第一个元素一直到尾的第一个元素

Rpush list2 "ZSJ" #从尾部压入元素

Linsert mylist before "Hello" "World": pressing a world element in front of hello "note: direction from tail to head"

LSet mylist 0 "Hello": re-assigning elements to the No. 0 position

Lrem list 1 "Hello": Remove 1 elements of Hello from list, return the number of successful deletions "delete N and value elements from List of key"

LTrim data within the range of the value of the key reserved

LTrim list 1-1: Keep starting from 1 to the last element

Lpop: remove element from head and return delete element

Rpoplpush: Removes the element from the tail of the first list and adds it to the head of the second list

Rpoplpush List1 List2

Lindex: Returns the element of the index position in the list named key

Lindex List 1

Llen returns the size of the list


9.set type

Sadd mysset "Hello"

Smembers MySet #查看元素

Srem myset "Hello" #删除元素

Spop randomly returns and deletes one of the elements in a set named key

Spop MySet

Sdiff Set1 Set2: [Returns the difference between all given key and the first key] returns the Set1 in Set2

Sdiffstore set3 Set1 Set2: Store the difference between Set1 and Set2 in Set3

Sinter Set1 Set2: Takes the intersection of two sets

Sinterstore set3 Set1 Set2: Storing intersections in Set1,set2 in Set3

Sunion Set1 Set2: Collection of Set1,set2

Sunionstore Set3 Set1 Set2

Smove [Remove member from the set corresponding to the first key and add to the second corresponding set]

Smove Set1 Set2 Value

SCard set: Returns the number of elements in the collection

Sismember: Tests whether an element is an element in a set

Sismember Set Value: Tests if value is an element in set

Srandmember: Randomly returns one of the elements in a set, but does not delete

Srandmember Set


Ten sorted sets ordered collection

Zadd adds an element member,score for sorting to a zset named key. If the element exists, its order is updated

Zadd Myzset 1 "one"

Zadd Myzset 2 "

Zadd myzset 3 ": Element" is not updated in this case, but the sort is updated to 3

Zrange myzset 0-1 withscores # #withscores的目的是输出顺序号

Zrem Delete the element in Zset with the name Key member

Zrem Set Value

Zincrby specifies an increase or decrease in the order of the set

Zincrby MySet 2 "one": increase the order value of one by 2 and add this element if one does not exist

Zrank returns the index of the elements in the Zset, sorted from small to large

Zrank MySet "A": Returns the index value of the binary element

Zrevrank sort from big to small

Zrevrange reverse view member and sorting in Zset

Zrevrange Myzset 0-1 Withscores

Zrangebyscore Myzset 2 3 withscores get all elements from 2 to 3

Zcount Myzset 2 4: Counts the number of elements between 2 and 4

Zcard Myzset: Returns the number of all elements in the collection

Zremrangebyrank: Deletes an element of an interval and returns the remaining element "delete based on index"

Zremrangebyrank myzset 1 1 [Remove elements from 1 to 1 starting from the first position]

Zremrangebyscore myzset 1 2 [delete elements of a given interval]


This article is from the "Inverse Day" blog, please be sure to keep this source http://xxzjzsj.blog.51cto.com/3052058/1629163

Redis Data type operations

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.