linux下操作redis相关命令

Redis主从设置
cp redis.conf redis6381.conf

centos7下redis哨兵集群配置
https://blog.csdn.net/weixin_42231507/article/details/81263240

监控redis: ./redis-cli -h 192.168.1.26 -p 32198 -a ~1@4e87x03874#NwOw0818 monitor > monitor.log 2>&1 &

192.168.1.26:6379> info replication//查看当前redis信息
192.168.1.26:26379> info sentinel//查看当前哨兵信息

[root@bogon bin]# ps aux|grep mongedb //查看redis已经启动服务
(1) 基本属性配置
pidfile /var/run/redis/redis6380-server.pid
port 6380 必须
logfile /var/log/redis/redis6380-server.log
dbfilename dump6380.rdb
(2)主从配置
slaveof 127.0.0.1 6379 必须
[root@bogon bin]# ./redis-server …/redis.conf 启动服务
[root@bogon bin]# ./redis-cli -h 192.168.1.26 -p 6380 (shutdown)
启动redis或者哨兵客户端
[root@bogon bin]# ./redis-sentinel …/sentinel26379.conf 启动哨兵

防火墙命令
systemctl stop firewalld.service #停止firewall

firewall-cmd --state ##查看防火墙状态,是否是running

remove
firewall-cmd --zone=public --add-port=1521/tcp --permanent //开启端口

firewall-cmd --reload //重启防火墙

firewall-cmd --list-ports //已开放端口

city.sql(bin目录下)如下:

SELECT CONCAT(
"*8\r\n",
'$', LENGTH(redis_cmd), '\r\n',redis_cmd, '\r\n','$', LENGTH(redis_key), '\r\n',redis_key, '\r\n',
'$', LENGTH(hkey1), '\r\n',hkey1, '\r\n','$', LENGTH(hval1), '\r\n', hval1, '\r\n'
'$', LENGTH(hkey2), '\r\n',hkey2, '\r\n','$', LENGTH(hval2), '\r\n', hval2, '\r\n'
'$', LENGTH(hkey3), '\r\n',hkey3, '\r\n','$', LENGTH(hval3), '\r\n', hval3, '\r')
FROM (
SELECT
'HMSET' AS redis_cmd, CONCAT('id:',id) AS redis_key,
'province_id' AS hkey1,province_id  AS hval1,
'city_name' AS hkey2,city_name AS hval2,
'create_time' AS hkey3,create_time AS hval3
 FROM t_city
 ) AS t

[root@bogon bin]# mysql -upublic -p654321 -h192.168.1.16 mydb --default-character-set=utf8 --skip-column-names --raw<product.sql | ./redis-cli -h 192.168.1.16 -p 6379 --pipe
[root@bogon bin]# mysql -upublic -p654321 mydb --default-character-set=utf8 --skip-column-names --raw<city.sql | ./redis-cli -h 192.168.1.26 -p 6379 --pipe

product.sql
SELECT CONCAT(
"*40\r\n",
'$', LENGTH(redis_cmd), '\r\n',redis_cmd, '\r\n','$', LENGTH(redis_key), '\r\n',redis_key, '\r\n',
'$', LENGTH(hkey1), '\r\n',hkey1, '\r\n','$', LENGTH(hval1), '\r\n', hval1, '\r\n'
'$', LENGTH(hkey2), '\r\n',hkey2, '\r\n','$', LENGTH(hval2), '\r\n', hval2, '\r\n'
'$', LENGTH(hkey3), '\r\n',hkey3, '\r\n','$', LENGTH(hval3), '\r\n', hval3, '\r\n'
'$', LENGTH(hkey4), '\r\n',hkey4, '\r\n','$', LENGTH(hval4), '\r\n', hval4, '\r\n'
'$', LENGTH(hkey5), '\r\n',hkey5, '\r\n','$', LENGTH(hval5), '\r\n', hval5, '\r\n'
'$', LENGTH(hkey6), '\r\n',hkey6, '\r\n','$', LENGTH(hval6), '\r\n', hval6, '\r\n'
'$', LENGTH(hkey7), '\r\n',hkey7, '\r\n','$', LENGTH(hval7), '\r\n', hval7, '\r\n'
'$', LENGTH(hkey8), '\r\n',hkey8, '\r\n','$', LENGTH(hval8), '\r\n', hval8, '\r\n'
'$', LENGTH(hkey9), '\r\n',hkey9, '\r\n','$', LENGTH(hval9), '\r\n', hval9, '\r\n'
'$', LENGTH(hkey10), '\r\n',hkey10, '\r\n','$', LENGTH(hval10), '\r\n', hval10, '\r\n'
'$', LENGTH(hkey11), '\r\n',hkey11, '\r\n','$', LENGTH(hval11), '\r\n', hval11, '\r\n'
'$', LENGTH(hkey12), '\r\n',hkey12, '\r\n','$', LENGTH(hval12), '\r\n', hval12, '\r\n'
'$', LENGTH(hkey13), '\r\n',hkey13, '\r\n','$', LENGTH(hval13), '\r\n', hval13, '\r\n'
'$', LENGTH(hkey14), '\r\n',hkey14, '\r\n','$', LENGTH(hval14), '\r\n', hval14, '\r\n'
'$', LENGTH(hkey15), '\r\n',hkey15, '\r\n','$', LENGTH(hval15), '\r\n', hval15, '\r\n'
'$', LENGTH(hkey16), '\r\n',hkey16, '\r\n','$', LENGTH(hval16), '\r\n', hval16, '\r\n'
'$', LENGTH(hkey17), '\r\n',hkey17, '\r\n','$', LENGTH(hval17), '\r\n', hval17, '\r\n'
'$', LENGTH(hkey18), '\r\n',hkey18, '\r\n','$', LENGTH(hval18), '\r\n', hval18, '\r\n'
'$', LENGTH(hkey19), '\r\n',hkey19, '\r\n','$', LENGTH(hval19), '\r\n', hval19, '\r')
FROM (
SELECT
'HMSET' AS redis_cmd, CONCAT('product:',id) AS redis_key,
'code' AS hkey1,if(code is not null, code, '') AS hval1,
'product_category_id' AS hkey2,if(product_category_id is not null, product_category_id, '') AS hval2,
'sale_price' AS hkey3,if(sale_price is not null, sale_price, '') AS hval3,
'main_title' AS hkey4,if(main_title is not null, main_title, '') AS hval4,
'sub_title' AS hkey5,if(sub_title is not null, sub_title, '') AS hval5,
'sales_volume' AS hkey6,if(sales_volume is not null, sales_volume, '') AS hval6,
'cost_price' AS hkey7,if(cost_price is not null, cost_price, '') AS hval7,
'color' AS hkey8,if(type is not null, type , '') AS hval8,
'type' AS hkey9,if(type is not null, type , '') AS hval9,
'brand' AS hkey10,if(brand is not null, brand, '') AS hval10,
'product_detail' AS hkey11,if(product_detail is not null, product_detail, '') AS hval11,
'is_active' AS hkey12,if(is_active is not null, is_active, '') AS hval12,
'create_time' AS hkey13,if(create_time is not null, create_time, '') AS hval13,
'modify_time' AS hkey14,if(modify_time is not null, modify_time, '') AS hval14,
'creater_id' AS hkey15,if(creater_id is not null, creater_id, '') AS hval15,
'modifier_id' AS hkey16,if(modifier_id is not null, modifier_id, '') AS hval16,
'quantity' AS hkey17,if(quantity is not null, quantity , '') AS hval17,
'puton_time' AS hkey18,if(puton_time is not null, puton_time, '') AS hval18,
'pulloff_time' AS hkey19,if(pulloff_time is not null, pulloff_time, '') AS hval19
 FROM t_product
 ) AS t


SELECT CONCAT(
"*40\r\n",
'$', LENGTH(redis_cmd), '\r\n',redis_cmd, '\r\n','$', LENGTH(redis_key), '\r\n',redis_key, '\r\n',
'$', LENGTH(hkey1), '\r\n',hkey1, '\r\n','$', LENGTH(hval1), '\r\n', hval1, '\r\n'
'$', LENGTH('productCategoryId'), '\r\n','productCategoryId', '\r\n','$', LENGTH(hval2), '\r\n', hval2, '\r\n'
'$', LENGTH('salePrice'), '\r\n','salePrice', '\r\n','$', LENGTH(hval3), '\r\n', hval3, '\r\n'
'$', LENGTH('mainTitle'), '\r\n','mainTitle', '\r\n','$', LENGTH(hval4), '\r\n', hval4, '\r\n'
'$', LENGTH('subTitle'), '\r\n','subTitle', '\r\n','$', LENGTH(hval5), '\r\n', hval5, '\r\n'
'$', LENGTH('salesVolume'), '\r\n','salesVolume', '\r\n','$', LENGTH(hval6), '\r\n', hval6, '\r\n'
'$', LENGTH('costPrice'), '\r\n','costPrice', '\r\n','$', LENGTH(hval7), '\r\n', hval7, '\r\n'
'$', LENGTH(hkey8), '\r\n',hkey8, '\r\n','$', LENGTH(hval8), '\r\n', hval8, '\r\n'
'$', LENGTH(hkey9), '\r\n',hkey9, '\r\n','$', LENGTH(hval9), '\r\n', hval9, '\r\n'
'$', LENGTH(hkey10), '\r\n',hkey10, '\r\n','$', LENGTH(hval10), '\r\n', hval10, '\r\n'
'$', LENGTH('productDetail'), '\r\n','productDetail', '\r\n','$', LENGTH(hval11), '\r\n', hval11, '\r\n'
'$', LENGTH('isActive'), '\r\n','isActive', '\r\n','$', LENGTH(hval12), '\r\n', hval12, '\r\n'
'$', LENGTH('createTime'), '\r\n','createTime', '\r\n','$', LENGTH(hval13), '\r\n', hval13, '\r\n'
'$', LENGTH('modifyTime'), '\r\n','modifyTime', '\r\n','$', LENGTH(hval14), '\r\n', hval14, '\r\n'
'$', LENGTH('createrId'), '\r\n','createrId', '\r\n','$', LENGTH(hval15), '\r\n', hval15, '\r\n'
'$', LENGTH('modifierId'), '\r\n','modifierId', '\r\n','$', LENGTH(hval16), '\r\n', hval16, '\r\n'
'$', LENGTH(hkey17), '\r\n',hkey17, '\r\n','$', LENGTH(hval17), '\r\n', hval17, '\r\n'
'$', LENGTH('putonTime'), '\r\n','putonTime', '\r\n','$', LENGTH(hval18), '\r\n', hval18, '\r\n'
'$', LENGTH('pulloffTime'), '\r\n','pulloffTime', '\r\n','$', LENGTH(hval19), '\r\n', hval19, '\r')
FROM (
SELECT
'HMSET' AS redis_cmd, CONCAT('product:',id) AS redis_key,
'code' AS hkey1,if(code is not null, code, '') AS hval1,
'product_category_id' AS hkey2,if(product_category_id is not null, product_category_id, '') AS hval2,
'sale_price' AS hkey3,if(sale_price is not null, sale_price, '') AS hval3,
'main_title' AS hkey4,if(main_title is not null, main_title, '') AS hval4,
'sub_title' AS hkey5,if(sub_title is not null, sub_title, '') AS hval5,
'sales_volume' AS hkey6,if(sales_volume is not null, sales_volume, '') AS hval6,
'cost_price' AS hkey7,if(cost_price is not null, cost_price, '') AS hval7,
'color' AS hkey8,if(type is not null, type , '') AS hval8,
'type' AS hkey9,if(type is not null, type , '') AS hval9,
'brand' AS hkey10,if(brand is not null, brand, '') AS hval10,
'product_detail' AS hkey11,if(product_detail is not null, product_detail, '') AS hval11,
'is_active' AS hkey12,if(is_active is not null, is_active, '') AS hval12,
'create_time' AS hkey13,if(create_time is not null, create_time, '') AS hval13,
'modify_time' AS hkey14,if(modify_time is not null, modify_time, '') AS hval14,
'creater_id' AS hkey15,if(creater_id is not null, creater_id, '') AS hval15,
'modifier_id' AS hkey16,if(modifier_id is not null, modifier_id, '') AS hval16,
'quantity' AS hkey17,if(quantity is not null, quantity , '') AS hval17,
'puton_time' AS hkey18,if(puton_time is not null, puton_time, '') AS hval18,
'pulloff_time' AS hkey19,if(pulloff_time is not null, pulloff_time, '') AS hval19
 FROM t_product
 ) AS t

serviceItem.sql
SELECT CONCAT(
"*12\r\n",
'$', LENGTH(redis_cmd), '\r\n',redis_cmd, '\r\n','$', LENGTH(redis_key), '\r\n',redis_key, '\r\n',
'$', LENGTH(hkey), '\r\n',hkey, '\r\n','$', LENGTH(hval), '\r\n', hval, '\r\n'
'$', LENGTH('productType'), '\r\n','productType', '\r\n','$', LENGTH(hval1), '\r\n', hval1, '\r\n'
'$', LENGTH(hkey2), '\r\n',hkey2, '\r\n','$', LENGTH(hval2), '\r\n', hval2, '\r\n'
'$', LENGTH(hkey3), '\r\n',hkey3, '\r\n','$', LENGTH(hval3), '\r\n', hval3, '\r\n'
'$', LENGTH(hkey4), '\r\n',hkey4, '\r\n','$', LENGTH(hval4), '\r\n', hval4, '\r\n'
'$', LENGTH('createTime'), '\r\n','createTime', '\r\n','$', LENGTH(hval5), '\r\n', hval5, '\r')
FROM (
SELECT
'HMSET' AS redis_cmd, CONCAT('serviceItem:',id) AS redis_key,
'id' AS hkey,if(id is not null, id, '') AS hval,
'product_type' AS hkey1,if(product_type is not null, product_type, '') AS hval1,
'name' AS hkey2,if(name is not null, name, '') AS hval2,
'description' AS hkey3,if(description is not null, description, '') AS hval3,
'price' AS hkey4,if(price is not null, price, '') AS hval4,
'create_time' AS hkey5,if(create_time is not null, create_time, '') AS hval5
 FROM t_service_item
 ) AS t
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值