Skip to content

Commit 11d7baf

Browse files
committed
redis apis
1 parent 96fd1c4 commit 11d7baf

5 files changed

Lines changed: 100 additions & 1 deletion

File tree

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,22 @@ docker-compose up
1616
- jpa
1717
- docker-compose
1818

19+
# java-redis
20+
21+
Java操作redis(单机)
22+
23+
- jdk11
24+
- springboot
25+
- redis
26+
- redission
27+
- docker compose
28+
1929
---
2030

2131
TODO List:
2232

2333
- Redis
24-
- ElasticSearch
34+
- ElasticSearch
2535
- MongoDB
2636
- Zookeeper
2737
- Kafka

java-redis/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Redis
22

33

4+
[doc](https://github.com/redisson/redisson/wiki/Table-of-Content)
5+
6+
47
Redis 是一种内存存储,具有一些持久性功能。您的所有数据集都应该适合内存。因此,单个实例受到服务器最大内存的限制。现在,可以将数据分片到多个Redis实例,在多个服务器上运行。如果有预算,完全有可能在一组 Redis 上存储 100GB - 1TB 的数据。请注意分片不是自动的:它必须由客户端或应用程序实现。对数据执行的操作施加一些限制(例如,无法在服务器端计算由不同 Redis 实例托管的两个集合的交集)。
58

69
单个Redis实例不是分布式系统。它是一个远程集中存储。现在通过使用多个 Redis 实例,可以构建一个分布式系统。因为它是一种自己动手的方法,所以您可以决定将其设为 CP 或 AP 系统。
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.cp.javaredis.model;
2+
3+
import java.io.Serializable;
4+
import java.time.LocalDateTime;
5+
import lombok.Data;
6+
7+
@Data
8+
public class Person implements Serializable {
9+
10+
private String name;
11+
12+
private Integer ages;
13+
14+
private LocalDateTime createTime;
15+
16+
public static Person tom() {
17+
Person person = new Person();
18+
person.setName("Tom");
19+
person.setAges(4);
20+
person.setCreateTime(LocalDateTime.now());
21+
return person;
22+
}
23+
24+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package org.cp.javaredis;
2+
3+
import java.util.concurrent.TimeUnit;
4+
import org.cp.javaredis.model.Person;
5+
import org.junit.jupiter.api.Test;
6+
import org.redisson.api.RBucket;
7+
import org.redisson.api.RList;
8+
import org.redisson.api.RedissonClient;
9+
import org.springframework.beans.factory.annotation.Autowired;
10+
import org.springframework.boot.test.context.SpringBootTest;
11+
12+
@SpringBootTest
13+
public class BasicApi {
14+
15+
@Autowired
16+
private RedissonClient redissonClient;
17+
18+
//String
19+
@Test
20+
public void testString() {
21+
RBucket<String> hello = redissonClient.getBucket("hello");
22+
System.out.println(hello.get());
23+
hello.set("world ! ", 5, TimeUnit.MINUTES);
24+
System.out.println(hello.get());
25+
}
26+
27+
// Object
28+
@Test
29+
public void testObject() {
30+
RBucket<Person> hello = redissonClient.getBucket("Tom");
31+
System.out.println(hello.get());
32+
hello.set(Person.tom(), 5, TimeUnit.MINUTES);
33+
System.out.println(hello.get());
34+
}
35+
36+
// List
37+
@Test
38+
public void testList() {
39+
RList<Person> list = redissonClient.getList("list");
40+
list.add(Person.tom());
41+
list.add(Person.tom());
42+
System.out.println(list.size());
43+
list.forEach(System.out::println);
44+
}
45+
46+
// Map
47+
48+
// Set
49+
50+
// ZSet
51+
52+
53+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
package org.cp.javaredis;
22

33
import org.junit.jupiter.api.Test;
4+
import org.redisson.api.RedissonClient;
5+
import org.springframework.beans.factory.annotation.Autowired;
46
import org.springframework.boot.test.context.SpringBootTest;
57

68
@SpringBootTest
79
class JavaRedisApplicationTests {
810

11+
@Autowired
12+
private RedissonClient redissonClient;
13+
914
@Test
1015
void contextLoads() {
16+
redissonClient.getBucket("hello").set("world");
17+
String test = (String) redissonClient.getBucket("hello").get();
18+
System.out.println(test);
19+
1120
}
1221

1322
}

0 commit comments

Comments
 (0)