当前位置:网站首页>Hash、Set、List、Zset、BitMap、Scan
Hash、Set、List、Zset、BitMap、Scan
2022-07-27 18:55:00 【Get lazy】
@SpringBootTest
class HashDemo {
@Autowired
private StringRedisTemplate stringRedisTemplate;
private final String key = "class#1";
@Test
public void test() {
stringRedisTemplate.opsForHash().put(key, "id", "12");
stringRedisTemplate.opsForHash().put(key, "name", "12");
stringRedisTemplate.opsForHash().put(key, "age", "12");
stringRedisTemplate.opsForHash().put(key, "address", "12");
Object name = stringRedisTemplate.opsForHash().get(key, "name");
System.out.println(name);
Map<Object, Object> entries = stringRedisTemplate.opsForHash().entries(key);
System.out.println(entries);
List<Object> hashsKey = new ArrayList<>();
hashsKey.add("id");
hashsKey.add("name");
List<Object> objects = stringRedisTemplate.opsForHash().multiGet(key, hashsKey);
System.out.println(objects);
}
}
@SpringBootTest
class ListDemo {
@Autowired
private StringRedisTemplate stringRedisTemplate;
private final String key1 = "class#206";
@Test
public void test() {
stringRedisTemplate.opsForList().leftPush(key1,"zhangsan");
stringRedisTemplate.opsForList().leftPush(key1,"lisi");
stringRedisTemplate.opsForList().leftPush(key1,"wangwu");
stringRedisTemplate.opsForList().set(key1,1,"11");
String password = stringRedisTemplate.opsForList().leftPop(key1);
System.out.println(password);
}
}
@SpringBootTest
class SetDemo {
@Autowired
private StringRedisTemplate stringRedisTemplate;
private final String key2 = "class#207";
private final String key3 = "class#208";
@Test
public void test() {
stringRedisTemplate.opsForSet().add(key2, "s");
stringRedisTemplate.opsForSet().add(key2, "a");
stringRedisTemplate.opsForSet().add(key3, "a");
stringRedisTemplate.opsForSet().add(key3, "d");
// Combine
Set<String> union = stringRedisTemplate.opsForSet().union(key2, key3);
System.out.println(union);
// Difference set
Set<String> difference = stringRedisTemplate.opsForSet().difference(key2, key3);
System.out.println(difference);
// intersection
Set<String> intersect = stringRedisTemplate.opsForSet().intersect(key2, key3);
System.out.println(intersect);
}
}
@SpringBootTest
class ZsetDemo {
@Autowired
private StringRedisTemplate stringRedisTemplate;
private final String kk = "class#209";
private final String key5 = "class#210";
@Test
public void test() {
stringRedisTemplate.opsForZSet().add(kk, " Chinese language and literature ", 99);
stringRedisTemplate.opsForZSet().add(kk, " English ", 80);
stringRedisTemplate.opsForZSet().add(kk, " mathematics ", 150);
stringRedisTemplate.opsForZSet().add(kk, " Politics ", 66);
System.out.println(" Find the maximum ");
ZSetOperations.TypedTuple<String> stringTypedTuple = stringRedisTemplate.opsForZSet().popMax(kk);
System.out.println(stringTypedTuple);
System.out.println(" Find the minimum ");
ZSetOperations.TypedTuple<String> stringTypedTuple1 = stringRedisTemplate.opsForZSet().popMin(kk);
System.out.println(stringTypedTuple1);
System.out.println(" Find the second ");
Set<ZSetOperations.TypedTuple<String>> typedTuples = stringRedisTemplate.opsForZSet().popMin(kk, 2);
System.out.println(typedTuples);
}
}
@SpringBootTest
public class BitMap {
@Resource (name="redisTemplate")
private ValueOperations valueOperations;
@Autowired
private StringRedisTemplate stringRedisTemplate;
private final Integer user1=1;
private final Integer user2=2;
private final Integer user3=3;
private final String key20220601="20220601";
private final String key20220602="20220602";
private final String key20220603="20220603";
private final String deskey="20220603-20220602";
@Test
public void test(){
valueOperations.setBit(key20220601,user1,true);
valueOperations.setBit(key20220601,user2,true);
valueOperations.setBit(key20220602,user2,true);
valueOperations.setBit(key20220603,user2,true);
valueOperations.setBit(key20220603,user3,true);
RedisCallback<Long> redisCallback=new RedisCallback<Long>() {
@Override
public Long doInRedis(RedisConnection connection) throws DataAccessException {
return connection.bitOp(RedisStringCommands.BitOperation.AND,deskey.getBytes(),key20220601.getBytes(), key20220602.getBytes(), key20220603.getBytes());
}
};
Long execute = stringRedisTemplate.execute(redisCallback);
System.out.println(execute);
}
}
@SpringBootTest
public class ScanTest {
@Autowired
private StringRedisTemplate stringRedisTemplate;
private final String key111="class#111";
@Test
public void test(){
for (int i=0;i<100;i++){
stringRedisTemplate.opsForValue().set("a"+i, "value"+i);
}
for (int i=0;i<100;i++){
stringRedisTemplate.opsForValue().set("b"+i, "value"+i);
}
ScanOptions scanOps = ScanOptions.scanOptions().match("b*").count(2).build();
Cursor<String> cursor = stringRedisTemplate.scan(scanOps);
while (cursor.hasNext()){
System.out.println(cursor.next());
}
// Close cursor
cursor.close();
}
}
边栏推荐
- Overview of Baidu map technology, and application development of basic API and webapi
- INSUFFICIENT_ ACCESS_ ON_ CROSS_ REFERENCE_ ENTITY APEX / SALESFORCE
- Jianmu continuous integration platform v2.5.2 release
- MySQL 06 事务、视图、索引、备份和恢复
- MySQL create event execution task
- Product name fuzzy search:
- Valueerror: found input variables with inconsistent numbers of samples: [80019456, 26673152] [error reporting]
- TypeScript安装
- C file and folder input / output stream code
- Led with fan eye protection learning table lamp touch chip-dlt8s12a
猜你喜欢

MySQL 04 advanced query (II)

What does the number of network request interface layers (2/3 layers) mean

Solve the problem of JSP cascading

Generate PDM file from Navicat export table

JDBC MySQL 01 JDBC operation MySQL (add, delete, modify and query)

MySQL 03 advanced query (I)

MySQL 01 关系型数据库设计

订单的提交

Build a simple knowledge question and answer system

百度地图鹰眼轨迹服务
随机推荐
JS to achieve smooth scrolling of pages or DOM elements
阿里p8总结的10条 SQL 优化方案(非常实用)
filebeat.yml配置文件关于多个服务的配置问题
ERROR 1366 (HY000): Incorrect string value: ‘\xE8\xB5\xB5\xE9\x9B\xB7‘ for column ‘s_ name‘ at row 1
飞机大战碰撞检测
USB充电式暖手宝芯片-DLTAP602SC-杰力科创
MySQL 03 高级查询(一)
Intelligent insomnia therapeutic instrument product dlt8p68sa Jericho
Zhaoqi scientific and technological innovation introduces high-level talents at home and abroad and connects innovation and entrepreneurship projects
瑞吉外卖sql表
Ant privacy computing innovation tee technology has won academic recognition
Valueerror: found input variables with inconsistent numbers of samples: [80019456, 26673152] [error reporting]
I'm stupid. When completable future is used with openfegin, it even reports an error
What should I do if MySQL master-slave replication data is inconsistent?
The song of the virtual idol was originally generated in this way!
MySQL set validate_ Adding skip grant tables after password=off failed to start the service
Nacos display service registration address error
迷你洗衣机触摸芯片-DLT8MA12TS-杰力科创
The hero of the aircraft war comes out with bullets
Canvas draws graphics according to coordinate points