Redis Operations Use

Source: Internet
Author: User

today overtime, I did not know what to learn, is considering reading, colleagues raised questions about Redis, because they have not been used before, slightly embarrassed, fortunately, more information.


Write an article that basically follows a colleague's question:

One, the problem check a key

Redis-cli Key ' * ' |grep key-name #查看redis中是否有这个key # When you have this key see the value of this key redis-cli127.0.0.1:6379> GET key-name


Second, set the value of a key

127.0.0.1>set Key-name Value


The problem is almost like this, solve the problem, by the Redis related commands to tidy up, in case of their future work in use:

Redis command:

The following commands are all: redis-cli after execution

Set key value: Sets the values of the specified key, and if key already stores other values, the set will overwrite the old value and ignore the type.

Get key: Used to get the value of the specified key. If key does not exist, nil is returned. If the value stored by key is not a string type, an error is returned.

Getrange: Used to get a substring of a string stored in the specified key. The Intercept range of a string is determined by the start and end two offsets (including start and end). Similar to arrays: starting from 0, the last one is-1. Getrange Key 0 10, take 1-11 of the key.

Getset: Sets the value of the given key to value and returns the old value of the key.

Setbit: Sets or clears a bit (bit) on the specified offset for the string value stored by key.

Mget: Returns the value of all (one or more) given key. If a key does not exist in the given key, the key returns a special value of nil.

Mset: Used to set one or more key-value pairs at the same time.

Setex: The command sets the value and its expiration time for the specified key. If the key already exists, the Setex command will replace the old value. Setex Key Nihao

Setrange: Use the value parameter to write to the string value stored by the key, starting at offset offsets. SETRANGE MyKey 8 Hello, replaces the original eighth digit character with Hello.

Strlen: Used to get the length of the string value stored by the specified key. An error is returned when key is not stored as a string value

SETNX: The command sets the specified value for key when the specified key does not exist.

MSETNX: command-sets one or more key-value pairs at the same time, when and only if all given key does not exist.

Msetnx key1 Valus1 Key2 value2

Psetex: This command is similar to the Setex command, but it sets the lifetime of the key in milliseconds instead of in seconds, as in the case of the Setex command.

INCR : Increase the number of values stored in key by one

DECR : Subtract one of the numeric values stored in key.

Incrby : Adds the value stored by key to the given increment value (increment). Incrby key 5 given key plus 5

Decrby : Subtracts the value stored by the key from the given decrement value

incrbyfloat: Adds the value stored by key to the given floating-point increment value (increment).

Append : If key already exists and is a string, the APPEND command appends value to the end of the original value of the key. There is an append, and no assignment exists.


This article is from the "Share,open source" blog, so be sure to keep this source http://liqilong2010.blog.51cto.com/3029053/1888200

Redis Operations Use

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.