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的安装我就不介绍了,你可 ...
随机推荐
- Mac 安装zsh
1.安装zsh mac下自带zsh,但不是最新.查看zsh版本:zsh --version如果没有安装, 可以通过brew安装最新版,brew install zsh 2.安装oh-my-zsh cd ...
- linux dig命令 转
dig 命令主要用来从 DNS 域名服务器查询主机地址信息. 查询单个域名的 DNS 信息 dig 命令最典型的用法就是查询单个主机的信息. $ dig baidu.com dig 命令默认的输出信息 ...
- Ubuntu系统重启后/etc/resolv.conf内容丢失的解决方案
通过resolvconf实现配置 resolvconfig应用可以实现DNS信息管理,可以通过下面的应用来安装此组件: sudo apt-get install resolvconf 创建/etc/d ...
- 【ContestHunter】【弱省胡策】【Round7】
Prufer序列+高精度+组合数学/DP+可持久化线段树 Magic 利用Prufer序列,我们考虑序列中每个点是第几个插进去的,再考虑环的连接方式,我们有$$ans=\sum_{K=3}^n N^{ ...
- Shell变量while循环内改变无法传递到循环外
转自: https://blog.csdn.net/shawhe/article/details/65631543 今天刷Leecode(192 Word frequency)时,遇到一个shell语 ...
- go语言之进阶篇定时器停止
1.定时器停止 示例: package main import ( "fmt" "time" ) func main() { timer := time.New ...
- IIS7.5配置Gzip压缩解决方案(转)
开启配置HTTP压缩(GZip) 在IIS7中配置Gzip压缩相比IIS6来说实在容易了许多,而且默认情况下就是启用GZip压缩的.如果没有,则可以再功能视图下找到“压缩”项,进入之后就会看到“静态内 ...
- Error: MDM failed command. Status: Only a single SDC may be mapped to this volume at a time
映射一个volume到多个SDC的时候报错如下: Error: MDM failed command. Status: Only a single SDC may be mapped to this ...
- ASP.NET中Session的个人浅谈
看到博客园的一个哥们写的面试经历,想到了面试中常问到的Session,一时手痒就谈下自己对Session的理解,这东西最开始在用户登录登出的时候用到过,后来一直没怎么用过,里面还是有很多知识点值得注意 ...
- Elasticsearch 入门教程
全文搜索属于最常见的需求,开源的 Elasticsearch (以下简称 Elastic)是目前全文搜索引擎的首选. 它可以快速地储存.搜索和分析海量数据.维基百科.Stack Overflow.Gi ...