Redis命令合集

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79

echo "511","ALL" > /proc/sys/net/core/somaxconn
sysctl vm.overcommit_memory=1
echo never > /sys/kernel/mm/transparent_hugepage/enabled

查看redis版本
redis-cli -v

登陆
redis-cli -h 192.168.2.109 -p 6379

密码登陆
redis-cli -a passwd

redis默认登陆是0库,可以用select命令切换
redis> select 1

查看当前redis有没有设置密码:
127.0.0.1:6379> config get requirepass
1) "requirepass"
2) ""

设置密码(重启失效)
> config set requirepass "test1234","ALL"

返回当前数据库中键的总数
> dbsize   

开启慢查询
> config set slowlog-log-slower-than 20000 
> config set slowlog-max-len 1000 
> config rewrite
如果要Redis将配置持久化到本地配置文件,需执行config rewrite命令

获取慢查询日志
> slowlog get
日志格式
标识id、发生时间戳、命令耗时(单位微妙)、执行命令和参数,

慢查询日志重置
> slowlog reset

新建主从复制, 命令执行后本机为slave,192.168.1.100为master
> slaveof 192.168.1.100 6379

断开主从复制, 需在slave节点执行此命令
> slaveof no one 

集群信息
cluster
> cluster nodes
> cluster info

scan获取key
> scan 0 match test* count 1000

获取100个key
127.0.0.1:6379> SCAN 0 match * count 100
1) "29312","ALL"
2)   1) "BASICDATA:REGION:MAP:ID:46122","ALL"

查看key的类型
> type BASICDATA:REGION:MAP:ID:46122

set类型:
  SMEMBERS key
  返回集合中的所有成员

zset:
  ZRANGE key start stop [WITHSCORES]
  通过索引区间返回有序集合指定区间内的成员

hash类型:
  获取key
  HGETALL key

list:
  LRANGE key start stop
  获取列表指定范围内的元素
……

阅读全文

Redis配置文件解释

protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile /var/run/redis_6379.pid
loglevel notice
logfile "/var/log/redis.log"
databases 16
always-show-logo yes

save 900 1
save 300 10
save 60 10000
# 只要满足以下三个条件中的任意一个,BGSAVE命令就会被执行:
# 服务器在900秒之内,对数据库进行了至少1次修改
# 服务器在300秒之内,对数据库进行了至少10次修改
# 服务器在60秒之内,对数据库进行了至少10000次修改

stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb

dir ./
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
slave-lazy-flush no
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble no
lua-time-limit 5000

slowlog-log-slower-than 10000
单位是微妙(1秒=1000毫秒=1000000微秒),默认值10000

slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes

masterauth "123","ALL"
# 针对master对应的slave节点设置的,在slave节点数据同步的时候用到

requirepass "1234","ALL"
# 本节点(实例)登录权限的限制
……

阅读全文

MYSQL ERRS

001

cripts/mysql_install_db –no-defaults –datadir=/mysql/my_cluster/mysqld_data/
FATAL ERROR: please install the following Perl modules before executing scripts/mysql_install_db:
Data::Dumper

yum install perl-Data-Dumper.x86_64

002

ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect…

set global max_allowed_packet=100M
将此值设置大些

003

[root@localhost ~]# rpm -ivh mysql-community-server-5.7.21-1.el6.x86_64.rpm
warning: mysql-community-server-5.7.21-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
libsasl2.so.2()(64bit) is needed by mysql-community-server-5.7.21-1.el6.x86_64

rpm -ivh https://rpmfind.net/linux/Mandriva/devel/cooker/x86_64/media/main/release/lib64sasl2-2.1.25-4-mdv2012.0.x86_64.rpm

004

[root@iZm5e3vnh3gtu6fzpvc2ooZ ~]# systemctl restart mysql

Job for mysql.service failed because the control process exited with error code. See “systemctl status mysql.service” and “journalctl -xe” for details.
[root@iZm5e3vnh3gtu6fzpvc2ooZ ~]# more /var/lib/mysql/iZm5e3vnh3gtu6fzpvc2ooZ.err
2018-03-11 16:21:02 4452 [Note] Plugin ‘FEDERATED’ is disabled.
/usr/sbin/mysqld: Can’t find file: ‘./mysql/plugin.frm’ (errno: 13 – Permission denied)
2018-03-11 16:21:02 4452 [ERROR] Can’t open the mysql.plugin table. Please run mysql_upgrade to create it.
2018-03-11 16:21:02 4452 [Note] InnoDB: Using atomics to ref count buffer pool pages
2018-03-11 16:21:02 4452 [Note] InnoDB: The InnoDB memory heap is disabled
2018-03-11 16:21:02 4452 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-03-11 16:21:02 4452 [Note] InnoDB: Memory barrier is not used
2018-03-11 16:21:02 4452 [Note] InnoDB: Compressed tables use zlib 1.2.3
2018-03-11 16:21:02 4452 [Note] InnoDB: Using Linux native AIO
2018-03-11 16:21:02 4452 [Note] InnoDB: Using CPU crc32 instructions
2018-03-11 16:21:02 4452 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2018-03-11 16:21:02 4452 [Note] InnoDB: Completed initialization of buffer pool
2018-03-11 16:21:02 4452 [ERROR] InnoDB: ./ibdata1 can’t be opened in read-write mode
2018-03-11 16:21:02 4452 [ERROR] InnoDB: The system tablespace must be writable!
2018-03-11 16:21:02 4452 [ERROR] Plugin ‘InnoDB’ init function returned error.
2018-03-11 16:21:02 4452 [ERROR] Plugin ‘InnoDB’ registration as a STORAGE ENGINE failed.
2018-03-11 16:21:02 4452 [ERROR] Unknown/unsupported storage engine: InnoDB
2018-03-11 16:21:02 4452 [ERROR] Aborting
解决办法solution:
chown mysql.mysql -R /var/lib/mysql
……

阅读全文

Sublime使用记录

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
1. python3 new build system

{

    "cmd": ["C:/path/python.exe","-u","$file"],

    "file_regex":"^[ ]*File \"(...*?)\", line ([0-9]*)",

    "selector":"source.python",

}

2. package control install sublimerepl
需要连接vpn

3. 设置快捷键
preferences->Key Binding-User,写入以下内容

[
    { "keys": ["f5"], "caption": "SublimeREPL:Python", 
                      "command": "run_existing_window_command", "args":
                      {
                           "id": "repl_python_run",
                           "file": "config/Python/Main.sublime-menu"
                      } 
    },
]

4. 快捷键
发现sublime真是好用啊。

ctrl+shift+/ 多行注释

选中多行,按下ctr+shift+L,可在多行行尾编辑,行首编辑需要按下右箭头 <--,行尾编辑按下-->

shift+右击上下拉
……

阅读全文

MySQL8.0安装使用(centos8)

一、 简单介绍

MySQL(官方发音为/maɪ ˌɛskjuːˈɛl/“My S-Q-L”[5],但也经常被错误读作/maɪ ˈsiːkwəl/“My Sequel”)是一个开放源码的关系数据库管理系统.

……

阅读全文

Redis安装使用

一、 简单介绍 Redis是一个开源(BSD授权)的基于内存键值对存储数据库,也常用来做缓存和消息中介。它支持字符串、哈希、列表、集合等多种数据结构。Redis内置了复制、Lua脚本、事务和磁盘持久性,并通过哨兵(Redis Sentinel)和集群(Redis Cluster)自动分区提供高可用性。

……

阅读全文