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的安装我就不介绍了,你可 ...
随机推荐
- java.io.IOException: Attempted read from closed stream解决
在HttpClient请求的时候,返回结果解析时出现java.io.IOException: Attempted read from closed stream. 异常,解决 原因是EntityUti ...
- 蓝精灵:寻找神秘村Smurfs: The Lost Village迅雷下载
蓝妹妹(黛米·洛瓦托 Demi Lovato 配音)发现了一张遗落的地图,由此引发精灵们对于神秘村庄真实性的猜想.于是,满怀好奇心的蓝妹妹与聪聪(丹尼·朴迪 Danny Pudi 配音).笨笨(杰克· ...
- ios成长之每日一遍(day 3)
今天要介绍一下更多的控键使用, 当然也会对上一篇说的控件做一个巩固, 所以这一篇涉及到的控键会包括 UIImage.UITextField.UIButton.UILabel.UISwitch.以及 U ...
- Makefile:160: recipe for target 'all' failed (Ubuntu 16.06 + Opencv3.2)解决办法
前言 之前一直用的opencv 好好的,今天安装了anaconda之后,python中的opencv不能用了,即便是拷贝cv2.so之后也是不能用,问题如下: 根本原因 安装anaconda之后,很多 ...
- Caffe常用层参数介绍
版权声明:本文为博主原创文章,转载请注明出处. https://blog.csdn.net/Cheese_pop/article/details/52024980 DATA crop:截取原图像中一个 ...
- Java Collection Framework : List
摘要: List 是 Java Collection Framework的重要成员,详细包括List接口及其全部的实现类.由于List接口继承了Collection接口,所以List拥有Collect ...
- Go语言之进阶篇TCP相互通信
1.TCP相互通信 服务端示例: tcp_server.go package main import ( "fmt" "net" ) func main() { ...
- easyui datagrid列使用按钮的一些心得 .
以前,用easyui的datagrid,有时候会用到一些操作选项,比如代码如下: $('#datagrid').datagrid({ border:false, fitColumns:true, si ...
- tensorflow 卷积/反卷积-池化/反池化操作详解
Plese see this answer for a detailed example of how tf.nn.conv2d_backprop_input and tf.nn.conv2d_bac ...
- 关于使用rem单位、css函数calc()进行自适应布局
一.关于css中的单位 大家都知道在css中的单位,一般都包括有px,%,em等单位,另外css3新增加一个单位rem. 其中px,%等单位平时在传统布局当中使用的比较频繁,大家也比较熟悉,不过px单 ...