jedis

【Redis】系列1、——Redis基础

爱⌒轻易说出口 提交于 2019-12-10 02:43:23
你只管努力, ——剩下的交给时光。 首先我们带着问题来学习 1、什么是Redis?为什么要用它?用它有什么好处? Redis是一个开源的使用ANSI C语言编写、遵守BSD协议、支持网络、可基于内存亦 可持久化的日志型、Key-Value数据库 ,并提供多种语言的API。它通常被称为数据结构服务器,因为值(value)可以是 字符串(String), 哈希(Map), 列表(list), 集合(sets) 和 有序集合(sorted sets) 等类型。以上标红为Redis常用数据类型。 2、Redis的安装 安装教程 Windows安装 在 https://github.com/MSOpenTech/redis/releases 地址下载后解压,打开命令行进入解压目录运行 redis-server.exe redis.conf(省略则使用默认) 出现下图服务就已经启动成功了 Linux安装 在https://redis.io/地址下载最新版 解压:$ tar -xzf redis-4.0.11.tar.gz 进入解压后目录:$ cd redis-4.0.11 编译:$ make 进入src目录启动服务器:$ cd src $ ./redis-server 配置 Redis 的配置文件位于 Redis 安装目录下,文件名为 redis.conf。 可以通过 CONFIG

Does Redis only allow string representation but not numeric value

人走茶凉 提交于 2019-12-10 01:37:08
问题 I am getting mixed answers on my research here. Can someone verify that the Redis Server can only store representation of any numerical values? For instance, if I use a Java client (Jedis) with a double type in lpush, do I need to convert it to the equivalent of a string type before sending to Redis? Or is there a way to I can send over an actual numeric type like a double? If so, is there any example code on how to accomplish this? Thanks 回答1: Redis stores everything in string or in its

redis中缓存数据的格式

微笑、不失礼 提交于 2019-12-10 01:07:04
使用json格式 存储:java对象----》json字符串 获取:json字符串-----》java对象 添加依赖 < dependency > < groupId > com . alibaba < / groupId > < artifactId > fastjson < / artifactId > < version > 1.2 .47 < / version > < / dependency > 建立Course实体类 package com . wangpx . pojo ; import java . io . Serializable ; import java . util . Objects ; /** * com.wangpx.pojo * * @author wangpx * @date 2019-12-09 20:43 */ public class Coures implements Serializable { private Integer cid ; private String cname ; @Override public boolean equals ( Object o ) { if ( this == o ) return true ; if ( o == null || getClass ( ) != o . getClass (

使用jedis操作redis

拜拜、爱过 提交于 2019-12-09 22:19:24
依赖配置 < ? xml version = "1.0" encoding = "UTF-8" ? > < project xmlns = "http://maven.apache.org/POM/4.0.0" xmlns : xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi : schemaLocation = "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" > < modelVersion > 4.0 .0 < / modelVersion > < groupId > com . wangpx . redis < / groupId > < artifactId > redis < / artifactId > < version > 1.0 - SNAPSHOT < / version > < dependencies > < ! -- 配置redis的资源坐标 -- > < dependency > < groupId > redis . clients < / groupId > < artifactId > jedis < / artifactId > < version > 2.8 .2 < /

Redis常见问题及处理方法

时光总嘲笑我的痴心妄想 提交于 2019-12-09 21:25:31
一、Redis状态检查 唯一标记一个redis实例的是ip和端口,前端是用tcp方式来访问redis的,我们提供给应用访问的是一个ip+63379(一般使用63379) 端口。因此我们执行如下命令检查redis状态: 上面的role这个值一定是master的,只要保证vip在master上我们的Padis cache服务就是没有问题的,如果不通或者role的角色是slave,那就得继续查看是什么问题. 二、两个redis的角色都是slave的问题 当两个主机都挂了或者我们自己不小心将两个redis停了,并且我们用下面的命令检查 /wls/wls81/redis/bin/redis-cli -h {ip} -p {port} -a {password} info replication 发现无论是vip还是另外的两个ip都是role:slave 的角色,这个时候需要对vip所在的主机执行slaveof no one 的操作,将vip 所在的redis变成master,如: /wls/wls81/redis/bin/redis-cli -h {vip} -p {port} -a {password} slaveof no one 三、sentinel的配置参数 我们的sentinel 配置文件里面有两个重要的配置 sentinel monitor pds_jks-core-prd 10

SpringBoot入门-Redis(六)

徘徊边缘 提交于 2019-12-09 17:21:49
依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency> application.yml spring: redis:# 指的是默认操作redis数据库中的db1 database: 0 host: 127.0.0.1 port: 6379 password: 123456 timeout: 0 pool: max-active: 8 max-idle: 8 max-wait: -1 min-idle: 0 测试代码 package com.vast; import com.vast.dao.AccountRepository; import com.vast.dao.IAccountMybatisDao; import com.vast.entity.Account; import org.junit.Test; import org.junit.runner.RunWith; import org.mybatis.spring.annotation.MapperScan; import org.springframework.beans.factory.annotation

Can redis pipeline multiple commands that depend on previous ones?

回眸只為那壹抹淺笑 提交于 2019-12-09 16:45:29
问题 I'm very very new to redis and still playing around with it. I want to test to see if its relevant to my project but I'm not sure about a specific command I'm running. The users on SO have got me convinced of the performance benefits of using pipelines and transactions so I thought I'd ask how to do this. Basically I have two statements that I just want to issue and not have to wait for the result(seems like a good candidate for pipe lining. It looks like this: Does valueX exist? If it does

使用 try-with-resources 优雅关闭资源

限于喜欢 提交于 2019-12-09 14:22:11
我们知道,在 Java 编程过程中,如果打开了外部资源(文件、数据库连接、网络连接等、redis),我们必须在这些外部资源使用完毕后,手动关闭它们。 因为外部资源不由 JVM 管理,无法享用 JVM 的垃圾回收机制,如果我们不在编程时确保在正确的时机关闭外部资源,就会导致外部资源泄露,紧接着就会出现文件被异常占用,数据库连接过多导致连接池溢出**等诸多很严重的问题。 JDK7 之前的资源关闭方式 /** * jdk7以前关闭流的方式 * */ public class CloseResourceBefore7 { private static final String FileName = "file.txt"; public static void main(String[] args) throws IOException { FileInputStream inputStream = null; try { inputStream = new FileInputStream(FileName); char c1 = (char) inputStream.read(); System.out.println("c1=" + c1); } catch (IOException e) { e.printStackTrace(); } finally { if

案例:Redis在唯品会的大规模应用

谁说胖子不能爱 提交于 2019-12-09 14:06:19
导读 目前在唯品会主要负责redis/hbase的运维和开发支持工作,也参与工具开发工作,本文是在Redis中国用户组给大家分享redis cluster的生产实践。 分享大纲 本次分享内容如下: 1、生产应用场景 2、存储架构演变 3、应用最佳实践 4、运维经验总结 关于这4部分的内容介绍: 第1、2部分:介绍redis cluster在唯品会的生产应用场景,以及存储架构的演变。 第3部分:redis cluster的稳定性,应用成熟度,踩到过那些坑,如何解决这些问题?这部分是大家比较关系的内容。 第4部分:简单介绍大规模运营的一些经验,包括部署、监控、管理以及redis工具开发。 生产应用场景 业务范围 redis cluster在唯品会主要应用于后端业务,用作内存存储服务。主要大数据实时推荐/ETL、风控、营销三大业使用。 cluster用于取代当前twemproxy三层架构,作为通用的存储架构。redis cluster可以大幅度简化我们的存储架构,也解决twemproxy架构无法在线扩容节点的问题。 目前我们在线有生产几十个cluster集群,约2千个instances,单个集群最大达到250+instances。 这是我们的生产应用场景,主要是后端业务的存储,目前没有作为cache使用的场景。 大数据、风控、营销系统的特征 cluster 一般数据量大,

How to create RedisCacheManager in spring-data 2.0.x

人走茶凉 提交于 2019-12-09 13:09:33
问题 I'm migrating my application from spring boot 1.5.x to 2.0.x. I want to keep jedis but I have a problem with the instantiation of RedisCacheManager . Now constructor signature is RedisCacheManager(RedisCacheWriter cacheWriter, RedisCacheConfiguration defaultCacheConfiguration) But before it was: RedisCacheManager(RedisOperations redisOperations) I define this bean having only RedisTemplate in scope: @Bean public RedisCacheManager redisCacheManager(RedisTemplate redisTemplate) {