关于readis与mysql不同的是,redis是非关系型数据库,即no-sql,而mysql是关系型数据库。
mysql关系型数据库是基于行式存储,一行代表一条数据,对于非关系型数据库则是以key-value模式存储,对于数据库扩展能力大大增强。
- redis-server.exe redis的服务器端
- redis-cli.exe redis的客户端
- redis.windows.conf redis的配置文件
命令操作
String 字符串型
hash map
list linkedList
set 不允许重复元素
sortedset 不允许重复元素,元素有顺序
hash
hset key filedname value
127.0.0.1:6379> set username zhangsan
OK
127.0.0.1:6379> get usename
(nil)
127.0.0.1:6379> get username
"zhangsan"
127.0.0.1:6379> set username zhengmiao
OK
127.0.0.1:6379> get username
"zhengmiao"
127.0.0.1:6379> hset myhash username zhao
(integer) 1
127.0.0.1:6379> hget myhash username
"zhao"
获得所有键值 hash
获得所有key
127.0.0.1:6379> keys *
1) "myhash"
2) "username"
list
lpush key value
127.0.0.1:6379> lpush mylist zhangsan
(integer) 1
127.0.0.1:6379> rpush mylist lisi
(integer) 2
127.0.0.1:6379> lrange mylist 0-1
(error) ERR wrong number of arguments for 'lrange' command
127.0.0.1:6379> lrange mylist 0 -1
1) "zhangsan"
2) "lisi"
127.0.0.1:6379> rrange mylist 0 -1
(error) ERR unknown command 'rrange'
127.0.0.1:6379> lpop mylist
"zhangsan"
127.0.0.1:6379> lrange mylist 0 -1
1) "lisi"
set语法
sadd key value
sortedset
zadd key score value
127.0.0.1:6379> zadd mysort 80 zhangsan
(integer) 1
127.0.0.1:6379> zadd mysort 90 lisi
(integer) 1
127.0.0.1:6379> zadd mysort 70 wangwu
(integer) 1
127.0.0.1:6379> zrange mysort 0 -1
1) "wangwu"
2) "zhangsan"
3) "lisi"
127.0.0.1:6379> zrem mysort lisi
(integer) 1
127.0.0.1:6379> zrange mysort 0 -1
1) "wangwu"
2) "zhangsan"
- after 900 sec (15 min) if at least 1 key changed
- after 300 sec (5 min) if at least 10 keys changed
- after 60 sec if at least 10000 keys changed