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

注册 | 登录

redis:list数据类型与操作

shamohua 分享于 2011-11-24

推荐:redis基本数据类型分析,redis:string数据类型与操作,redis:set数据类型与操作

http://blog.csdn.net/shamohua/article/category/933347   redis:string数据类型与操作 redis的基本数据类型之一:string。 类型说明 定义:src/sds.h [cpp] 

redis数据类型之list:redis list数据类型是一个双向循环链表。redis.conf中的相关配置如下:

428 # Similarly to hashes, small lists are also encoded in a special way in order
429 # to save a lot of space. The special representation is only used when
430 # you are under the following limits:
431 list-max-ziplist-entries 512
432 list-max-ziplist-value 64

对于list的操作详见: http://redis.readthedocs.org/en/2.4/list.html

推荐:redis数据类型List的常用命令

redis的文档写的还是比较详细的,中文版: http://doc.redisfans.com/  英文版:http://redis.io/commands。这篇文章主要是自己亲自实践一下redis的基本操作,做个


redis 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") );

		redis::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数据类型及操作

本文由larrylgq编写,转载请注明出处:http://blog.csdn.net/larrylgq/article/details/7399769 作者:吕桂强 邮箱:larry.lv.word@gmail.com strings 类型 strin

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

相关阅读排行


用户评论

游客

相关内容推荐

最新文章

×

×

请激活账号

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

您的注册邮箱: 修改

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

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