Python分享之redis(2)

本文涉及的产品
云数据库 Tair(兼容Redis),内存型 2GB
Redis 开源版,标准版 2GB
推荐场景:
搭建游戏排行榜
简介: Python分享之redis(2)

Hash 操作


redis中的Hash 在内存中类似于一个name对应一个dic来存储


hset(name, key, value)


#name对应的hash中设置一个键值对(不存在,则创建,否则,修改)

r.hset("dic_name","a1","aa")


hget(name,key)


r.hset("dic_name","a1","aa")

#在name对应的hash中根据key获取value

print(r.hget("dic_name","a1"))#输出:aa


hgetall(name)


#获取name对应hash的所有键值

print(r.hgetall("dic_name"))


hmset(name, mapping)



#在name对应的hash中批量设置键值对,mapping:字典

dic={"a1":"aa","b1":"bb"}

r.hmset("dic_name",dic)

print(r.hget("dic_name","b1"))#输出:bb



hmget(name, keys, *args)


# 在name对应的hash中获取多个key的值

li=["a1","b1"]

print(r.hmget("dic_name",li))

print(r.hmget("dic_name","a1","b1"))


hlen(name)、hkeys(name)、hvals(name)


dic={"a1":"aa","b1":"bb"}

r.hmset("dic_name",dic)


#hlen(name) 获取hash中键值对的个数

print(r.hlen("dic_name"))


#hkeys(name) 获取hash中所有的key的值

print(r.hkeys("dic_name"))


#hvals(name) 获取hash中所有的value的值

print(r.hvals("dic_name"))


hexists(name, key)


#检查name对应的hash是否存在当前传入的key

print(r.hexists("dic_name","a1"))#输出:True


hdel(name,*keys)


#删除指定name对应的key所在的键值对

r.hdel("dic_name","a1")


hincrby(name, key, amount=1)


#自增hash中key对应的值,不存在则创建key=amount(amount为整数)

print(r.hincrby("demo","a",amount=2))


hincrbyfloat(name, key, amount=1.0)


#自增hash中key对应的值,不存在则创建key=amount(amount为浮点数)


hscan(name, cursor=0, match=None, count=None)


hscan_iter(name, match=None, count=None)

相关文章
|
4月前
|
数据采集 存储 NoSQL
分布式爬虫去重:Python + Redis实现高效URL去重
分布式爬虫去重:Python + Redis实现高效URL去重
|
NoSQL Unix 网络安全
【Azure Cache for Redis】Python Django-Redis连接Azure Redis服务遇上(104, 'Connection reset by peer')
【Azure Cache for Redis】Python Django-Redis连接Azure Redis服务遇上(104, 'Connection reset by peer')
136 0
【Azure Cache for Redis】Python Django-Redis连接Azure Redis服务遇上(104, 'Connection reset by peer')
|
12月前
|
NoSQL Linux Redis
linux安装单机版redis详细步骤,及python连接redis案例
这篇文章提供了在Linux系统中安装单机版Redis的详细步骤,并展示了如何配置Redis为systemctl启动,以及使用Python连接Redis进行数据操作的案例。
292 3
|
11月前
|
消息中间件 存储 NoSQL
python 使用redis实现支持优先级的消息队列详细说明和代码
python 使用redis实现支持优先级的消息队列详细说明和代码
178 0
|
缓存 NoSQL 网络安全
【Azure Redis 缓存】 Python连接Azure Redis, 使用redis.ConnectionPool 出现 "ConnectionResetError: [Errno 104] Connection reset by peer"
【Azure Redis 缓存】 Python连接Azure Redis, 使用redis.ConnectionPool 出现 "ConnectionResetError: [Errno 104] Connection reset by peer"
202 0
|
缓存 监控 NoSQL
【Azure Redis 缓存】使用Python代码获取Azure Redis的监控指标值 (含Powershell脚本方式)
【Azure Redis 缓存】使用Python代码获取Azure Redis的监控指标值 (含Powershell脚本方式)
|
NoSQL 网络安全 Redis
用python安装redis并设置服务自启
用python安装redis并设置服务自启
148 0
|
NoSQL Linux Redis
redis的python客户端redis-py初识
 转载请注明出处哈:http://carlosfu.iteye.com/blog/2240426    声明: 我是java程序员,对python不是很熟悉,只是写书的需要,要了解一下redis的python客户端,欢迎拍砖。
1509 0
|
4月前
|
缓存 NoSQL 关系型数据库
美团面试:MySQL有1000w数据,redis只存20w的数据,如何做 缓存 设计?
美团面试:MySQL有1000w数据,redis只存20w的数据,如何做 缓存 设计?
美团面试:MySQL有1000w数据,redis只存20w的数据,如何做 缓存 设计?
|
4月前
|
缓存 NoSQL Java
Redis+Caffeine构建高性能二级缓存
大家好,我是摘星。今天为大家带来的是Redis+Caffeine构建高性能二级缓存,废话不多说直接开始~
691 0

热门文章

最新文章

推荐镜像

更多