Skip to content

Commit

Permalink
Merge pull request #182 from JiazhenBao/main
Browse files Browse the repository at this point in the history
redis依赖库新增set集合操作
  • Loading branch information
JiazhenBao authored Jun 25, 2024
2 parents 889cbc1 + 19edbec commit c421e3a
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 12 deletions.
2 changes: 1 addition & 1 deletion httpclient/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<artifactId>httpclient</artifactId>
<name>httpclient</name>
<description>httpclient</description>
<version>0.14.0</version>
<version>0.14.1</version>

<dependencies>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion redis-template-tool/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.netease.lowcode</groupId>
<artifactId>redis-template-tool</artifactId>
<version>0.0.14</version>
<version>0.2.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,10 @@

import com.netease.lowcode.core.annotation.NaslLogic;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.data.redis.core.*;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.TimeUnit;


Expand All @@ -21,11 +15,77 @@ public class RedisTool {
@Autowired
public RedisTemplate<String, String> redisTemplate;

/**
* 设置 Redis 中指定 key 的过期时间
*
* @param key
* @param timeout
* @return
*/
@NaslLogic
public Boolean setExpire(String key, Long timeout) {
return redisTemplate.expire(key, timeout, TimeUnit.SECONDS);
}

/**
* 从集合中删除指定元素
*
* @param key
* @param value
* @return
*/
@NaslLogic
public Long removeFromSet(String key, String value) {
SetOperations<String, String> setOperations = redisTemplate.opsForSet();
return setOperations.remove(key, value);
}

/**
* 从集合中删除多个指定元素
*
* @param key
* @param values
* @return
*/
@NaslLogic
public Long removesFromSet(String key, List<String> values) {
SetOperations<String, String> setOperations = redisTemplate.opsForSet();
return setOperations.remove(key, values.toArray());
}

/**
* 向集合中添加元素
*
* @param key
* @param value
* @return
*/
@NaslLogic
public Long addToSet(String key, String value) {
SetOperations<String, String> setOperations = redisTemplate.opsForSet();
return setOperations.add(key, value);
}

/**
* 根据key获取集合中的所有元素
*
* @param key
* @return
*/
@NaslLogic
public List<String> getSetMembers(String key) {
SetOperations<String, String> setOperations = redisTemplate.opsForSet();
//set转list
return new ArrayList<>(Objects.requireNonNull(setOperations.members(key)));
}

/**
* 设置 Redis 中指定 key 的值为指定字符串
*
* @param key Redis 中的键
* @param value Redis 中的值
* @param key
* @param value
* @param timeout
* @return
*/
@NaslLogic
public String setValueTimeOut(String key, String value, Long timeout) {
Expand Down
Binary file not shown.

0 comments on commit c421e3a

Please sign in to comment.