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的更多相关文章

  1. 后端程序员之路 55、go redis

    redigo有点像hiredis,只提供了最基本的连接和执行命令接口. 找到个不错的redis库: https://github.com/go-redis/redis func ExampleNewC ...

  2. 后端程序员之路 46、Redis Sentinel

    Sentinel - Redis 命令参考http://doc.redisfans.com/topic/sentinel.html#sentinel-api Guidelines for Redis ...

  3. 后端程序员之路 44、Redis结合protobuf

    protobuf序列化速度不错,在往Redis里存对象时,用protobuf序列化可以节省内存,省去写序列化反序列化代码的工作. google protocol buffer 与 redis 结合使用 ...

  4. 后端程序员之路 25、Redis Cluster

    官方教程和功能介绍: REDIS cluster-tutorial -- Redis中文资料站 -- Redis中国用户组(CRUG)http://www.redis.cn/topics/cluste ...

  5. 后端程序员之路 24、Redis hiredis

    Redishttps://redis.io/ Redis快速入门 - Redis教程http://www.yiibai.com/redis/redis_quick_guide.html wget ht ...

  6. 后端程序员之路 59、go uiprogress

    gosuri/uiprogress: A go library to render progress bars in terminal applicationshttps://github.com/g ...

  7. 后端程序员之路 49、SSDB

    正如Redis似乎是为替换memcached一样,SSSB是一个国人开发的旨在替换Redis的kv数据库. SSDB - 高性能的支持丰富数据结构的 NoSQL 数据库, 替代 Redishttp:/ ...

  8. 后端程序员之路 48、memcached

    memcached - a distributed memory object caching systemhttp://memcached.org/ Memcached 教程 | 菜鸟教程http: ...

  9. 后端程序员之路 27、LogStash

    访谈与书评:<LogStash,使日志管理更简单>http://www.infoq.com/cn/articles/review-the-logstash-book/ [Logstash] ...

随机推荐

  1. Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2) E. Let Them Slide(数据结构+差分)

     题意:问你有n个长度总和为n的数组 你可以移动数组 但不能移出长度为w的矩形框 问你每一列的最大值是多少? 思路:只有一次询问 我们可以考虑差分来解决 然后对于每一行数组 我们可以用数据结构维护一下 ...

  2. 使用 Nginx 在 Linux 上托管 ASP.NET Core

    server { listen 80; server_name example.com *.example.com; location / { proxy_pass http://localhost: ...

  3. woj1002-Genesis woj1003-birthofnoah woj1004-noah's ark

    title: woj1002-Genesis date: 2020-03-05 categories: acm tags: [acm,woj] 输入输出考虑一下.easy #include <i ...

  4. 白日梦的ES笔记三:万字长文 Elasticsearch基础概念统一扫盲

    目录 一.导读 二.彩蛋福利:账号借用 三.ES的Index.Shard及扩容机制 四.ES支持的核心数据类型 4.1.数字类型 4.2.日期类型 4.3.boolean类型 4.4.二进制类型 4. ...

  5. JxBrowser: 6.6.1 Crack

    JxBrowser: 6.6.1. 1. RELEASE NOTES Download:HomePage JxBrowser is a cross-platform library that prov ...

  6. PyCharm 中文 字符 python 报错 的 完美 解决方案!

    PyCharm 中文 字符 python 报错 的 完美 解决方案! #_*_ coding:utf-8_*_ https://www.python.org/dev/peps/pep-0263/ 到p ...

  7. React Suspense All In One

    React Suspense All In One 挂起让组件在渲染之前"等待"某些东西. 如今,Suspense仅支持一种用例:使用React.lazy动态加载组件. 将来,它将 ...

  8. Smashing Conf 2020

    Smashing Conf 2020 https://smashingconf.com/online-workshops/ events https://smashingconf.com/ny-202 ...

  9. Redux React & Online Video Tutorials

    Redux React & Online Video Tutorials https://scrimba.com/@xgqfrms https://scrimba.com/c/cEwvKNud ...

  10. pull down/pull up refresh & UI Components

    pull down/pull up refresh & UI Components 下拉/上拉刷新 https://mint-ui.github.io/docs/#/zh-cn2/loadmo ...