随笔 - 275  文章 - 0 评论 - 0 阅读 - 15万
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

1.string类型 : 图片和视频文件,静态文件

 

2.list 双向链表:回帖ID,我的关注列表,消息队列

length = redis.lpush('users:newest', 'user:goku')
if length > 100
  #trim is to we only keep 100 "newest" users
  redis.rpop('users:newest')
end

最新注册用户 $newest = [ 'goku', 'tom', ...];

# get the 10 newest users
keys = redis.lrange('users:newest', 0, 10)
#multi get the actual 10 user objects
redis.mget(*keys)

 

3.set无序集合,通过hash table实现,优点是快速查找元素是否存在 :

  a. 记录一些不能重复的记录,例如用户名

  b. 记录做过的事情,比如限制用户一天内投一票,用时间做key,用户ID做member,以时间key来查询用户ID是否在members里面来确认是否投票。

Sets are the kind of data structure you use to keep track of friends and tags:

SADD friends:leto ghanima
SADD friends:leto duncan
SADD friends:paul duncan
SADD friends:paul gurney
SINTER friends:leto friends:paul
1) "duncan"

 

4. sorted set 有序集合,用double类型的整数进行排序,由skipList(跳跃表)与Hash Table组合完成。

  a. 构建具有优先级的队列

  b. 排行榜排序,将排序的值设为score值

we could add a weight to our data:

ZADD friends:leto 1000 ghanima
ZADD friends:leto 994 duncan
ZADD friends:leto 2 farad'n
ZRANGEBYSCORE friends:leto 500 1000
1) "duncan"
2) "ghanima"

The above will get all of leto's friend with a score of 500-1000.

 

5. Hash类型,每个KEY对应一个Hash Table:适合用于存储对象,用户ID为KEY,用户数据为VALUE

HSET users:goku race sayan
HSET users:goku power 9001
$user = new stdObj;
$user->race = 40;
$user->power = 100;

 

参考:

http://www.iyunv.com/thread-52670-1-1.html

 REDIS处理

复制代码
session.save_handler = redis

//多节点
session.save_path = "tcp://ip:port?auth=secret?weight=1&timeout=2.5,tcp://ip2:port2?weight=2"

//单个节点
session.save_path = "tcp://ip:port?auth=secret?weight=1&timeout=2.5"

//socket 方式
session.save_path = "unix:///var/run/redis/redis.sock?persistent=1&weight=1&database=0
复制代码
复制代码
ip: Redis 节点的 IP。

port: Redis 节点的端口。

auth: 与 Redis 节点进行权限验证。

weight: 权重,上面的例子表示session数量,ip2节点 是 ip1节点的两倍。

timeout: Redis 连接超时时间。单位:秒。连接失败时,Session不可用(风险!)

persistent: 持久连接。

prefix: 前缀,默认是 "PHPREDIS_SESSION:"。

database: 选择哪个 Redis 数据库。取值:int。参见 Redis 配置 databases 16
复制代码

 

posted on   jzfan  阅读(227)  评论(0编辑  收藏  举报
(评论功能已被禁用)
编辑推荐:
· 软件产品开发中常见的10个问题及处理方法
· .NET 原生驾驭 AI 新基建实战系列:向量数据库的应用与畅想
· 从问题排查到源码分析:ActiveMQ消费端频繁日志刷屏的秘密
· 一次Java后端服务间歇性响应慢的问题排查记录
· dotnet 源代码生成器分析器入门
阅读排行:
· ThreeJs-16智慧城市项目(重磅以及未来发展ai)
· 软件产品开发中常见的10个问题及处理方法
· Vite CVE-2025-30208 安全漏洞
· 互联网不景气了那就玩玩嵌入式吧,用纯.NET开发并制作一个智能桌面机器人(四):结合BotSharp
· MQ 如何保证数据一致性?
点击右上角即可分享
微信分享提示