Redis database series (II)

Source: Internet
Author: User
Delkey1key2... keyn function: delete one or more keys. Return: Ignore nonexistent keys. Return the number of actually deleted keys. renamekeynewkey function: assign a new key name to the key. Note: if newkey already exists, the original newkey will be overwritten by renamenxkeynewkey. function: Rename the key

Del key1 key2... keyn function: delete one or more keys. Return: Ignore nonexistent keys. Return the number of actually deleted keys. rename key newkey function: assign a new key name to the key. Note: if newkey already exists, newkey will be overwritten by renamenx key newkey. function: Rename the key

del key1 key2 ... Keyn

Purpose: delete one or more keys.

Return Value: ignore a nonexistent key and return the number of actually deleted keys.

rename key newkey

Purpose: assign a new key name to the key.

NOTE: If newkey already exists, the original value of newkey is overwritten.

renamenx key newkey  

Purpose: Rename the key as newkey.

Return: 1 is returned for modification. If no modification is made, 0 is returned.

Note: nx --> not exists, that is, when newkey does not exist, change the name.

move key db

redis 127.0.0.1:6379[1]> select 2OKredis 127.0.0.1:6379[2]> keys *(empty list or set)redis 127.0.0.1:6379[2]> select 0OKredis 127.0.0.1:6379> keys *1) "name"2) "cc"3) "a"4) "b"redis 127.0.0.1:6379> move cc 2(integer) 1redis 127.0.0.1:6379> select 2OKredis 127.0.0.1:6379[2]> keys *1) "cc"redis 127.0.0.1:6379[2]> get cc"3"

(Note: A redis process opens more than one database. By default, 16 databases are opened, ranging from 0 to 15,

If you want to open more databases, you can modify them from the configuration file)

Keys pattern query the corresponding key

Fuzzy key query is allowed in redis.

There are 3 wildcards *,? , []

*: Wildcard can contain any number of characters.

? : Wildcard Single Character

[]: A certain character in parentheses

redis 127.0.0.1:6379> flushdbOKredis 127.0.0.1:6379> keys *(empty list or set)redis 127.0.0.1:6379> mset one 1 two 2 three 3 four 4OKredis 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 *o1) "two"redis 127.0.0.1:6379> keys ???1) "one"2) "two"redis 127.0.0.1:6379> keys on?1) "one"redis 127.0.0.1:6379> set ons yesOKredis 127.0.0.1:6379> keys on[eaw]1)"one"
Random keyexists key returned by randomkey

Checks whether the key exists and returns 1/0


type key

Type of the value stored in the key

String, link, set, order set, and hash


ttl key 

Purpose: query the key lifecycle.

Return: seconds

Note:-1 is returned for non-existing or expired keys/non-expired keys.

In Redis2.8,-2 is returned for keys that do not exist.


Expire key integer value

Purpose: set the key lifecycle in seconds.

Likewise:

Pexpire key in milliseconds, set the lifecycle

Pttl key, returned in milliseconds


persist key

Purpose: set the specified key to permanently valid.

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.