I. operations related to the string type of redis.

Source: Internet
Author: User
Tags key string

I. operations related to the string type of redis.

* Use in redis client:


============== Method of the string type


Description: string is the simplest type of redis. A key corresponds to a value, and the string type is binary secure.
Redis string can contain any data, such as JPG images or serialized objects.


1: A key contains only one value. If the same value is set, = overwrites

Set name: leyangjun
Get value: get name

2: setnx: (determines whether the set value exists. If it does not exist, it is set)
Set the value corresponding to the key to a value of the string type. If the key already exists, 0 is returned. nx indicates not exist.

3: setex:
Set the value corresponding to the key to a value of the string type and specify the validity period of the key value.
Example: setex name 10 leyangjun --> set the name to leyangjun and save it for 10 seconds.
Get name --> 10 seconds or the like.
4: setrange: (replace the value. If there are two values, replace them with two. For example, the length and the previous digits will not be deleted)
String used to set the value of the specified KEY
Example: setrange name 6 gmail.com -->) replace the value of name with gmail.com

5: mset: Batch setting
Multiple KEY values are set at one time. If "OK" is returned successfully, all values are set. If "failure" is returned, 0 indicates no value is set.
Example: mset key1 leyangjun1 key2 leyangjun2
6: msetnx:
Set the values of multiple keys at a time. If "OK" is returned successfully, all values are set. If "0" is returned for failure, no values are set, but existing keys are not overwritten.
Example: msetnx key1 leyangjun3 key2 leyangjun2 --> if any of the keys exists, the setting will not succeed.
7: get:
Returns the string value corresponding to the key. If the key does not exist, nil is returned.

8: getset:
Sets the key value and returns the old value of the key.
Example: getset key6 30 --> get the old value and set it to a new value
9: getrange
Obtains the value of a key string.
Example: getrange email 0 4 --> get Email value from 0-4 (leyan) leyangjun@qq.com,
10: mget: Batch Retrieval
Obtain the values of multiple keys at a time. If the corresponding key does not exist, the corresponding nil is returned.
Example: mget key1 key2 key3...
11: incr auto-increment 1
Add the key value and return a new value --> If the key does not exist, the key is set and the original value is 0.
Example: incr key6 --> increment by 1
12: incrby
Similar to incr, if a specified value is added, the key is set when the key does not exist and the original value is regarded as 0.
Example: incrby key7 5 --> auto-increment 5 plus
Incrby key7-5 --> negative auto-increment minus
13: decr auto-Reduction
Subtraction of key values
Example: decr key6 --> key6-1 minus 1
14: decrby
Similar to decr, specify impairment
Example: decrby key6 3 --> key6-3
Decrby key6-3 --> adding 3 to the negative
15: append
Append value to the string of the specified key to return the length of the new string.
Example: append name. net --> name = leyangjun after append leyangjun.net
16: strlen
Set the value length of the key.
Example: strlen name

================================================================ END = ========================================================== ==================

What is redis rediskey-value storage system? similar to Memcached, redis supports storing more value types, including string, list, and set), zset (sorted set -- ordered set) and hash (hash type) some data types support push/pop, add/remove, Intersection Set, difference set, and richer operations, and some operations are atomic. On this basis, redis supports various same-way sorting and memcached samples. guaranteed efficiency data cache memory difference redis will periodically write the updated data to the disk or write the modification operation to the append record file. On this basis, the master-slave (master-slave) is implemented) synchronization
Redis's high-performance key-value database redis greatly compensates for memcached-type key/value storage. It plays a complementary role in relational databases in different scenarios and provides the PythonRubyErlangPHP client for ease of use.
Redis provides five data types: stringhashlistset and zset (sorted set)
Redis uses two file formats: full data and incremental requests.
Can cache objects in redis be strings only?
The basic types of complex structures such as hashmap and list are only string.

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.