在过去的几天里,我一直在玩redis(并添加一些乐趣),我想知道是否有办法清空数据库(删除集合,现有密钥......) .
在我的测试中,我创建了几个有很多成员的集合,甚至创建了我不记得名字的集合(我怎么能列出那些人呢?).
有关如何摆脱所有这些的想法吗?
我正在编写一个django管理命令来处理我们的一些redis缓存.基本上,我需要选择所有键,确认某种模式(例如:"prefix:*")并删除它们.
我知道我可以使用cli来做到这一点:
redis-cli KEYS "prefix:*" | xargs redis-cli DEL
Run Code Online (Sandbox Code Playgroud)
但我需要在应用程序中执行此操作.所以我需要使用python绑定(我使用的是py-redis).我已经尝试将列表输入到删除中,但它失败了:
from common.redis_client import get_redis_client
cache = get_redis_client()
x = cache.keys('prefix:*')
x == ['prefix:key1','prefix:key2'] # True
Run Code Online (Sandbox Code Playgroud)
# 现在
cache.delete(x)
Run Code Online (Sandbox Code Playgroud)
#返回0.没有删除
我知道我可以迭代x:
for key in x:
cache.delete(key)
Run Code Online (Sandbox Code Playgroud)
但这将失去redis的速度和滥用其功能.是否有py-redis的pythonic解决方案,没有迭代和/或cli?
谢谢!
我们有一个包含各种特殊字符的数十万个Redis密钥列表,我们希望批量删除它们.在这个问题上有类似问题的一些很好的答案:如何使用Redis原子地删除匹配模式的键
但是,我似乎无法找到以下案例的答案:
如果我们可以像下面这样做,我会很乐意,但是它会处理带有Redis问题的所有特殊字符的键:
redis-cli SMEMBERS "myGiganticListOfKeys" | xargs --delim='\n' redis-cli DEL
不幸的是,这只是给出了以下错误:
"C:/Program Files (x86)/Git/bin/xargs.exe": redis-cli: Bad file number
我认为如果我们在键中没有特殊字符,这将会起作用.
非常感谢提前.
如何使用redis-cli删除redis中与某个模式匹配的键.我想从以下列表中删除所有foo.
KEYS *
foo:1
foo:2
bar:1
foo:3
bar:2
foo:4
Run Code Online (Sandbox Code Playgroud) 我想使用Spring缓存@Cacheable来管理缓存.真正的缓存是redis.
我的代码是这样的:
@PostMapping("/post")
@CachePut(value = "abc", key = "#key")
public String putInRedis(@RequestParam String key, @RequestParam String value) {
saveInDB(key, value);
return value;
}
@GetMapping("/get")
@Cacheable(value = "abc", key = "#key")
public String queryRedis(@RequestParam String key) {
return findByKey(key);
}
Run Code Online (Sandbox Code Playgroud)
我有帖子请求之后
本地主机:8080 /后键=键和值=价值?
redis服务器看起来很奇怪
127.0.0.1:6379> keys *
1) "abc:\xac\xed\x00\x05t\x00\x03key"
127.0.0.1:6379> GET "abc:\xac\xed\x00\x05t\x00\x03key"
"\xac\xed\x00\x05t\x00\x05value"
Run Code Online (Sandbox Code Playgroud)
如何将@ Cacheable的Serializer设置为StringRedisTemplate默认值:
public StringRedisTemplate() {
RedisSerializer<String> stringSerializer = new StringRedisSerializer();
setKeySerializer(stringSerializer);
setValueSerializer(stringSerializer);
setHashKeySerializer(stringSerializer);
setHashValueSerializer(stringSerializer);
}
Run Code Online (Sandbox Code Playgroud)
我的application.properties:
spring.redis.host=localhost
spring.redis.password=
spring.redis.port=6379
Run Code Online (Sandbox Code Playgroud)
的build.gradle
group 'io.freezhan'
version '1.0-SNAPSHOT'
buildscript { …Run Code Online (Sandbox Code Playgroud) 通过使用phpredis,我在分页中保存了一些数据,如下所示:
review/itemA/1
review/itemA/2
Run Code Online (Sandbox Code Playgroud)
其中1和2是页码。我在文档中读到您可以使用通配符来检索多个键。
$allKeys = $redis->keys('*'); // all keys will match this.
$keyWithUserPrefix = $redis->keys('user*');
Run Code Online (Sandbox Code Playgroud)
但是,当有人发布新评论时,我是否也可以使用通配符删除所有旧密钥?我可以做这样的事情:
$redis->delete('review/itemA/*'); // or $redis->delete('review/itemA*')
Run Code Online (Sandbox Code Playgroud)
然而它并没有奏效。
我使用 Redis 哈希集以以下格式存储数据:
hset b1.b2.b3 name test
Run Code Online (Sandbox Code Playgroud)
现在我想删除这个键,所以我使用以下格式:
del b1.b2.*
Run Code Online (Sandbox Code Playgroud)
但它不起作用,那么我如何使用模式删除 Redis 键呢?
我已经在centos中安装了Redis,我有多个像这样的redis键,
Product:<id>:<url>
Run Code Online (Sandbox Code Playgroud)
如何Product:*:* 使用CLI 删除所有内容?
Redis版本:3.2.4 [最新我猜]
谢谢!
假设我有数百万个prefix:<numeric_id>密钥。
我想以原子方式清除它们。
如何使用 Redis 以原子方式删除与模式匹配的键显示了许多选项。有些使用redis-cli或 Bash 脚本,但我需要以编程方式使用我的客户端来完成。
Lua 脚本方法很有前途,但使用KEYS命令的解决方案失败并出现“太多元素无法解包”错误。
如何实现这一目标?