In the previous article, we tested and tested the existing redis data structure (see ). We will test some common redis commands today:
You need to check the data volume of the current database. There are three methods: keys *, dbsize, and info (there are many data parameters, which are also frequently used recently)
- [Root @ fsailing1 bin] #./redis-cli
- Redis 127.0.0.1: 6379>Keys *
- 1) "key2"
- 2) "age"
- 3) "ss"
- 4) "test"
- 5) "name"
- 6) "key1"
- Redis 127.0.0.1: 6379>Dbsize
- (Integer) 6
- Redis 127.0.0.1: 6379>Info
- Redis_version: 2.4.15
- Redis_git_sha1: 00000000
- Vm_enabled: 0
- Role: master
- Db0: keys=6,Expires=0
- Db1: keys=5,Expires=0
When you view a key value, exists deletes a key value and del
- Redis 127.0.0.1: 6379>Exists age
- (Integer) 1
- Redis 127.0.0.1: 6379>Exists chen
- (Integer) 0
- Redis 127.0.0.1: 6379>Del age
- (Integer) 1
- Redis 127.0.0.1: 6379>Exists age
- (Integer) 0
Rename/renamenx
- Redis 127.0.0.1: 6379>Keys *
- 1) "key2"
- 2) "ss"
- 3) "test"
- 4) "name"
- 5) "key1"
- Redis 127.0.0.1: 6379>Rename ss chen
- OK
- Redis 127.0.0.1: 6379>Renamenx key1 chen
- (Integer) 0
- Redis 127.0.0.1: 6379>Keys *
- 1) "key2"
- 2) "chen"
- 3) "test"
- 4) "name"
- 5) "key1"
Another command to set the expiration time and persistent expire/persist is to view the current situation. ttl means time to live.
- Redis 127.0.0.1: 6379>Keys *
- 1) "key2"
- 2) "ss"
- 3) "test"
- 4) "name"
- 5) "key1"
- Redis 127.0.0.1: 6379>Rename ss chen
- OK
- Redis 127.0.0.1: 6379>Renamenx key1 chen
- (Integer) 0
- Redis 127.0.0.1: 6379>Keys *
- 1) "key2"
- 2) "chen"
- 3) "test"
- 4) "name"
- 5) "key1"
- Redis 127.0.0.1: 6379>Expire chen 10
- (Integer) 1
- Redis 127.0.0.1: 6379>Ttl chen
- (Integer) 6
- Redis 127.0.0.1: 6379>Ttl chen
- (Integer) 4
- Redis 127.0.0.1: 6379>Ttl chen
- (Integer) 2
- Redis 127.0.0.1: 6379>Keys *
- 1) "key2"
- 2) "test"
- 3) "name"
- 4) "key1"
- Redis 127.0.0.1: 6379>Expire test 100
- (Integer) 1
- Redis 127.0.0.1: 6379>Ttl test
- (Integer) 94
- Redis 127.0.0.1: 6379>Persist test
- (Integer) 1
- Redis 127.0.0.1: 6379>Ttl test
- (Integer)-1
In addition, redis has 16 inventories by default. How can we choose and use redis: select move
- Redis 127.0.0.1: 6379 [19]>Select 15
- OK
- Redis 127.0.0.1: 6379 [15]>Select 16
- (Error) ERR invalid DB index
- Redis 127.0.0.1: 6379>Keys *
- 1) "key2"
- 2) "test"
- 3) "name"
- 4) "key1"
- Redis 127.0.0.1: 6379>Move key1 1
- (Integer) 1
- Redis 127.0.0.1: 6379>Select 1
- OK
- Redis 127.0.0.1: 6379 [1]>Keys *
- 1) "test3"
- 2) "test"
- 3) "key1"
- 4) "test2"
- 5) "myhash"
- 6) "mylist"
- Redis 127.0.0.1: 6379 [1]>Select 0
- OK
- Redis 127.0.0.1: 6379>Keys *
- 1) "key2"
- 2) "test"
- 3) "name"