redis常用命令
来源:互联网 发布:金山软件股票多少钱 编辑:程序博客网 时间:2024/06/05 23:00
一:散列
1>设置散列值
Hset key field value
Hset student name lishuai
2>获取散列值
Hget key field
Hget student name
3>field不存在进行插入,存在则不插入
HsetNx key field name
hsetnx student name lishuai
hsetnx student age 28
4>查看field是否存在
hexists key field
hexists student name
5>删除field
hdel key field
hdel student name
6>获取key的长度
hlen key
hlen student
7>设置多个field
hmset key field values field values field values ....
hmset student sex f address hebei
8>获取多个field
hmget key field field field
hmget student name age sex address
9>获取所有的field
hkeys key
hkeys student
10>获取所有的values
hvals key
hvals student
11>获取所有的fiels和values
hgetall key
hgetall student
12>fiel对应values自增整数
hincrby key field num
hincrby student age 1
13>fiel对应values自增浮点数
hincrbyfloat key field float
hincrbyfloat student age 0.5
二:列表
1>存入
lpush key values values values(值被推入的顺序和参数的顺序相反)
lpush names lishuai lishuai01 lishuai02 lishuai03(顺序是从左往右先存lishuai --》lishuai01--》lishuai02-->lihsuai03)
rpush key values values values(值被推入的顺序和参数的顺序相同)
rpush names lishuai04 lishuai05 lishuai06 (会存到lishuai下面,顺序是从右往左先存lishuai06--》lishuai05-->lishuai04)
2>查看元素
lrange names 0 10
3>弹出元素
lpop key
lpop names 弹出 lishuai03(弹出最上面的)
rpop key
rpop names 弹出kusgyau06(弹出最下面的)
4>获取元素数量
llen key
llen names
5>获取第几个元素
lindex key 0 (整数)
lindex name 0 ---》lishuai03
lindex key -1(负数)
lindex name -1 ---------->lishuai06
6>设定key的某个values
lset key index values
lset names o lishuainew
7>插入元素
linsert key before/after priot (不存在不执行任何操作) values 列表里面有多个priot已找到的第一个为准
insert names before lishuainew lishuainew01
8>移除元素
lrem key count value
count>0 从前向后找,移除count个值为values的元素
count<0 从后向前找,移除count个值为values的元素
count=0 移除全部
9>移除元素(按照先进先出原则移除)
ltrim key start stop
ltrim names 0 1 --》移除的是元素lishuai06
三:无序不重复集合(set)
1>添加元素
sdd key elements elements ...
sadd scores 100 101 102
2>查看元素
smembers key
smembers scores
srandmember key count
srandmember scores 2 (count为整数时,且count小于集合的长度,返回count个元素的数组,数组元素不重复,如果count大于集合的长度,返回整个集合。
如果count为负数,返回count的绝对值个元素,元素可能重复)
3>查看集合的长度
scard key
scard scores
4>查看元素是否存在
sismember key element
sismember scores 101
5>随机弹出元素
spop key
spop scores
6>删除某个元素
srem key element
srem scores 101
7>求集合的交集 并集 全集
求差集:返回的是第一个集合的差集
zadd scores1 101 102 103
sdiff key key 返回一个集合
sdiff scores scores1
sdiff deststore key key 返回一个集合存到deststore中
sdiff diffscore scores scores1
smembers diffscore
求交集:
sinter key key
sinter scores scores1
sinter deststore key key
sinter interscore scores scores1
smembers interstore
四:有序无重复集合(zset)
1>添加元素
zadd key score element score element ...
zadd fruits-price 1 xiangjiao 2 pingguo 3 hamigua
2>查看元素
zrange key start stop (正序排列,查看start开始到stop结束的元素)
zrange fruits-price 0 1
zrevrange key start stop (倒序)
zrevrange fruits-price 0 1
zrangebyscore key min max (正序查看score范围在min~~max之间的元素)
zrangebyscore fruits-price 0 10
zrevrangebyscore key max min (倒序查看score范围在max~~min 之间的元素)
zrevrangebyscore fruits-price 10 0
3>查看元素排名
zrank key element
zrank fruits-price hamigua
4>查看元素的score值
zscore key element
zscore fruits-price hamigua
5>查看元素的长度
zcard key
zcard fruits-price
6>元素scores增值
zincrby key increment element 对元素进行增值
zscore fruits-price xiangjiao
zincrby fruits-price 1 xiangjiao
zscore fruits-price xiangjiao
7>移除元素
zrem key element
zrem fruits-price xiangjiao
zremrangebyrank key start stop 按照元素排名移除start~~stop元素
zremrangebyrank fruits-price 0 1
zremrangebyscore key min max 移除指定分值范围内的元素
zremrangebyscore fruits-price 1 2
8>集合元素
zadd fruits-price2 1 xiangjiao 2 pingguo 3 hamigua
求交集:
zunionstore destkey numskey key key ... (numskey 是集合的个数,destkey 是返回的集合存储)
zunionstore zunionfruits 2 fruits-price fruits-price2
zrange zunionfruits 0 10 withscores
求并集
zinterstore desckey numskey key key
zinterstore interfruits 2 fruits-price fruits-price2
zrange interfruits 0 10 withscores
- Redis常用命令
- redis常用命令
- redis常用命令
- redis常用命令
- redis常用命令
- Redis常用命令
- Redis常用命令
- redis常用命令
- Redis常用命令
- Redis常用命令
- redis常用命令
- Redis常用命令
- redis 常用命令
- redis常用命令
- redis常用命令
- redis 常用命令
- Redis常用命令
- Redis 常用命令
- 放盘子
- HDU 1102 Constructing Roads (最小生成树)
- 第七周第一项目——成员函数
- 图像特效---Glow Filter发光滤镜
- Nova reboot 和 lock 操作 - 每天5分钟玩转 OpenStack(32)
- redis常用命令
- ViewPager和FragmentPagerAdapter
- Tomcat集群配置学习篇-----分布式应用
- UITabBar
- 图像特效---LOMO Filter
- JMXProxyBeat
- Eclipse的"Android sdk manager"中安装了指定版本的系统(或指定API版本),为什么在run as Android Applicantion中新建虚拟机时,target中找不到
- UVA 10859 Placing Lampposts(树形DP)
- 大搬家-2016"百度之星" - 测试赛(热身,陈题)