C语言操作Redis总结
#include "hiredis.h" #define NO_QFORKIMPL
#pragma comment(lib,"hiredis.lib")
#pragma comment(lib,"Win32_Interop.lib") int get_int_command(char int_command[])
{
reply = (redisReply *)redisCommand(c, int_command);
//printf("exists命令执行结果: %d\n", reply->type);
if (reply->type == ) //返回整型标识
{
//printf("%s命令执行结果: %d\n", int_command, reply->integer);
return reply->integer;
}
else if (reply->type == ) //返回nil对象
{
return -;
}
else if (reply->type == ) //返回错误
{
return -;
}
freeReplyObject(reply);
return ;
} char* get_string_command(char string_command[])
{
reply = (redisReply *)redisCommand(c, string_command);
//printf("lindex MA_h1_K 0命令执行结果 reply type: %d\n", reply->type);
if (reply->type == ) //返回字符串标识
{
//printf("lindex MA_h1_K 0命令执行结果 reply type: %s\n", reply->str);
return reply->str;
}
else if (reply->type == ) //返回nil对象
{
return "不存在要访问的数据";
}
else if (reply->type == ) //返回错误
{
return reply->str;
}
freeReplyObject(reply);
return "";
} void run_command(char run_command[])
{
reply = (redisReply *)redisCommand(c, run_command);
//printf("reply type: %d\n", reply->type);
if (reply->type == )
{
//printf("run_command执行结果: %s\n", reply->str);
}
freeReplyObject(reply);
} int main()
{
SYSTEMTIME sys;
char local_time[] = ""; c = redisConnect((char*)redis_host, redis_port);
if (c->err) { /* Error flags, 0 when there is no error */
printf("连接Redis失败: %s\n", c->errstr);
exit();
}
else
{
printf("连接Redis成功!\n");
} reply = (redisReply *)redisCommand(c, "AUTH %s", redis_password);
if (reply->type == REDIS_REPLY_ERROR) {
printf("Redis认证失败!\n");
}
else
{
printf("Redis认证成功!\n");
}
freeReplyObject(reply); reply = (redisReply *)redisCommand(c, "SELECT 1"); //选择数据库
printf("SELECT: 1 %s\n", reply->str);
freeReplyObject(reply); //delete命令
run_command("DEL foo"); //set命令
run_command("SET foo hello world"); //get命令
printf("GET foo命令执行结果 : %s\n", get_string_command("GET foo")); //exists命令
printf("exists test1命令执行结果: %d\n", get_int_command("exists test1"));
printf("exists MA_h1_K命令执行结果: %d\n", get_int_command("exists MA_h1_K")); //llen命令
printf("llen MA_h1_K命令执行结果: %d\n", get_int_command("llen MA_h1_K")); //lrange命令
reply = (redisReply *)redisCommand(c, "lrange MA_h1_K 0 7");
//printf("lrange MA_h1_K 0 7命令执行结果 reply type: %d\n", reply->type);
if (reply->type == )
{
printf("队列数量为: %d\n", reply->elements);
if (reply->element[]->type == )
{
for (int i = ; i < reply->elements; i++)
{
printf("lrange MA_h1_K 0 7命令执行结果: %s\n", reply->element[i]->str);
}
} }
freeReplyObject(reply); //lindex命令
printf("lindex MA_h1_K 0命令执行结果 : %s\n", get_string_command("lindex MA_h1_K 0")); //lpush命令
run_command("lpush list test1 test2 test3"); //lpop命令
printf("lpop list命令执行结果 : %s\n", get_string_command("lpop list")); //rpop命令
printf("rpop list命令执行结果 : %s\n", get_string_command("rpop list")); //rpoplpush命令
printf("rpoplpush list list1命令执行结果 : %s\n", get_string_command("rpoplpush list list1")); printf("lpop list1命令执行结果 : %s\n", get_string_command("lpop list1")); //lpush rpush lpop rpop RPOPLPUSH char test;
test = getchar();
}
C语言操作Redis总结的更多相关文章
- Go语言操作Redis
Go语言操作Redis Redis介绍 Redis是一个开源的内存数据库,Redis提供了多种不同类型的数据结构,很多业务场景下的问题都可以很自然地映射到这些数据结构上.除此之外,通过复制.持久化和客 ...
- GO学习-(24) Go语言操作Redis
Go语言操作Redis 在项目开发中redis的使用也比较频繁,本文介绍了Go语言中go-redis库的基本使用. Redis介绍 Redis是一个开源的内存数据库,Redis提供了多种不同类型的数据 ...
- Go语言基础之操作Redis
Go语言操作Redis 在项目开发中redis的使用也比较频繁,本文介绍了Go语言如何操作Redis. Redis介绍 Redis是一个开源的内存数据库,Redis提供了5种不同类型的数据结构,很多业 ...
- 【原创】自己动手写一个能操作redis的客户端
引言 redis大家在项目中经常会使用到.官网也提供了多语言的客户端供大家操作redis,如下图所示 但是,大家有思考过,这些语言操作redis背后的原理么?其实,某些大神会说 只要按照redis的协 ...
- go语言之行--golang操作redis、mysql大全
一.redis 简介 redis(REmote DIctionary Server)是一个由Salvatore Sanfilippo写key-value存储系统,它由C语言编写.遵守BSD协议.支持网 ...
- Go语言之进阶篇操作redis
1.windows安装redis 软件包下载地址: https://github.com/MicrosoftArchive/redis/releases 1.1.安装--->下一步---> ...
- Java Spring mvc 操作 Redis 及 Redis 集群
本文原创,转载请注明:http://www.cnblogs.com/fengzheng/p/5941953.html 关于 Redis 集群搭建可以参考我的另一篇文章 Redis集群搭建与简单使用 R ...
- Python操作Redis、Memcache、RabbitMQ、SQLAlchemy
Python操作 Redis.Memcache.RabbitMQ.SQLAlchemy redis介绍:redis是一个开源的,先进的KEY-VALUE存储,它通常被称为数据结构服务器,因为键可以包含 ...
- Python操作Redis及连接方式
前沿:随着互联网的高速发展,数据变得越来越重要,Python成为了人工智能的热门语言,而Nosql数据库已成为日常开发用品. 今天要写的是Python操作Redis Redis的安装我就不介绍了,你可 ...
随机推荐
- 高速Android开发系列通信篇之EventBus
概述及基本概念 **EventBus**是一个Android端优化的publish/subscribe消息总线,简化了应用程序内各组件间.组件与后台线程间的通信.比方请求网络,等网络返回时通过Hand ...
- Material Designer的低版本兼容实现(十四)—— CardView
今天说的又是一个5.0中才有的新控件——CardView(卡片视图).这个东东其实我们早就见过了,无论是微博还是人人客户端,它都有出现.通常我们都是通过自定义一个背景图片,然后通过给layout进行设 ...
- ab命令作apache压力测试
ab命令作apache压力测试 ./ab -c 100 -n 10000 http://127.0.0.1/index.php -c 100 即:每次并发100个 -n 10000 即: 共发送100 ...
- eclipse 创建聚合maven项目
本人不想花太多时间去排版,所以这里排版假设不好看,请多多包涵! 一直都在用maven,可是却基本没有自己创建过maven项目,今天也试着创建一个. 1.打开eclipse.然后new,other,然后 ...
- 【经验】STL的list vector在iterator迭代器的循环中 使用erase 造成的BUG
#include <iostream> #include <list> #include <vector> using namespace std; typedef ...
- 弹出层框架layer快速使用
layer官方及演示文档:layer官方及演示文档 1.将layer整个放入工程内. 2.文件内引入layer.js, <script type="text/javascript&qu ...
- mysql主从备份及原理分析
一.mysql主从备份(复制)的基本原理mysql支持单向.异步复制,复制过程中一个服务器充当主服务器,而一个或多个其它服务器充当从服务器.mysql复制基于主服务器在二进制日志中跟踪所有对数据库的更 ...
- 【大数据】Spark-Hadoop-架构对比
Spark-Hadoop-架构对比 spark executor - zyc920716的博客 - CSDN博客 董的博客 » Apache Spark探秘:多进程模型还是多线程模型? Apache ...
- fastText、TextCNN、TextRNN……这里有一套NLP文本分类深度学习方法库供你选择
https://mp.weixin.qq.com/s/_xILvfEMx3URcB-5C8vfTw 这个库的目的是探索用深度学习进行NLP文本分类的方法. 它具有文本分类的各种基准模型,还支持多标签分 ...
- MySql查询时间段的方法(转)
http://www.jb51.net/article/58668.htm 本文实例讲述了MySql查询时间段的方法.分享给大家供大家参考.具体方法如下: MySql查询时间段的方法未必人人都会,下面 ...