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

Common commands of redis

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

Keys: returns all key that satisfy a given pattern.

127.0.0.1 6379 > keys *

1) "num1"

2) "mylist3"

3) "key3"

4) "myzset2"

5) "name"

6) "mylist6"

7) "myset7"

8) "myzset3"

9) "myset3"

10) "num2"

11) "myhash"

12) "myset6"

13) "myset4"

14) "mylist2"

15) "key1"

16) "myzset"

17) "nane"

18) "email"

19) "key4"

20) "key2"

21) "mylist4"

22) "myset2"

23) "foo"

24) "myset"

127.0.0.1 purl 6379 > keys myzset*

1) "myzset2"

2) "myzset3"

3) "myzset"

Exists: confirm whether a key exists.

127.0.0.1 purl 6379 > exists name

(integer) 1

127.0.0.1 purl 6379 > exists age

(integer) 0

Del: delete a key

127.0.0.1 purl 6379 > del name

(integer) 1

127.0.0.1 purl 6379 > exists name

(integer) 0

Expire: sets the expiration time of a key.

127.0.0.1 purl 6379 > set addr cq

OK

127.0.0.1 6379 > expire addr 10

(integer) 1

127.0.0.1 purl 6379 > ttl addr

(integer) 8

127.0.0.1 purl 6379 > ttl addr

(integer) 6

127.0.0.1 purl 6379 > ttl addr

(integer) 4

127.0.0.1 purl 6379 > ttl addr

(integer) 2

127.0.0.1 purl 6379 > ttl addr

(integer)-2

Move: transfer the key from the current database to another database.

127.0.0.1 select 6379 > 0

OK

127.0.0.1 6379 > set age 30

OK

127.0.0.1 purl 6379 > get age

"30"

127.0.0.1 move age 6379 > 1

(integer) 1

127.0.0.1 purl 6379 > get age

(nil)

127.0.0.1 select 6379 > 1

OK

127.0.0.1 get age [1] >

"30"

Persist: removes the expiration time of a given key.

127.0.0.1 6379 > set age 30

OK

127.0.0.1 expire age 6379 >

(integer) 1

127.0.0.1 purl 6379 > ttl age

(integer) 298

127.0.0.1 purl 6379 > persist age

(integer) 1

127.0.0.1 purl 6379 > ttl age

(integer)-1

Randomkey: a key that randomly returns the key space.

127.0.0.1 purl 6379 > randomkey

"myzset3"

127.0.0.1 purl 6379 > randomkey

"key4"

Rename: rename key.

127.0.0.1 purl 6379 > keys age*

1) "age"

127.0.0.1 purl 6379 > rename age age_new

OK

127.0.0.1 purl 6379 > keys age*

1) "age_new"

Type: the type of return value.

127.0.0.1 purl 6379 > type age_new

String

127.0.0.1 purl 6379 > type myzset2

Zset

127.0.0.1 purl 6379 > type mylist2

List

Ping: test whether the connection is alive.

127.0.0.1 purl 6379 > ping

PONG

Echo: print something on the command line.

127.0.0.1 purl 6379 > echo stone

"stone"

Select: options database. Redis database number from 0 to 15, you can choose any database to access the data.

127.0.0.1 select 6379 > 1

OK

127.0.0.1 get age [1] >

"30"

127.0.0.1 select 6379 [1] >

(error) ERR DB index is out of range

127.0.1 select 6379 [1] >

OK

Dbsize: returns the number of key in the current database.

127.0.0.1 purl 6379 > dbsize

(integer) 24

127.0.0.1 select 6379 > 1

OK

127.0.0.1 dbsize [1] >

(integer) 1

Info: get server information and statistics.

127.0.0.1 purl 6379 > info

# Server

Redis_version:4.0.1

Config get: gets the parameter settings.

127.0.0.1 purl 6379 > config get dir

1) "dir"

2) "/ root/redis-4.0.1"

127.0.0.1 purl 6379 > config get max*

1) "maxmemory"

2) "0"

3) "maxmemory-samples"

4) "5"

5) "maxclients"

6) "10000"

7) "maxmemory-policy"

8) "noeviction"

Flushdb: deletes all key in the currently selected database.

127.0.0.1 select 6379 > 1

OK

127.0.0.1 dbsize [1] >

(integer) 1

127.0.0.1 flushdb [1] >

OK

127.0.0.1:6

Flushall: delete all key from all databases.

127.0.1 set age 6379 [1] >

OK

127.0.0.1 dbsize [1] >

(integer) 1

127.0.1 select 6379 [1] >

OK

127.0.0.1 purl 6379 > dbsize

(integer) 24

127.0.0.1 purl 6379 > flushall

OK

127.0.0.1 purl 6379 > dbsize

(integer) 0

127.0.0.1 select 6379 > 1

OK

127.0.0.1 dbsize [1] >

(integer) 0

Security: sets the password that the client needs to use for any operation after connecting.

127.0.0.1 config get requirepass [1] >

1) "requirepass"

2) "

127.0.0.1 config set requirepass 6379 [1] >

OK

127.0.0.1 exit [1] >

[root@D2-LZY245 redis-4.0.1] # src/redis-cli

127.0.0.1 6379 > set age 30

(error) NOAUTH Authentication required.

127.0.0.1 6379 > auth 123456

OK

127.0.0.1 6379 > set age 30

OK

[root@D2-LZY245 redis-4.0.1] # src/redis-cli-a 123456

127.0.0.1 purl 6379 > set name stone

OK

127.0.0.1 purl 6379 > get name

"stone"

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

Database

Wechat

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

12
Report