Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the use of keys in Redis

2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

This article is to share with you about the use of keys in Redis. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Enter the directory: cd / usr/local/redis/

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

Enter:. / bin/redis-cli

(1) check key: keys *

View all keys:127.0.0.1:6379 > keys *

127.0.1 mya1 6379 > keys * 1) "myb1" 2) "mya1" 3) "mya2" 4) "my3" 5) "myhash" 6) "mylist2" 7) "num2" 8) "my1" 9) "num" 10) "mylist3" 11) "mya3" 12) "name" 13) "myb3" 14) "mylist" 15) "my2" 16) "num3" 17) "imooc" 18) "num5" 19) ) "mylist4" 20) "myb2" 21) "myset" 22) "mysort"

(2) View key:keys strings that start with any character?

Query the key at the beginning of my: keys my?

127.0.1 my1 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 whether exists exists in key

Check to see if it exists. 1 means it exists, 0 means it does not exist: exists my1

127.0.0.1 exists my1 6379 > exists num3 (integer) 1

(5) rename key: rename

Rename key operation: rename original key name new key name

127.0.0.1 get num 6379 > rename num newnumOK127.0.0.1:6379 > get newnum "36" 127.0.0.1

(6) set expiration time: expire

Set expiration time: number of seconds of expire key name

127.0.0.1 6379 > expire newnum 1000 (integer) 1

(7) check the remaining time of key: ttl

Check the remaining time of key: ttl key name, or return a negative value if it is not set.

127.0.0.1 expire newnum 6379 > ttl newnum (integer) 1000 (integer) 1127.0.0.1

(8) judge the type of key: type

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

127.0.0.1 type myhashhash127.0.0.1:6379 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 Thank you for reading! This is the end of this article on "what is the use of keys in Redis?". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report