Redis common Commands (iv) database management, Key management, subscription publishing

Source: Internet
Author: User
Tags delete key

# # Database Management


Keys pattern # Lookup key, parameter wildcard lookup


Keys * # View all keys

Keys N # View all keys starting with n

Keys *e # View all keys ending with E

Keys H?llo

Keys H[ae]llo


exists name # View name This key exists, exists as 1, does not exist as 0


Type key # to view the types of value corresponding to the key

Type name


Del key1 key2 ... # Delete key and corresponding value

Del addr


Rename Key Newkey # Changes the name of the key from key to Newkey, and if Newkey already exists, overwrite

Rename Num1 num3


Renamenx Key Newkey # To change the name of the key from key to Newkey, if the newkey already exists, do not do the action

Renamenx num3 num2


# sort the list, collection, and ordered collection by calling the sort command

Sort key [by pattern] [limit offset count] [get pattern [get pattern]] [ASC|DESC] [alpha] [store destination]

Rpush Numbers 9 5 1 3 2

Sort numbers # By default the sort command interprets the value contained by the key as a floating-point number and then sorts the floating-point numbers

Sort numbers ASC

Sort Numbers desc


Sadd names Peter Jack Tom

Sort names Alpha # Use Alpha to let sort command sort text based on dictionary order


Sort numbers Limit 0 3 # does not skip any values and returns the first three values

Sort numbers Limit 3 3 # escapes the first three values and then returns the three values immediately following


Sort numbers Store Sorted-numbers # by specifying store Destkey, we store the sorting results in Destkey, and the sorted results are stored as a list


Randomkey # Randomly returns a key from the current database and the returned key is not deleted


# Scan command iterates through the entire database in a gradual manner and returns a key that matches a given pattern

# The cursor is the cursor used to traverse, the cursor must be set to 0 at the beginning of a new traverse, each time the scan is called, the command returns a new cursor value, and the scan needs to enter the entire cursor value

# match pattern is used to specify the pattern to match

# count number Specifies how many keys to return for this traversal

Scan cursor [match pattern] [count number]

Scan 0


Sscan key cursor [match pattern] [count number] # in place of the smembers command that might block the server, traversing the elements contained in the collection

Sscan names 0


Hscan key cursor [match pattern] [count number] # instead of the Hgetall command that might block the server, traverse the hash containing the individual key-value pairs

Hscan Daiby::info 0


Zscan key cursor [match pattern] [count number] # in place of the Zrange command that might block the server, traverse the individual elements contained in an ordered collection

Zscan "blog::p Aging" 0


Dbsize # Returns the number of key-value pairs currently contained in the database


FLUSHDB # Delete all key-value pairs contained in the current database


Select num # switch Database


Move Key Target-db # moves the key in the current database to the target database and does not act if the target database already has a key with the same name

Move numbers 1


Flushall # Remove Key-value pairs from all Redis databases


# Key Expiration feature

# The role of expire and pexpire is to let the key be deleted after n seconds or n milliseconds

# Expireat and Pexpireat's role is to have the key deleted after the specified Unix time arrives


Expire Key seconds # sets the lifetime of the key, in seconds, if no expiration is specified until it is removed using Del

Expire Name 5


Pexpire key milliseconds # Set key lifetime, in milliseconds, one second equals 1000 milliseconds, redis default 100 milliseconds check keys expire once

Pexpire msg 5500


Expireat key Timestamp # Set key expiration time, specify second-level UNIX timestamp

Expireat msg 100000005


Pexpireat Key Milliseconds-timestamp # Set key expiration time, specify millisecond UNIX timestamp

Pexpireat msg 100000000000005


Pttl Key # View remaining lifetime, in milliseconds


TTL Key # View remaining live time in seconds

TTL age


Persist # Delete Time to live or expire

Persist msg


Setex Key seconds Value # sets the key value and the expiration time, in seconds

Set age 5 18


Psetex key Millisecond Value # Sets the key value and expiration time, in milliseconds, equivalent to executing set and Pexpire two commands

Set Age 5000 18



# # # Publish and subscribe


Subscribe Channel [Channel ...] # Subscribe to one or more channels given

Subscribe News::it


Psubscribe pattern [pattern ...] # Subscribe to one or more patterns, the pattern parameter can contain glob style matches (*,[],?)

Psubscirbe news::[ie]t


# The behavior of the unsubscribe command is different for each client, REDIS-CLI directly out of the client to unsubscribe, Python and Ruby need to display the execution command

Unsubcribe [channel|[  Channel ...] # Unsubscribe from designated channels and unsubscribe from all subscribed channels if not specified


Punsubcribe [pattern|[  Pattern ...]] # unsubscribe from the specified mode and unsubscribe from all subscribed modes if not specified


Channels # Show subscribed channels


Publish channel message # sends a message to the specified channel, and the command returns the number of subscribers who received the information


PubSub channels [pattern] # lists channels with at least one subscriber


PubSub numsub [Channel ...] # returns the number of subscribers for a given channel


PubSub Numpat # Returns the number of modes subscribed to


This article is from the "Daibayang blog" blog, make sure to keep this source http://daibaiyang119.blog.51cto.com/3145591/1964015

Redis common Commands (iv) database management, Key management, subscription publishing

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.