Common operations (code) for keys in Redis

Source: Internet
Author: User
Tags delete key
This article brings you the content is about the keys in Redis general operation (code), there is a certain reference value, the need for friends can refer to, I hope to help you.

Entry directory: cd/usr/local/redis/

Start service:./bin/redis-server./redis.conf

Enter:./bin/redis-cli

(1) View Key:keys *

View all keys:127.0.0.1:6379> keys *

127.0.0.1:6379> keys * 1) "MYB1" 2) "MYA1" 3) "MYA2" 4) "My3" 5) "Myhash" 6) "Mylist2" 7) "num2" 8) "my1" 9) "num" 10) " Mylist3 "one)" Mya3 "()" name ")" Myb3 "(" MyList ")" My2 ")" num3 ")" Imooc ")" NUM5 "Mylist4)" Myb2 "Mys ET "Mysort"

(2) See the Key:keys string that starts with any character?

Query my at the beginning of my Key:keys?

127.0.0.1:6379> keys my?1) "My3" 2) "my1" 3) "My2"

(3) Delete Key:del

Delete Key:del my1 my2 my3

127.0.0.1:6379> del my1 my2 my3 (integer) 3

(4) Check if key exists exists

See if there is, 1 represents present, 0 means not present: exists MY1

127.0.0.1:6379> exists my1 (integer) 0127.0.0.1:6379> exists num3 (integer) 1

(5) Rename key: Rename

Rename operation to key: Rename original key name new key name

127.0.0.1:6379> get num "127.0.0.1:6379>" rename num newnumok127.0.0.1:6379> get Newnum "36"

(6) Set Expiration Time: Expire

Set expiration Time: Expire key name number of seconds

127.0.0.1:6379> expire Newnum (integer) 1

(7) To view the remaining time of key: TTL

Check the time remaining on key: The TTL key name, or a negative value if not set.

127.0.0.1:6379> expire Newnum (integer) 1127.0.0.1:6379> ttl newnum (integer) 885

(8) Determine the type of key: type

Determine the type of key: The name of type key.

127.0.0.1:6379> type newnumstring127.0.0.1:6379> type my1none127.0.0.1:6379> type myhashhash127.0.0.1:6379 > Type mylist4list127.0.0.1:6379> type Mysortzset
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.