Redis Operation command for key

Source: Internet
Author: User

Del key1 Key2 ... Keyn

Action: Delete 1 or more keys

Return value: The nonexistent key is ignored, returning the number of really deleted keys

Rename Key Newkey

Function: Assign a new key name to the key

Note: If Newkey already exists, the original value of Newkey is overwritten

Function: Rename key to Newkey

Return: The modification returned 1, no modification returned 0

Note: Nx--> not exists, that is, when Newkey does not exist, make a name change action

Move Key db

Redis 127.0.0.1:6379[1]> Select 2

Ok

Redis 127.0.0.1:6379[2]> Keys *

(empty list or set)

Redis 127.0.0.1:6379[2]> Select 0

Ok

Redis 127.0.0.1:6379> Keys *

1) "Name"

2) "CC"

3) "A"

4) "B"

Redis 127.0.0.1:6379> Move cc 2

(integer) 1

Redis 127.0.0.1:6379> Select 2

Ok

Redis 127.0.0.1:6379[2]> Keys *

1) "CC"

Redis 127.0.0.1:6379[2]> Get CC

"3"

(Note: A Redis process that opens more than one database, opens 16 databases by default, numbering from 0 to 15 , can be modified from a configuration file if you want to open more databases)

Keys pattern query the corresponding key

In Redis, allow fuzzy query key

There are 3 wildcard characters *,? ,[]

*: Wildcard with any number of characters

?: Pass a single character

[]: 1 characters in parentheses

Redis 127.0.0.1:6379> Flushdb

Ok

Redis 127.0.0.1:6379> Keys *

(empty list or set)

Redis 127.0.0.1:6379> Mset One 1 2 three 3 four 4

Ok

Redis 127.0.0.1:6379> Keys o*

1) "One"

Redis 127.0.0.1:6379> Key *o

(Error) ERR unknown command ' key '

Redis 127.0.0.1:6379> Keys *o

1) "Both"

Redis 127.0.0.1:6379> Keys???

1) "One"

2) "Both"

Redis 127.0.0.1:6379> keys on?

1) "One"

Redis 127.0.0.1:6379> Set ONS yes

Ok

Redis 127.0.0.1:6379> Keys ON[EAW]

1) "One"

Randomkey return random Key

Exists key

Determine if key exists, return 1/0

Type key

Returns the type of value stored by key

Have String,link,set,order set, hash

TTL key

Role: Querying the life cycle of a key

Return: Number of seconds

Note: For nonexistent key or expired key/key, all returns-1

Redis2.8, for a nonexistent key, return-2

Expire key Integral type value

Function: Sets the lifecycle of a key in seconds

Similarly:

Pexpire key milliseconds, setting life cycle

Pttl key, returns the life cycle in milliseconds

Persist key

Function: The specified key is permanently active

Redis action command for key

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.