Redis Simple Operations Command Introduction

Source: Internet
Author: User
Tags benchmark redis server

Time display server time, timestamp (seconds), microseconds

127.0.0.1:6379> time
1) "1462572140"
2) "564061"

Dbsize//number of keys in the current database
127.0.0.1:6379> dbsize
(integer) 3

Different results after switching to another DB
127.0.0.1:6379> Select 3
Ok
127.0.0.1:6379[3]> dbsize
(integer) 0

bgrewriteaof background Process rewrite aof
[email protected] redisdb]# LL
Total 28912
-rw-r--r--1 root root 29600160 May 6 22:08 appendonly_master.aof
-rw-r--r--1 root root 7 05:45 redis_master.db
127.0.0.1:6379[3]> bgrewriteaof
Background Append only file rewriting started
After rewriting the AOF:
[email protected] redisdb]# LL
Total 8
-rw-r--r--1 root root 153 May 7 06:04 appendonly_master.aof
-rw-r--r--1 root root 7 05:45 redis_master.db

BGSAVE Background Save Rdb Snapshot
127.0.0.1:6379[3]> BGSAVE
Background Saving started
Rewritten Rdb file modification time:
[email protected] redisdb]# LL
Total 8
-rw-r--r--1 root root 153 May 7 06:04 appendonly_master.aof
-rw-r--r--1 root root 7 06:04 redis_master.db

Save the Rdb Snapshot
As with bgsave usage, it is only not recommended when the volume of data is large, instead bgsave

Lastsave Last save timestamp
127.0.0.1:6379[3]> Lastsave
(integer) 1462572342


Flushall Empty All library keys
FLUSHDB clears all keys for the current library
Showdown [Save/nosave] Turn off Redis

Note: If you accidentally run the Flushall, shutdown Nosave immediately, shut down the server
Then manually edit the AoF file, remove the "Flushall" related lines in the file, and then turn on the server, you can import back to the original data.
[Email protected] redisdb]# REDIS-CLI
127.0.0.1:6379> keys *
(Error) Noauth Authentication required.
127.0.0.1:6379> Auth Passw0rd
Ok
127.0.0.1:6379> keys *
1) "key:__rand_int__"
2) "counter:__rand_int__"
3) "DB"
127.0.0.1:6379> Flushall
Ok
127.0.0.1:6379> keys *
(empty list or set)
127.0.0.1:6379> SHUTDOWN Nosave
Not connected> exit
Edit the AoF file to remove the last line of Flushall:
$8
Flushall
"Appendonly_master.aof" [dos] 39L, 217C
Restart Redis again:
[Email protected] redisdb]# redis-server/etc/redis/redis.conf
[Email protected] redisdb]# REDIS-CLI
127.0.0.1:6379> Auth Passw0rd
Ok
127.0.0.1:6379> keys *
1) "DB"
2) "key:__rand_int__"
3) "counter:__rand_int__
If, after Flushall, the system happens to be bgrewriteaof, then the AOF is emptied and the data is lost.


Slowlog Show Slow Query
Note: How slow is slow?
Answer: Specified by Slowlog-log-slower-than 10000, (in microseconds)

How many slow query records does the server store?
Answer: By Slowlog-max-len 128, to do the limit

Info [Replication/cpu/memory.]
View information for a Redis server

Config get configuration item
Config Set configuration item value (special option, not allowed with this command set, such as slave-of, need to be set with a separate slaveof command)

127.0.0.1:6379> CONFIG GET Slowlog-log-slower-than
1) "Slowlog-log-slower-than"
2) "10000"
Configure Slowlog
127.0.0.1:6379> CONFIG SET Slowlog-log-slower-than 100
Ok
Re-use the benchmark test once:
[Email protected] redisdb]# redis-benchmark-a passw0rd-n 200000
127.0.0.1:6379> Slowlog Get
1) 1) (integer) 163
2) (integer) 1462572873
3) (integer) 102
4) 1) "Lpush"
2) "MyList"
3) "XXX"
2) 1) (integer) 162
2) (integer) 1462572873
3) (integer) 178
4) 1) "Lpush"
2) "MyList"
。。。。
Now with Slowlog, you can get the specified slowlog:
127.0.0.1:6379> Slowlog Get 3
1) 1) (integer) 920
2) (integer) 1462572912
3) (integer) 101
4) 1) "Lrange"
2) "MyList"
3) "0"
4) "449"
2) 1) (integer) 919
2) (integer) 1462572912
3) (integer) 171
4) 1) "Lrange"
2) "MyList"
3) "0"
4) "449"
3) 1) (integer) 918
2) (integer) 1462572912
3) (integer) 130
4) 1) "Lrange"
2) "MyList"
3) "0"
4) "449"

This article is from the "Technical Blog" blog, please be sure to keep this source http://raytech.blog.51cto.com/7602157/1770942

Redis Simple Operations Command Introduction

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.