linux测试模块redis,redis 入门(一)——Linux环境安装测试以及基本命令演示
redis概述
redis是一个开源的,先进的 key-value 存储可用于构建高性能的存储解决方案。它支持数据结构有字符串,哈希,列表,集合,带有范围查询的排序集,位图,超文本和具有半径查询的地理空间索引。 NoSQL,Not Only [SQL],泛指非关系型的数据库。所以redis是一种nosql。敲黑板画重点:redis是一种nosql.
redis的优点:
异常快速
支持丰富的数据类型
操作都是原子的
下载安装
$ wget http://download.redis.io/releases/redis-3.2.6.tar.gz
/root/redis tar xzf redis−3.2.6.tar.gz
/root/redis/redis-3.2.6 make
启动服务器:
``` $ src/redis-server
```
启动客户端
``` $ src/redis-cli
```
启动:
redis-server
redis-cli
11645:C 23 Apr 14:48:49.784 # Warning: no config file specified, using the default config. In order to specify a config file use src/redis-server /path/to/redis.conf
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 3.2.6 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | `-._ `._ / _.-' | PID: 11645
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | http://redis.io `-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-' `-.__.-'
11645:M 23 Apr 14:48:49.788 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
11645:M 23 Apr 14:48:49.788 # Server started, Redis version 3.2.6
11645:M 23 Apr 14:48:49.788 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
11645:M 23 Apr 14:48:49.788 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
11645:M 23 Apr 14:48:49.788 * DB loaded from disk: 0.000 seconds
11645:M 23 Apr 14:48:49.788 * The server is now ready to accept connections on port 6379
redis 支持的数据类型
启动客户端 ,存储字符串到redis.
127.0.0.1:6379> set name wonder
OK
取字符串:
127.0.0.1:6379> get name
"wonder"
哈希值
127.0.0.1:6379> hmset king username wonder password root age 22
OK
127.0.0.1:6379> hgetall king
1) "username"
2) "wonder"
3) "password"
4) "root"
5) "age"
6) "22"
Lists - 列表
127.0.0.1:6379> lpush pricess yiyue
(integer) 1
127.0.0.1:6379> lpush pricess chen
(integer) 2
127.0.0.1:6379> lpush privess yinli
(integer) 1
127.0.0.1:6379> lpush pricess yinli
(integer) 3
127.0.0.1:6379> lrange pricess 0 10
1) "yinli"
2) "chen"
3) "yiyue"
127.0.0.1:6379>
Redis 有序集合
Redis有序集合类似Redis集合存储在设定值唯一性。不同的是,一个有序集合的每个成员带有分数,用于以便采取有序set命令,从最小的到最大的分数有关。
127.0.0.1:6379> zadd kindom 1 redis
(integer) 1
127.0.0.1:6379> zadd kindom 2 mongodb
(integer) 1
127.0.0.1:6379> zadd kindom 3 mysql
(integer) 1
127.0.0.1:6379> zadd kindom 3 mysql
(integer) 0
127.0.0.1:6379> zadd kindom 4 mysql
(integer) 0
127.0.0.1:6379> zrange kindom 0 10 withscores
1) "redis"
2) "1"
3) "mongodb"
4) "2"
5) "mysql"
6) "4"
redis 发布订阅
开启客户端作为接受者
127.0.0.1:6379> subscribe myking messages
Reading messages... (press Ctrl-C to quit)
1) "subscribe"
2) "myking"
3) (integer) 1
1) "subscribe"
2) "messages"
3) (integer) 2
开启另一个客户端作为发送者:
127.0.0.1:6379> publish myking redis
(integer) 1
127.0.0.1:6379> publish myking "hello redis,you are a great caching technique"
(integer) 1
注意订阅端的变化:
Reading messages... (press Ctrl-C to quit)
1) "subscribe"
2) "myking"
3) (integer) 1
1) "subscribe"
2) "messages"
3) (integer) 2
1) "message"
2) "myking"
3) "redis"
1) "message"
2) "myking"
3) "hello redis,you are a great caching technique"
其他的一些操作
1.获取所以的key
KEYS *
127.0.0.1:6379> keys *
1) "kindom"
2) "name"
3) "privess"
4) "king"
5) "pricess"
2.判断key是否存在
EXISTS key
存在返回 1,不存在返回 0
127.0.0.1:6379> exists privess
(integer) 1
127.0.0.1:6379> exists privesssssss
(integer) 0
3.删除key
DEL key [key …]
127.0.0.1:6379> del privess
(integer) 1
127.0.0.1:6379> keys *
1) "kindom"
2) "name"
3) "king"
4) "pricess"
4.获取数据类型
TYPE key
127.0.0.1:6379> type kindom
zset
5.向尾部添加
APPEND key value
127.0.0.1:6379> append name qqq (integer) 9
127.0.0.1:6379> get name
"wonderqqq"
6.获取字符串长度
strlen key
127.0.0.1:6379> strlen name
(integer) 9
当然这里只是介绍简单的一些操作,复杂的参考官方文档。
在java应用中使用redis—jedis
前提是redis 已经安装,并且已经开启服务。
jedis 下载地址 https://github.com/xetorthio/jedis
Jedis is a blazingly small and sane Redis java client.
Jedis was conceived to be EASY to use.
翻译: jedis是一个非常小的java客户端,被认为是容易使用。
怎么使用?
import redis.clients.jedis.Jedis;
import java.util.List;
public class TestRedisClient {
public static void main(String[] args){
Jedis jedis = new Jedis("10.20.112.33");
System.out.println("Connection to server sucessfully");
//check whether server is running or not
System.out.println("Server is running: "+jedis.ping());
jedis.lpush("wonder-list", "Redis");
jedis.lpush("wonder-list", "Mongodb");
jedis.lpush("wonder-list", "Mysql");
// Get the stored data and print it
List list = jedis.lrange("wonder-list", 0 ,5);
for(int i=0; i
System.out.println("Stored string in redis:: "+list.get(i));
}
}
}
Connection to server sucessfully
Server is running: PONG
Stored string in redis:: Mysql
Stored string in redis:: Mongodb
Stored string in redis:: Redis
以上均为自己安装测试通过。
如果未开启服务,那么则会拒绝连接:
Exception in thread "main" redis.clients.jedis.exceptions.JedisConnectionException: java.net.ConnectException: Connection refused: connect
at redis.clients.jedis.Connection.connect(Connection.java:207)
at redis.clients.jedis.BinaryClient.connect(BinaryClient.java:93)
at redis.clients.jedis.Connection.sendCommand(Connection.java:126)
at redis.clients.jedis.Connection.sendCommand(Connection.java:121)
at redis.clients.jedis.BinaryClient.ping(BinaryClient.java:106)
at redis.clients.jedis.BinaryJedis.ping(BinaryJedis.java:195)
at TestRedisClient.main(TestRedisClient.java:11)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at redis.clients.jedis.Connection.connect(Connection.java:184)
... 6 more
其中遇到的问题有:
1.如何通过远程,Windows使用远程Linux上的redis服务。
1.注释掉你的redis.conf 的bind ip 的配置
我这里将原来的127.0.0.1注释掉
2.设置 protect-mode no
3.关闭redis服务:redis-server stop 或者使用 ctrl + c
4.启动: redis-server 你的redis.conf 目录
如 /user/redis/src/redis-server /user/redis/redis.conf
启动的时候,可以指定配置文件启动
成功连接。
linux测试模块redis,redis 入门(一)——Linux环境安装测试以及基本命令演示相关推荐
- Redis集群方案,Codis安装测试
Redis集群方案,Codis安装测试 1,关于豌豆荚开源的Codis Codis是豌豆荚使用Go和C语言开发.以代理的方式实现的一个Redis分布式集群解决方案,且完全兼容Twemproxy.Twe ...
- mqtt linux 编译,MQTT客户端代码X64位Ubuntu环境编译+测试实践小结
https://cloud.baidu.com/doc/IOT/IoTdownload.html#.E4.B8.8B.E8.BD.BDMQTT.E7.9B.B8.E5.85.B3 下载MQTT相关: ...
- linux下的c 编程入门教程,Linux下的C编程入门教程.ppt
<Linux下的C编程入门教程.ppt>由会员分享,可在线阅读,更多相关<Linux下的C编程入门教程.ppt(14页珍藏版)>请在装配图网上搜索. 1.Linux下c+编程, ...
- linux操作入门---配置px4环境/安装eclipse
笔者基本上在2016.06第一次实实在在接触linux,为的是linux下编译px4能更快些,然而摸索一段时间下在牛叔的帮助下仍然没有安装成功.时至至今终于独立下载配置好了px4,下载 ...
- node.js介绍及Win7环境安装测试(转)
官网描述: Node.js is a platform built on Chrome's JavaScript runtime for easily building fast, scalable ...
- ubuntu-10.04的测试环境 安装测试 Coreseek开源中文检索引擎-Sphinx中文版
主要参考文档:http://www.coreseek.cn/products-install/install_on_bsd_linux/ 一. 32位版本: coreseek安装需要预装的软件: ap ...
- Scala入门_开发环境安装
开发环境安装 学习如何编写scala代码之前,需要先安装scala编译器以及开发工具 Java程序编译执行流程 Scala程序编译执行流程 scala程序运行需要依赖于Java类库,必须要有Java运 ...
- 【Redis之轨迹】Redis基础入门(Linux IDEA)(配套工具类例子)
-- 目录 -- 0. Redis 简介 1. 安装 Redis 2. 基本命令 3. 五大数据类型 ① String 字符串 ② List 列表 ③ Set 集合 ④ Hash 散列表 ⑤ Zset ...
- linux创建启动连接数据库,DB2入门(1)--安装、启动、连接
1.安装数据库 windows下的安装 软件下载直接是从官网下载的, 下载免费试用版学习一下: 1. 进入官网,点击"Free DB2 trials" 2. 然后选择自己要下载的版 ...
最新文章
- SpringMVC常用Maven POM.xml依赖包片段
- Map json数据解析
- oracle取32位唯一码,Oracle导出导入dmp文件命令,以及excel生成32位uuid
- boost::multi_array模块测试 index_gen 的代码
- vue/return-in-computed-property Enforce that a return statement is present in computed property
- applet实现大文件ftp上传(三)
- Mysql-MVCC
- 查询oracle表空间有什么数据,oracle查询表空间使用情况与查询有哪些数据库实例在运行...
- 2019pythonqq机器人_基于Python来开发一个QQ机器人, 原来这么简单!
- 如何使用Mac DVDRipper Pro在mac上备份包括菜单和附加功能在内的完整的DVD
- 【鱼眼镜头7】如何利用鱼眼镜头测距
- python的分布式任务并行处理框架Jug简单使用
- 睡眠阶段分期——SVM和ELM分别与粒子群算法结合(main)
- 8086CPU 的寻址方式(重点)
- 中山大学非全日制计算机考研,中山大学社会工作非全日制考研经验贴
- 微软苏州集体抵制来自阿里、华为的跳槽者:请停止你的“奋斗逼”行为!
- js实现简易HTML动画-----手翻书版
- 4G5G相关缩略词中文及功能简述
- RxSwift 的简单使用
- 如何制定数据割接方案