Linux-nosql's Redis (iii)

Source: Internet
Author: User

One, Redis data common operation 1, string common operation

Set Key1 Aminglinux

Get Key1

Set Key1 aming//A key corresponds to a value, multiple assignments, overwriting the previous value

SETNX Key2 AAA//return 1

Get Key2 setnx key2 BBB//Return 0 Description: Setnx If key exists, returns 0, does not exist will create this key directly

Setex Key3 10 1//This is used to set the expiration time for key

Mset Key1 1 Key2 2 Key3 3//Set multiple keys simultaneously

Mget Key1 Key2 Key3

2, hash data common operation

Hset user1 name aming//Build Hash

Hset User1 age 30

Hset User1 Job It

Hgetall user1

Hmset user2 name aming Age job IT//bulk build key value pair

Hmget user2 hmget user2 name Age job Hdel user2 job//delete specified filed

Hkeys User2//Print all keys

Hvals User2//Print all values

Hlen user2//view hash There are several filed

3, list Data common operation

Lpush lista A//pressing an element from the left

Lpush lista b lrange lista 0-1//0 for head,-1 for tail

Lpop lista//Remove from left

Rpush lista 1//Pressing an element from the right

Rpush lista 2 lrange lista 0-1

Rpop lista//Take the first element from the right

Linsert lista before 2 3//in front of 2 insert an element of 3

LSet lista 4 bbb//change 5th element to BBB

Lindex lista 0//view 1th element

Lindex lista 3//view 4th element

Llen lista//View a list of several elements

4. Common operation of SET data

Sadd Seta AAA//Put elements into the collection Seta

Smembers Seta//View all elements in a collection

Srem Seta AAA//delete element

Spop Seta//randomly take out an element, delete

Sdiff Seta SETB//differential set, Seta as standard

Sdiffstore setc Seta SETB//differential set and stored in SETC

Sinter Seta SETB//Seek intersection

Sinterstore setd Seta SETB//The intersection is stored setd

Sunion Seta SETB//Request and set

Sunionstore Sete Seta SETB//Request and save to Sete

Sismember Seta AAA//Determine if an element belongs to a collection

Srandmember Seta//random extraction of an element without deleting

5, Zset Data common operation

Zadd Zseta 11 123//Create an ordered collection

Zrange Zseta 0-1//Show all elements in order

Zrange Zseta 0-1 withscores//can bring the score

Zrem Zseta 222//delete specified element

Zrank Zseta 222//Returns the index value of the element, starting from 0, sorted by score

Zrevrank Zseta 222//Ibid, different, sorted by score reverse order

Zrevrange Zseta 0-1 Reverse order displays all elements with a score

Zcard Zseta//Returns the number of all elements in the collection

Zcount Zseta 1 10//Returns the number of elements in the score range 1-10

Zrangebyscore Zseta 1 10//Return the element of the score range 1-10

Zremrangebyrank Zseta 0 2//delete element of index range 0-2, sort by score

Zremrangebyscore Zseta 1 10//Delete the element of the score range 1-10

Second, Redis key value related operations

Keys *//Remove all keys

Keys my*//fuzzy matching

exists name//has the name key to return 1, otherwise returns 0;

Del key1//delete a key//successfully return 1, otherwise return 0;

EXPIRE Key1 100//Set Key1 expires after 100s

The TTL key//View key still has how long to expire, unit is s, when key does not exist, return-2. Returns 1 when key exists but no remaining lifetime is set. Otherwise, the remaining lifetime of the key is returned. Select 0//represents selecting the current database and entering the 0 database by default

Move age 1//moves age to 1 database

Persist Key1//Cancel the expiration time of the Key1

Randomkey//Randomly returns a key

Rename oldname newname//rename key

Type key1//types of return keys

Iii. operations related to Redis services

Dbsize//Returns the number of keys in the current database

Info//Return Redis database status information

FLUSHDB//empties all keys in the current database

Flushall//Clears all keys from all databases

Linux-nosql's Redis (iii)

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.