Redis data Type (string)

Source: Internet
Author: User

String

This is the simplest type of redis. If you only use this type, Redis is like a memcached server that can be persisted

127.0.0.1:6379> Set MyKey Somevalueok

127.0.0.1:6379> get MyKey "somevalue"

SET Command

Set key value [ex seconds] [px milliseconds] [nx|xx]

Ex: set key expiration time, unit seconds

PX: Set the expiration time of the key, in milliseconds

NX: The key cannot be set until it exists

XX: The value of key is set only when keys exist

127.0.0.1:6379> set MyKey newval NX (nil)

127.0.0.1:6379> Set MyKey newval Xxok

127.0.0.1:6379> set MyKey 30seconds ex 30ok127.0.0.1:6379> ttl MyKey (integer) 27

The TTL command is used to view the expiry time of key keys

Using set to implement lock mechanism

Set Resource-name anystring NX ex Max-lock-time

127.0.0.1:6379> set Stock-NX ex 3000OK

Atomic Increment

127.0.0.1:6379> Set Counter 100
Ok

(integer) 101
127.0.0.1:6379> Incrby Counter 50
(integer) 151
127.0.0.1:6379> DECR counter
(integer) 150

Set or store multiple values at once

127.0.0.1:6379> Mset a ten b c 30ok127.0.0.1:6379> mget a B C1) "10" 2) "20" 3 "30"

Mget returns an array of strings

Redis data Type (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.