Ubuntu环境下的Redis 配置与C++使用入门
来源:互联网 发布:编程语言工资排行 编辑:程序博客网 时间:2024/05/17 23:57
Redis是一个高性能的key-value数据库。 Redisedis的出现,很大程度补偿了memcached这类key/value存储的不足,在部分场合可以对关系数据库起到很好的补充作用。它提供了Java,C/C++,C#,PHP,JavaScript,Perl,Object-C,Python,Ruby,Erlang等客户端,使用很方便。
本文将通过介绍Ubuntu环境下的Redis 配置,介绍C++入门使用的方式,帮助读者快速上手Redis。
安装配置
获取源码、解压、进入源码目录,编译
<code>$ wget http://download.redis.io/redis-stable.tar.gz$ tar xvzf redis-stable.tar.gz$ cd redis-stable$ make</code>
测试、安装
$ make test$ sudo make install
make命令执行完成后,会在 src 目录下生成本个可执行文件,分别是redis-server、redis-cli、redis-benchmark、redis-stat,它们的作用如下:
redis-server :Redis服务器的daemon启动程序
redis-cli :Redis命令行操作工具。当然,你也可以用telnet根据其纯文本协议来操作
redis-benchmark :Redis性能测试工具,测试Redis在你的系统及你的配置下的读写性能
redis-stat :Redis状态检测工具,可以检测Redis当前状态参数及延迟状况。
Run Redis with:
$ src/redis-server
You can interact with Redis using the built-in client:
$ src/redis-cliredis> set foo barOKredis> get foo"bar"
或者参见 http://redis.io/topics/quickstart
C++配置与入门使用
配置
on Ubuntu:
$ apt-get install libhiredis-dev
On OSX run:
$ brew install hiredis
on other platforms:
$ git clone https://github.com/antirez/hiredis.git && cd hiredis && make && sudo make install && sudo ldc
否则,由于缺少hiredis依赖关系,可能出现错误:
error: hiredis/hiredis.h: No such file or directory
入门使用
redisTest.cpp
#include <stdio.h>#include <hiredis/hiredis.h>int main(){ redisContext* conn = redisConnect("127.0.0.1",6379); if(conn->err){ printf("connection error:%s\n",conn->errstr); } redisReply* reply = (redisReply*)redisCommand(conn,"set foo 1234"); freeReplyObject(reply); reply = (redisReply*)redisCommand(conn,"get foo"); printf("%s\n",reply->str); freeReplyObject(reply); redisFree(conn); return 0;}
编译命令
g++ redisTest.cpp -o redisTest -I./deps/hiredis/ -L./deps/hiredis/ -lhiredis
进阶请看源码与测试用例: https://github.com/redis/hiredis
0 0
- Ubuntu环境下的Redis 配置与C++使用入门
- Ubuntu环境下的php-Redis 配置与php使用入门
- Ubuntu下LAMP环境的搭建,配置与使用教程
- 【Redis学习】:Windows环境下的Redis安装与配置
- 【Redis学习】:Linux环境下的Redis安装与配置
- Ubuntu环境下Redis的安装与JAVA连接测试
- Linux环境下Redis的安装与配置
- Linux环境下Redis的安装与配置
- Windows环境下的Redis安装与配置
- Linux环境下Redis的安装与配置
- Ubuntu下的samba配置与使用
- ubuntu 下编译环境的配置(java, c++)
- ubuntu下C/C++基本开发环境的配置
- ubuntu下c/c++开发环境配置
- ubuntu下c/c++开发环境配置
- ubuntu下c/c++开发环境配置
- ubuntu下c/c++开发环境配置
- ubuntu下c/c++开发环境配置
- C + +用户的杂志
- hdoj 3746
- iOS-生成Bundle包-引入bundle-使用bundle
- 正则表达式30分钟入门教程
- vim-snippets Ultisnips的写法
- Ubuntu环境下的Redis 配置与C++使用入门
- 316 算菜价
- 中国粒子对撞机曝光:迄今世界最大
- WA了一天还没解决的poj1442!
- weblogic文件下载不弹出窗口
- SQL Server快速生成SQL增删改查语句
- Linux安装express后,运行express指令一直提示找不到express
- 324 猴子吃桃问题
- 我竟然不知道span