redis介绍

2017-10-13

Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker. It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs and geospatial indexes with radius queries. Redis has built-in replication, Lua scripting, LRU eviction, transactions and different levels of on-disk persistence, and provides high availability via Redis Sentinel and automatic partitioning with Redis Cluster.

 

1、蕊黛丝redis

默认redis支持16个数据库

redis不支持自定义数据库名字,每个数据库以编号命名。

redis不支持为每个数据库设置不同的访问密码。

flushall 可以清空一个redis实例中所有数据库的数据

2、

find . -type f -name "redis*" |awk '{print $1 " stop"}'
redis-cli -h $HOSTNAME -p 100000

ping PONG返回响应是否连接成功
echo hi在命令行打印一些内容

set db_number 1
默认使用 0 号数据库
GET db_number

 

 

SELECT 1 # 使用 1 号数据库

keys *
1) "db_number"
2) "chat:cate:10000004"
3) "fav:10000004"
4) "u:10000004"
5) "room:10000004"
6) "gu:10000004"
7) "quick:10000004"

3、redis-cli is the Redis command line interface, a simple program that allows to send commands to Redis, and read the replies sent by the server, directly from the terminal.

redis-cli --stat

redis-cli --bigkeys

redis-cli --scan | head -10

redis-cli --scan --pattern '*-11*'

redis-cli --scan --pattern 'user:*' | wc -l

redis-cli monitor

redis-cli --latency

redis-cli --slave

./redis-cli --lru-test 10000000

4、cat /tmp/commands.txt | redis-cli

5、配置3台主从

1--172.17.0.5
2--172.17.0.6
3--172.17.0.10

| 主机 | 备机 |
|----- |----  |
|1:2100|2:2101|
|2:2100|3:2101|
|3:2100|1:2101|

|1:2102|2:2103|
|2:2102|3:2103|
|3:2102|1:2103|

|1:2104|2:2105|
|2:2104|3:2105|
|3:2104|1:2105|

./redis-trib.rb create --replicas 1 172.17.0.5:2100 172.17.0.6:2101 172.17.0.6:2100 172.17.0.10:2101 172.17.0.10:2100 172.17.0.5:2101
./redis-trib.rb create --replicas 1 172.17.0.5:2102 172.17.0.6:2103 172.17.0.6:2102 172.17.0.10:2103 172.17.0.10:2102 172.17.0.5:2102
./redis-trib.rb create --replicas 1 172.17.0.5:2104 172.17.0.6:2105 172.17.0.6:2104 172.17.0.10:2105 172.17.0.10:2104 172.17.0.5:2105

5、为了执行redis-trib.rb,需要

cp /opt/redis-4.0.6/src/redis-trib.rb .

下载

yum -y install ruby rubygems
ruby 默认安装的是2.0,如果需要安装更新版本需要编译安装

wget https://rubygems.global.ssl.fastly.net/gems/redis-3.2.2.gem

gem install redis-3.2.2.gem

wget https://rubygems.global.ssl.fastly.net/gems/redis-4.0.1.gem

gem install redis-4.0.1.gem

redis requires Ruby version >= 2.2.2.

 

5、启动停止脚本
/etc/init.d
stop增加
-h $HOSTNAME

 

分类:Linux | 标签: |

相关日志

评论被关闭!