3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/daikon/namespace_tools.rb', line 3
def namespace_input(ns, command, *args)
command = command.to_s.downcase
case command
when "multi", "exec", "discard"
[ command ]
when "exists", "del", "type", "keys", "ttl", "set", "get", "getset",
"setnx", "incr", "incrby", "decr", "decrby", "rpush", "lpush",
"llen", "lrange", "ltrim", "lindex", "lset", "lrem", "lpop", "rpop",
"sadd", "srem", "spop", "scard", "sismember", "smembers", "srandmember",
"zadd", "zrem", "zincrby", "zrange", "zrevrange", "zrangebyscore",
"zcard", "zscore", "zremrangebyscore", "expire", "expireat", "hlen",
"hkeys", "hvals", "hgetall", "hset", "hget", "hincrby", "hexists",
"hdel", "hmset"
head = add_namespace(ns, args.first)
tail = args[1, args.length - 1] || []
[ command, head, *tail ]
when "smove"
result = [ command ]
args.each_with_index do |arg, i|
result << ((i == 0 || i == 1) ? add_namespace(ns, arg) : arg)
end
result
when "mget", "rpoplpush", "sinter", "sunion", "sdiff", "info",
"sinterstore", "sunionstore", "sdiffstore", "dbsize"
keys = add_namespace(ns, args)
[ command, *keys ]
when "mset", "msetnx"
hash1 = Hash[*args]
hash2 = {}
hash1.each do |k, v|
hash2[add_namespace(ns, k)] = hash1.delete(k)
end
[ command, hash2 ]
when "sort"
return [] if args.count == 0
key = add_namespace(ns, args.shift)
parms = {}
while keyword = args.shift.andand.downcase
case keyword
when "by", "get", "store"
k = keyword.intern
v = add_namespace(ns, args.shift)
parms[k] = v
when "limit"
parms[:limit] = [ args.shift.to_i, args.shift.to_i ]
when "asc", "desc", "alpha"
parms[:order].andand << " "
parms[:order] ||= ""
parms[:order] << keyword
end
end
[ command, key, parms ]
end
end
|