Fail to delete keys with bulk operation

201 views
Skip to first unread message

Denny Triana

unread,
Oct 24, 2012, 6:08:02 AM10/24/12
to redi...@googlegroups.com
So, when I ran this command:

goku@staging:/$ redis-cli -h localhost -p 6380 -n 3 keys *ads_731943*

it give this this output:

1. user_ads_731943_list_1
2. user_ads_731943_list_2

then I did a bulk operation to delete those keys with this command:

goku@staging:/$ redis-cli -h localhost -p 6380 -n 3 keys *ads_731943* | xargs redis-cli -h localhost -p 6380 -n 3 del

But, instead of deleting those 2 keys, i got this as a return:

(integer) 1    --> so, it's only delete 1 key

Then I check again there's still one key exist:

goku@staging:/$ redis-cli -h localhost -p 6380 -n 3 keys *ads_731943*
1. user_ads_731943_list_1

And for the second time i try to delete the key by mentioning it:

goku@staging:/$ redis-cli -h localhost -p 6380 -n 3 del user_ads_731943_list_1
(integer) 1

this last command succeeded to delete the key.

This behaviour were randomly occur in my redis-server, and still I don't have any idea what's wrong with my redis-server.
There's no persistence in my redis-server (8GB RAM), because all "save" lines were commented in configuration.
Can anyone please give me some explanation for this.

Redis server info :
redis_version:2.4.17
redis_git_sha1:00000000
redis_git_dirty:0
arch_bits:64
multiplexing_api:epoll
gcc_version:4.4.3
process_id:16335
run_id:3a69a105b49c35486f290f46ff683394d0c71f92
uptime_in_seconds:1619343
uptime_in_days:18
lru_clock:889562
used_cpu_sys:61456.01
used_cpu_user:35194.92
used_cpu_sys_children:0.00
used_cpu_user_children:0.00
connected_clients:33
connected_slaves:0
client_longest_output_list:0
client_biggest_input_buf:0
blocked_clients:0
used_memory:6442434776
used_memory_human:6.00G
used_memory_rss:7122444288
used_memory_peak:6475945496
used_memory_peak_human:6.03G
mem_fragmentation_ratio:1.11
mem_allocator:jemalloc-3.0.0
loading:0
aof_enabled:0
changes_since_last_save:432405357
bgsave_in_progress:0
last_save_time:1349453561
bgrewriteaof_in_progress:0
total_connections_received:413056034
total_commands_processed:1948540740
expired_keys:88729546
evicted_keys:2238634
keyspace_hits:498594280
keyspace_misses:351946662
pubsub_channels:0
pubsub_patterns:0
latest_fork_usec:0
vm_enabled:0
role:master
db0:keys=694894,expires=326692
db3:keys=2079158,expires=419557

regards,
DT

Denny Triana

unread,
Oct 31, 2012, 10:34:24 AM10/31/12
to redi...@googlegroups.com
anyone?
I've googled it...it lead me no where

Regards,
DT
--


Best Regards,

Denny Triana $ deni45



"I would love to change the world, but they won't give me the source code." - Unknown.

Andrea Campi

unread,
Oct 31, 2012, 10:45:31 AM10/31/12
to redi...@googlegroups.com


On Wed, Oct 31, 2012 at 3:34 PM, Denny Triana <dny....@gmail.com> wrote:
anyone?
I've googled it...it lead me no where

I seriously doubt Redis is doing anything wrong here, so make sure your commands are actually doing what you think.

When creating "tricky" pipes with xargs, I use find it useful to stick a call to echo in there, e.g.


redis-cli -h localhost -p 6380 -n 3 keys *ads_731943* | xargs echo redis-cli -h localhost -p 6380 -n 3 del


That should point you in the right direction.

Denny Triana

unread,
Nov 1, 2012, 12:26:19 AM11/1/12
to redi...@googlegroups.com
Hi Andrea,
thanks for the respond, here what I've got when executing: redis-cli -h localhost -p 6380 -n 3 keys *731943* | xargs echo redis-cli -h localhost -p 6380 -n 3 del

redis-cli -h localhost -p 6380 -n 3 del 1. profile_17319432. comment_117319433. comment_107319434. ads_731943_list_15. ads_731943_list_26. ads_731943_list_37. ads_731943_list_48. ads_731943_list_5

And still, it doesn't delete all the keys, after the command executed, the keys still exists.

regards,
DT

--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To post to this group, send email to redi...@googlegroups.com.
To unsubscribe from this group, send email to redis-db+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/redis-db?hl=en.

Didier Spezia

unread,
Nov 1, 2012, 3:35:10 AM11/1/12
to redi...@googlegroups.com

Hi,

I would say it is a wrong idea to put space characters in your keys.
It makes this kind of commands tricky.

xargs parse its input using the space as a separator. If you need to deal
with keys containing spaces, be sure to change the default separator:

Let's put some data in Redis.
Note the space character.

> ./redis-cli
redis 127.0.0.1:6379> set "1. profile_1731943" toto
OK
redis 127.0.0.1:6379> set "2. comment_11731943" titi
OK
redis 127.0.0.1:6379> set "3. comment_10731943" tutu
OK
redis 127.0.0.1:6379> keys *731943*
1) "3. comment_10731943"
2) "2. comment_11731943"
3) "1. profile_1731943"

Now let's try to run xargs in a naive way:

> ./redis-cli keys '*731943*' | xargs ./redis-cli mget
1) (nil)
2) (nil)
3) (nil)
4) (nil)
5) (nil)
6) (nil)

6 nil are returned because the spaces make xargs think there are 6 parameters instead of 3.
Now, let's change the delimiter:

> ./redis-cli keys '*731943*' | xargs -d'\n' ./redis-cli mget
1) "tutu"
2) "titi"
3) "toto"

Now it works fine.

Regards,
Didier.

Reply all
Reply to author
Forward
0 new messages