标签:通过 根据 进制 rpo 时间 模式 jpeg off str
Redis key 值是二进制安全的, 可以用任何二进制序列作为key值, 无论是简单字符串还是JPEG文件的内容皆可。空字符串也是有效key值。
select databaseid 选中数据库 (redis 默认有16个实例库, 0~15, 登录时默认库0)
KEYS pattern
EXISTS key
EXPIRE key seconds
MOVE key db
TTL key
TYPE key
DEL key [key ...]
练习:
# exercise
127.0.0.1:6379> select 1
OK
127.0.0.1:6379[1]> exists ronnie
(integer) 0
127.0.0.1:6379[1]> set ronnie yuan
OK
127.0.0.1:6379[1]> exists ronnie
(integer) 1
127.0.0.1:6379[1]> move ronnie 2
(integer) 1
127.0.0.1:6379[1]> exists ronnie
(integer) 0
127.0.0.1:6379[1]> select 2
OK
127.0.0.1:6379[2]> exists ronnie
(integer) 1
127.0.0.1:6379[2]> type ronnie
string
127.0.0.1:6379[2]> del ronnie
(integer) 1
127.0.0.1:6379[2]> exists ronnie
(integer) 0
# ex
127.0.0.1:6379[2]> SETEX test 20 fun
OK
127.0.0.1:6379[2]> ttl test
(integer) 16
127.0.0.1:6379[2]> ttl test
(integer) 12
127.0.0.1:6379[2]> ttl test
(integer) 5
127.0.0.1:6379[2]> ttl test
(integer) -2
字符串是Redis最基本的一种值类型。Redis 字符串是二进制安全的, 这意味着一个Redis字符串能包含任意类型的数据
SET key value [EX seconds][PX milliseconds] [NX|XX]
# EX: 设置过期时间, 秒, 等同于SETEX key seconds value
# PX: 设置过期时间, 毫秒, 等同于PSETEX key milliseconds value
# NX: NX键不存在, 才能设置, 等同于SETNX key value
# XX: XX键存在时, 才能设置
## 将字符串值 value 关联到key
## 如果该 key 已经持有其他值, SET就覆写旧值, 无视类型
## 对于某个原本带有生存时间(TTL)的键来说, 当 SET 命令成功在这个键上执行时, 这个键原有的 TTL 将被清除。
GET key
APPEND key value
STRLEN key (String Length of key)
INCR key (INCR --> Increase)
INCRBY key increment (INCRBY --> Increase by)
DECR key (DECR --> decrease)
DECRBY key decrement (DECRBY --> Decrease by)
GETRANGE key start end
SETRANGE key offset value
SETEX key seconds value
SETNX key value
MGET key [key ... ] (M --> Multiply)
MSET key value [key value ... ]
MSETNX key value [key value ... ]
# e1
127.0.0.1:6379[2]> set heros slark
OK
127.0.0.1:6379[2]> append heros luna
(integer) 9
127.0.0.1:6379[2]> strlen heros
(integer) 9
127.0.0.1:6379[2]> get heros
"slarkluna"
127.0.0.1:6379[2]> getrange heros 4 -1
"kluna"
127.0.0.1:6379[2]> setrange heros 5 sf
(integer) 9
127.0.0.1:6379[2]> get heros
"slarksfna"
127.0.0.1:6379[2]> setex heros 10 storm
OK
127.0.0.1:6379[2]> ttl heros
(integer) 1
127.0.0.1:6379[2]> ttl heros
(integer) -2
# e2
127.0.0.1:6379[2]> SETNX balance 300
(integer) 1
127.0.0.1:6379[2]> get balance
"300"
127.0.0.1:6379[2]> SETNX balance 200
(integer) 0
127.0.0.1:6379[2]> get balance
"300"
# e3
127.0.0.1:6379[2]> MSETNX name ronnie hometown shanghai university massey age 24 major chemistry
(integer) 1
127.0.0.1:6379[2]> MGET name hometown university age major
1) "ronnie"
2) "shanghai"
3) "massey"
4) "24"
5) "chemistry"
127.0.0.1:6379[2]> MSETNX name john hometown auckalnd university massey age 57 occupation professor
(integer) 0
127.0.0.1:6379[2]> MGET name hometown university age occupation
1) "ronnie"
2) "shanghai"
3) "massey"
4) "24"
5) (nil)
LPUSH key value [value ... ] (L --> Left)
RPUSH key value [value ... ] (R --> Right)
LRANGE key start stop (L --> List)
LPOP key
RPOP key
LINDEX key index (L --> List)
LLEN key (L --> Left LEN --> Length)
LREM key count value (L --> Left REM --> remove)
LTRIM key start stop (L --> Left)
RPOPLPUSH source destination (Right Pop Push)
命令 RPOPLPUSH 在一个原子时间内,执行以下两个动作:
将列表 source 中的最后一个元素(尾元素)弹出,并返回给客户端。
将 source 弹出的元素插入到列表 destination ,作为 destination 列表的的头元素。
LSET key index value
LINSERT key BEFORE|AFTER pivot value (Left Insert)
127.0.0.1:6379[2]> LPUSH heros slark luna spectre storm ember broodmother
(integer) 6
127.0.0.1:6379[2]> LRANGE heros 0 4
1) "broodmother"
2) "ember"
3) "storm"
4) "spectre"
5) "luna"
127.0.0.1:6379[2]> LRANGE heros 0 -1
1) "broodmother"
2) "ember"
3) "storm"
4) "spectre"
5) "luna"
6) "slark"
127.0.0.1:6379[2]> RPUSH heros2 viper anti_mage zeus meepo huskar
(integer) 5
127.0.0.1:6379[2]> LLEN heros
(integer) 6
127.0.0.1:6379[2]> RPOPLPUSH heros heros2
"slark"
127.0.0.1:6379[2]> LRANGE heros 0 -1
1) "broodmother"
2) "ember"
3) "storm"
4) "spectre"
5) "luna"
127.0.0.1:6379[2]> LRANGE heros2 0 -1
1) "slark"
2) "viper"
3) "anti_mage"
4) "zeus"
5) "meepo"
6) "huskar"
127.0.0.1:6379[2]> LSET heros 0 wtf
OK
127.0.0.1:6379[2]> LRANGE heros 0 -1
1) "wtf"
2) "ember"
3) "storm"
4) "spectre"
5) "luna"
127.0.0.1:6379[2]> LINSERT heros BEFORE wtf omg
(integer) 6
127.0.0.1:6379[2]> LRANGE heros 0 -1
1) "omg"
2) "wtf"
3) "ember"
4) "storm"
5) "spectre"
6) "luna"
SADD key member [member ... ]
SMEMBERS key
SISMEMEBER key member
SCARD key
SREM key member [member ... ]
SPOP key (随机抽奖)
SMOVE source destination member
SDIFF key [key ... ]
SINTER key [key ... ] (求交集)
SUNTION key [key ... ]
类似Sets,但是每个字符串元素都关联到一个叫score浮动数值。里面的元素总是通过score进行着排序, 有所不同的是, 它是可以检索一系列元素。Zset 是 key score1 value1 score2 value2。
ZADD key score member [[score member] ... ]
ZRANGE key start stop [WITHSCORES]
返回有序集?key?中,指定区间内的成员。
其中成员的位置按?score?值递增(从小到大)来排序。
具有相同?score?值的成员按字典序(lexicographical order?)来排列。
如果你需要成员按?score?值递减(从大到小)来排列,请使用?ZREVRANGE?命令。
ZREVRANGE key start stop [WITHSCORES] (REV --> reverse)
ZREM key member [member ... ]
ZREMRANGEBYSCORE key min max
ZSCORE key member
ZCARD key
ZCOUNT key min max
ZRANK key member
HSET key field value
HGET key field
HMSET key field value [field value ... ]
HMGET key field [field ...]
HGETALL key
HKEYS key
HVALS key
HSETNX key field value
HEXISTS key field
HDEL key field [field ... ]
HINCRBY key field increment
HINCRBTFLOAT key field increment
标签:通过 根据 进制 rpo 时间 模式 jpeg off str
原文地址:https://www.cnblogs.com/ronnieyuan/p/11674541.html