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的安装我就不介绍了,你可 ...
随机推荐
- Unity3D——SendMessage方法的使用
SendMessage效率不高,因为每次调用的时候都会去遍历检测自身或者子节点上要调用的方法. 一.方法 GameObject自身的Script SendMessage("函数名" ...
- java去除数组中重复的元素方法总结
/* * ArrayUnique.java * Version 1.0.0 * Created on 2017年12月16日 * Copyright ReYo.Cn */ package reyo.s ...
- Quartz 2.3.0 升级感受
Quartz 2.3.0 发布,Quartz是一个开源的作业调度框架,它完全由Java写成,并设计用于J2SE和J2EE应用中.它提供了巨大的灵 活性而不牺牲简单性.你能够用它来为执行一个作业而创建简 ...
- script标签加载顺序(defer & async)
script 拥有的属性 async:可选,表示应该立即下载脚本,但不应妨碍页面中的其他操作,比如下载其他资源或等待加载其他脚本.只对外部脚本文件有效. charset:可选.表示通过 src 属性指 ...
- 疑犯追踪第五季/全集Person of Interest迅雷下载
英文全名Person of Interest,第5季(2015)CBS.本季看点:<疑犯追踪>本季剧组暗示Finch可能重建机器,这次他会给机器更多自由(如Root一直要求的那样).或许新 ...
- [转]在Windows中安装PhpUnit
FROM : http://www.cnblogs.com/heiing/archive/2012/09/07/2674807.html 步骤: 安装 pear ,参见http://www.cnblo ...
- Reloading Java Classes 301: Classloaders in Web Development — Tomcat, GlassFish, OSGi, Tapestry 5 and so on Translation
The Original link : http://zeroturnaround.com/rebellabs/rjc301/ Copyright reserved by Rebel Inc In t ...
- 样条之Akima光滑插值函数
核心代码: ////////////////////////////////////////////////////////////////////// // Akima光滑插值 // t - 存放指 ...
- [leetcode]Interleaving String @ Python
原题地址:https://oj.leetcode.com/problems/interleaving-string/ 题意: Given s1, s2, s3, find whether s3 is ...
- CSS-background-position百分比
关于背景图片的位置其background-position设置背景图片的位置有两种方式,一种是是根据像素设置,第二种根据百分比设置,第一种根据像素的位置是很简单的,只是关于百分比这个设置理解特别容易出 ...