
进入Redis安装目录,执行./src/redis-server redis.conf,看到下面这个界面就启动成功了

用下面的地址下载redis压缩包,本地解压,然后在解压出的文件夹路径下执行redis-server redis.windows.conf命令
Redis

修改redis.config中 daemonize yes 来启动后台启动
执行 ./src/redis-cli shutdown 命令
String最大为512mb,建议单个最大kv不超过100kb

字符串命令:







package com.imooc.jedis;
import redis.clients.jedis.Jedis;
import java.util.List;
/**
* todo {类简要说明}
*
* @Author wangw
* @Date 2022/11/20 22:55
* @Version 1.0
*/
public class JedisTestor {
public static void main(String[] args) {
Jedis jedis = null;
try {
jedis = new Jedis("192.168.44.128", 6380);
jedis.auth("123456");
jedis.select(2);
System.out.println("redis链接成功");
jedis.set("sn", "77819538");
jedis.mset(new String[]{"title", "t", "num", "20"});
List<String> list = jedis.mget(new String[]{"sn", "title", "num"});
Long num = jedis.incr("num");
System.out.println(num);
for (String str : list
) {
System.out.println(str);
}
System.out.println(jedis.get("sn"));
// list
jedis.del("letter");
jedis.rpush("letter",new String[] {"d","e","f"});
jedis.lpush("letter","c","b","a");
List<String> letters = jedis.lrange("letter",0,-1);
System.out.println(letters);
jedis.lpop("letter");
letters = jedis.lrange("letter",0,-1);
System.out.println(letters);
} catch (Exception e) {
e.printStackTrace();
} finally {
jedis.close();
}
}
}
下面给出具体使用示例:
public class CacheSample {
public static void main(String[] args) {
new CacheSample();
System.out.println("请输入查询的商品编号");
String goodsId =new Scanner(System.in).next();
Jedis jedis =new Jedis("192.168.44.131",6380);
try {
jedis.auth("123456");
jedis.select(3);
String key ="goods:"+goodsId;
if (jedis.exists(key)){
String json = jedis.get(key);
System.out.println(json);
Goods goods =JSON.parseObject(json,Goods.class);
System.out.println(goods);
}else {
System.out.println("查询结果为空");
}
}catch (Exception e){
e.printStackTrace();
}finally {
jedis.close();
}
}
public CacheSample() {
Jedis jedis =new Jedis("192.168.44.131",6380);
try {
List<Goods> goodsList = new ArrayList<>();
goodsList.add(new Goods(1000, "apple", "yantai", 100f));
goodsList.add(new Goods(1001, "pear", "jinan", 200f));
goodsList.add(new Goods(1002, "watermelon", "tulufan", 300f));
jedis.auth("123456");
jedis.select(3);
for (Goods goods :goodsList) {
String json = JSON.toJSONString(goods);
System.out.println(json);
jedis.set("goods:"+goods.getGoodsId(),json);
}
}catch (Exception e) {
e.printStackTrace();
}finally {
jedis.close();
}
}
}