Test some common commands of Redis

Source: Internet
Author: User

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)

  1. [Root @ fsailing1 bin] #./redis-cli
  2. Redis 127.0.0.1: 6379>Keys *
  3. 1) "key2"
  4. 2) "age"
  5. 3) "ss"
  6. 4) "test"
  7. 5) "name"
  8. 6) "key1"
  9. Redis 127.0.0.1: 6379>Dbsize
  10. (Integer) 6
  11. Redis 127.0.0.1: 6379>Info
  12. Redis_version: 2.4.15
  13. Redis_git_sha1: 00000000
  14. Vm_enabled: 0
  15. Role: master
  16. Db0: keys=6,Expires=0
  17. Db1: keys=5,Expires=0
When you view a key value, exists deletes a key value and del
  1. Redis 127.0.0.1: 6379>Exists age
  2. (Integer) 1
  3. Redis 127.0.0.1: 6379>Exists chen
  4. (Integer) 0
  5. Redis 127.0.0.1: 6379>Del age
  6. (Integer) 1
  7. Redis 127.0.0.1: 6379>Exists age
  8. (Integer) 0
Rename/renamenx
  1. Redis 127.0.0.1: 6379>Keys *
  2. 1) "key2"
  3. 2) "ss"
  4. 3) "test"
  5. 4) "name"
  6. 5) "key1"
  7. Redis 127.0.0.1: 6379>Rename ss chen
  8. OK
  9. Redis 127.0.0.1: 6379>Renamenx key1 chen
  10. (Integer) 0
  11. Redis 127.0.0.1: 6379>Keys *
  12. 1) "key2"
  13. 2) "chen"
  14. 3) "test"
  15. 4) "name"
  16. 5) "key1"
Another command to set the expiration time and persistent expire/persist is to view the current situation. ttl means time to live.
  1. Redis 127.0.0.1: 6379>Keys *
  2. 1) "key2"
  3. 2) "ss"
  4. 3) "test"
  5. 4) "name"
  6. 5) "key1"
  7. Redis 127.0.0.1: 6379>Rename ss chen
  8. OK
  9. Redis 127.0.0.1: 6379>Renamenx key1 chen
  10. (Integer) 0
  11. Redis 127.0.0.1: 6379>Keys *
  12. 1) "key2"
  13. 2) "chen"
  14. 3) "test"
  15. 4) "name"
  16. 5) "key1"
  17. Redis 127.0.0.1: 6379>Expire chen 10
  18. (Integer) 1
  19. Redis 127.0.0.1: 6379>Ttl chen
  20. (Integer) 6
  21. Redis 127.0.0.1: 6379>Ttl chen
  22. (Integer) 4
  23. Redis 127.0.0.1: 6379>Ttl chen
  24. (Integer) 2
  25. Redis 127.0.0.1: 6379>Keys *
  26. 1) "key2"
  27. 2) "test"
  28. 3) "name"
  29. 4) "key1"
  30. Redis 127.0.0.1: 6379>Expire test 100
  31. (Integer) 1
  32. Redis 127.0.0.1: 6379>Ttl test
  33. (Integer) 94
  34. Redis 127.0.0.1: 6379>Persist test
  35. (Integer) 1
  36. Redis 127.0.0.1: 6379>Ttl test
  37. (Integer)-1
In addition, redis has 16 inventories by default. How can we choose and use redis: select move
  1. Redis 127.0.0.1: 6379 [19]>Select 15
  2. OK
  3. Redis 127.0.0.1: 6379 [15]>Select 16
  4. (Error) ERR invalid DB index
  1. Redis 127.0.0.1: 6379>Keys *
  2. 1) "key2"
  3. 2) "test"
  4. 3) "name"
  5. 4) "key1"
  6. Redis 127.0.0.1: 6379>Move key1 1
  7. (Integer) 1
  8. Redis 127.0.0.1: 6379>Select 1
  9. OK
  10. Redis 127.0.0.1: 6379 [1]>Keys *
  11. 1) "test3"
  12. 2) "test"
  13. 3) "key1"
  14. 4) "test2"
  15. 5) "myhash"
  16. 6) "mylist"
  17. Redis 127.0.0.1: 6379 [1]>Select 0
  18. OK
  19. Redis 127.0.0.1: 6379>Keys *
  20. 1) "key2"
  21. 2) "test"
  22. 3) "name"
  • 1
  • 2
  • Next Page

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.