后端程序员之路 43、Redis list
Redis数据类型之LIST类型 - Web程序猿 - 博客频道 - CSDN.NET
http://blog.csdn.net/thinkercode/article/details/46565051
Redis的list是一个双向链表,应用场景很多,比如微博的关注列表,粉丝列表等都可以用Redis的list结构来实现;博客实现中,可为每篇日志设置一个list,在该list中推入进博客评论;也可以使用Redis list实现消息队列。
# list命令
- LPUSH/RPUSH
- LPUSH key value [value …]
- 头尾插入元素
- LPUSHX/RPUSHX
- LPUSHX key value
- 头尾插入元素,只在key对应一个list时生效
- LPOP/RPOP
- LPOP key
- 移除并返回头尾元素
- BLPOP/BRPOP
- BLPOP key [key …] timeout
- B(blocking),pop的阻塞版
- LINSERT
- LINSERT key BEFORE|AFTER pivot value
- 在某个值前后插
- LRANGE
- LRANGE key start stop
- 返回列表 key 中指定区间内的元素
- 以0表示列表的第一个元素
- -1表示最后一个元素,-2表示倒数第二个元素
- LREM
- LREM key count value
- 移除值为value的元素
- count>0 从前往后移除count个
- count<0 从后往前移除|count|个
- count=0 移除所有
- LTRIM
- LTRIM key start stop
- 只保留指定区间内的元素
- LINDEX/LSET
- LINDEX key index
- LSET key index value
- 读写指定下标的元素
- LLEN
- LLEN key
- 取列表长度
- 其它
- RPOPLPUSH
- BRPOPLPUSH
Redis 列表(List) | 菜鸟教程
http://www.runoob.com/redis/redis-lists.html
c++的调用实例:
int bl_redis_client::zrange(const std::string & key, const int start, const int stop, std::vector<std::string> & result)
{
if (_check_connection() != 0) {
return -1;
}
redisReply * reply = (redisReply *) redisCommand(_context, "ZRANGE %s %d %d", key.c_str(), start, stop);
if (reply == NULL) {
_re_connect(true);
} else if (reply->type != REDIS_REPLY_ARRAY) {
// not an arry
// LOG_DEBUG("ZRANGE: response is not an array");
} else {
for (size_t i = 0; i < reply->elements; i++) {
result.push_back(reply->element[i]->str);
}
}
if (reply != NULL) {
freeReplyObject(reply);
}
return 0;
}
后端程序员之路 43、Redis list的更多相关文章
- 后端程序员之路 55、go redis
redigo有点像hiredis,只提供了最基本的连接和执行命令接口. 找到个不错的redis库: https://github.com/go-redis/redis func ExampleNewC ...
- 后端程序员之路 46、Redis Sentinel
Sentinel - Redis 命令参考http://doc.redisfans.com/topic/sentinel.html#sentinel-api Guidelines for Redis ...
- 后端程序员之路 44、Redis结合protobuf
protobuf序列化速度不错,在往Redis里存对象时,用protobuf序列化可以节省内存,省去写序列化反序列化代码的工作. google protocol buffer 与 redis 结合使用 ...
- 后端程序员之路 25、Redis Cluster
官方教程和功能介绍: REDIS cluster-tutorial -- Redis中文资料站 -- Redis中国用户组(CRUG)http://www.redis.cn/topics/cluste ...
- 后端程序员之路 24、Redis hiredis
Redishttps://redis.io/ Redis快速入门 - Redis教程http://www.yiibai.com/redis/redis_quick_guide.html wget ht ...
- 后端程序员之路 59、go uiprogress
gosuri/uiprogress: A go library to render progress bars in terminal applicationshttps://github.com/g ...
- 后端程序员之路 49、SSDB
正如Redis似乎是为替换memcached一样,SSSB是一个国人开发的旨在替换Redis的kv数据库. SSDB - 高性能的支持丰富数据结构的 NoSQL 数据库, 替代 Redishttp:/ ...
- 后端程序员之路 48、memcached
memcached - a distributed memory object caching systemhttp://memcached.org/ Memcached 教程 | 菜鸟教程http: ...
- 后端程序员之路 27、LogStash
访谈与书评:<LogStash,使日志管理更简单>http://www.infoq.com/cn/articles/review-the-logstash-book/ [Logstash] ...
随机推荐
- 连接MongoDb数据库 -- Python
1.安装完mongoDb数据库后,如果需要我们的Python程序和MongoDb数据库进行交互,需要安装pymongo模块: 安装方式:采用pip install pymongo的方式 Microso ...
- GO - go mod使用原理
Go Module 依赖管理 go mod使用 原理及使用ref: https://xuanwo.io/2019/05/27/go-modules/ go module的稳定路径: https://l ...
- Atlas 分表功能
目录 分表原因 分表方式 Atlas 分表 分表思路 配置 Atlas 创建原表 创建分表 数据测试 分表原因 1.数据过多,访问缓慢 2.创建索引时重新排序,创建缓慢,并且占用大量的磁盘空间 分表方 ...
- 康托展开:对全排列的HASH和还原,判断搜索中的某个排列是否出现过
题目:http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=2297 前置技能:(千万注意是 ...
- Gym 101480I Ice Igloos(思维乱搞)题解
题意:给个最多500 * 500的平面,有半径最多不为1的n个圆,现在给你1e5条线段,问你每条线段和几个圆相交,时限10s 思路: 因为半径<1,那么我其实搜索的范围只要在线段附近就好了.x1 ...
- 如何使用 js 实现tooltips 的 hover 时候坐标的自动计算
如何使用 js 实现tooltips 的 hover 时候坐标的自动计算 js 监听 mouseover event https://developer.mozilla.org/zh-CN/docs/ ...
- 中文域名 & 原理剖析
中文域名 & 原理剖析 https://zh.wikipedia.org/wiki/中文域名 原理 利用浏览器的对字符编码的转换算法,实现 unicode 字符显示! 国际化域名: 就是一个普 ...
- Markdown & Static Site Generator
Markdown & Static Site Generator https://www.gitbook.com/ https://vuepress.vuejs.org/ https://ww ...
- vue watch & arrow function bug
vue watch & arrow function bug watch: { GeoJSON: function(newValue, oldValue) { log(`\n\n\nGeoJS ...
- 【PY从0到1】 一文掌握Pandas量化进阶
# 一文掌握Pandas量化进阶 # 这节课学习Pandas更深的内容. # 导入库: import numpy as np import pandas as pd # 制作DataFrame np. ...