ITKeyword,专注技术干货聚合推荐

注册 | 登录

redis:list数据类型与操作

shamohua 2011-11-24

相关推荐:JAVA之旅(十八)——基本数据类型的对象包装类,集合框架,数据结构,Collection,ArrayList,迭代器Iterator,List的使用

JAVA之旅(十八)——基本数据类型的对象包装类,集合框架,数据结构,Collection,ArrayList,迭代器Iterator,List的使用 JAVA把完事万物都定

redis数据类型之list:redis list数据类型是一个双向循环链表。redis.conf中的相关配置如下:428 # Similarly to hashes, small lists are also encoded in a special way in order429 # to save a lot of space. The special representation is only used when430 # you are under the following limits:431 list-max-ziplist-entries 512432 list-max-ziplist-value 64对于list的操作详见:http://redis.readthedocs.org/en/2.4/list.htmlredis c++接口的调用:#include "redisclient.h"#include "tests/functions.h"#include <iostream>#include <boost/date_time.hpp>#define OUT(x) std::cout<<#x<<" = "<<x<<std::endl;boost::shared_ptr<redis::client> init_non_cluster_client();void test_list(redis::client & c);int main(int argv, char* argc[]) { boost::shared_ptr<redis::client> shared_c; shared_c = init_non_cluster_client(); redis::client& c = *shared_c; test_list(c); return 0;}void test_list(redis::client & c){ test("test redis list type."); while(c.llen("list")>0) {

OUT(c.lpop("list")); } test("lpush & rpush & lpop & rpop & blpop & brpop"); {

OUT( c.lpush("list", "lpush1") );

OUT( c.lpush("list", "lpush2") );

OUT( c.rpush("list", "rpush1") );

OUT( c.rpush("list", "rpush2") );

OUT( c.llen("list") );

r

相关推荐:redis 数据类型

1. keys redis本质上一个key-value db,所以我们首先来看看他的key.首先key也是字符串类型,但是key中不能包括边界字符由于key不是binary safe的字

edis::client::string_vector out;

OUT( c.lrange("list", 0, 10, out) );

for(size_t i=0; i<out.size(); ++ i) {

OUT(out[i]);

}

OUT( c.lpop("list") );

OUT( c.rpop("list") );

OUT( c.llen("list") );

OUT( c.lpush("list", "lpush2") );

OUT( c.rpush("list", "rpush2") );

OUT( c.llen("list") );

OUT( c.blpop("list1", 1) );

OUT( c.blpop("list", 1) );

OUT( c.brpop("list1", 1) );

OUT( c.brpop("list", 1) );

OUT( c.llen("list") ); } test("llen & lrange & ltrim"); {

OUT( c.llen("list") );

redis::client::string_vector out;

OUT( c.lrange("list", 0, 10, out) );

for(size_t i=0; i<out.size(); ++ i) {

OUT(out[i]);

}

c.ltrim("list", 0, 2);

OUT( c.lrange("list", 0, 10, out) );

for(size_t i=0; i<out.size(); ++ i) {

OUT(out[i]);

}

OUT( c.llen("list") ); } test("lrem"); {

OUT( c.llen("list") );

OUT( c.lrem("list", 1, "lpush1") );

OUT( c.lrem("list", -1, "lpush2") );

OUT( c.llen("list") ); } test("lset & lindex"); {

OUT( c.lindex("list", 0) );

c.lset("list", 0, "set new value of index 0");

OUT( c.lindex("list", 0) ); }}

相关推荐:Redis客户端之Jedis(Key、String、Set、List、pub/sub、cluster、pool、pipleline)

原文链接:http://blog.csdn.net/xyang81/article/details/51918129环境: OS:CentOS7 64位 server版本:Redis 3.2.0 client 版本:Jedis 2.8.0

redis数据类型之list:redis list数据类型是一个双向循环链表。redis.conf中的相关配置如下:428 # Similarly to hashes, small lists are also encoded in a special way in order429 # to ...

相关阅读排行


用户评论

游客

相关内容推荐

最新文章

×

×

请激活账号

为了能正常使用评论、编辑功能及以后陆续为用户提供的其他产品,请激活账号。

您的注册邮箱: 修改

重新发送激活邮件 进入我的邮箱

如果您没有收到激活邮件,请注意检查垃圾箱。