ruby-redis 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +9 -0
- data/README +90 -0
- data/bin/ruby-redis +12 -0
- data/bin/ruby-redis.compiled.rbc +243 -0
- data/lib/redis/bin.rb +74 -0
- data/lib/redis/bin.rbc +1325 -0
- data/lib/redis/buftok.rbc +2658 -0
- data/lib/redis/config.rb +46 -0
- data/lib/redis/config.rbc +1009 -0
- data/lib/redis/connection.rb +69 -0
- data/lib/redis/connection.rbc +1354 -0
- data/lib/redis/database.rb +109 -0
- data/lib/redis/database.rbc +2275 -0
- data/lib/redis/hashes.rb +72 -0
- data/lib/redis/hashes.rbc +1843 -0
- data/lib/redis/hiredis.rbc +658 -0
- data/lib/redis/keys.rb +165 -0
- data/lib/redis/keys.rbc +3386 -0
- data/lib/redis/lists.rb +227 -0
- data/lib/redis/lists.rbc +5241 -0
- data/lib/redis/logger.rb +81 -0
- data/lib/redis/logger.rbc +2106 -0
- data/lib/redis/protocol.rb +170 -0
- data/lib/redis/protocol.rbc +3735 -0
- data/lib/redis/pubsub.rb +153 -0
- data/lib/redis/pubsub.rbc +3447 -0
- data/lib/redis/reader.rb +164 -0
- data/lib/redis/reader.rbc +2769 -0
- data/lib/redis/send.rbc +1268 -0
- data/lib/redis/sender.rb +49 -0
- data/lib/redis/sender.rbc +1057 -0
- data/lib/redis/server.rb +62 -0
- data/lib/redis/server.rbc +1177 -0
- data/lib/redis/sets.rb +105 -0
- data/lib/redis/sets.rbc +2800 -0
- data/lib/redis/strict.rb +67 -0
- data/lib/redis/strict.rbc +1419 -0
- data/lib/redis/strings.rb +144 -0
- data/lib/redis/strings.rbc +3338 -0
- data/lib/redis/synchrony.rb +58 -0
- data/lib/redis/synchrony.rbc +1397 -0
- data/lib/redis/version.rb +7 -0
- data/lib/redis/version.rbc +180 -0
- data/lib/redis/zsets.rb +281 -0
- data/lib/redis/zsets.rbc +6596 -0
- data/lib/redis.rb +215 -0
- data/lib/redis.rbc +4391 -0
- metadata +117 -0
data/lib/redis/hashes.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
require File.expand_path '../redis', File.dirname(__FILE__)
|
2
|
+
|
3
|
+
class Redis
|
4
|
+
module Hashes
|
5
|
+
|
6
|
+
def redis_HSET key, field, value
|
7
|
+
hash = @database[key] ||= {}
|
8
|
+
result = !hash.has_key?(field)
|
9
|
+
hash[field] = value
|
10
|
+
result
|
11
|
+
end
|
12
|
+
|
13
|
+
def redis_HEXISTS key, field
|
14
|
+
(@database[key] || {}).has_key? field
|
15
|
+
end
|
16
|
+
|
17
|
+
def redis_HSETNX key, field, value
|
18
|
+
hash = @database[key] || {}
|
19
|
+
return false if hash.has_key? field
|
20
|
+
redis_HSET key, field, value
|
21
|
+
return true
|
22
|
+
end
|
23
|
+
|
24
|
+
def redis_HKEYS key
|
25
|
+
(@database[key] || {}).keys
|
26
|
+
end
|
27
|
+
|
28
|
+
def redis_HVALS key
|
29
|
+
(@database[key] || {}).values
|
30
|
+
end
|
31
|
+
|
32
|
+
def redis_HMSET key, *args
|
33
|
+
(@database[key] ||= {}).merge! Hash[*args]
|
34
|
+
Response::OK
|
35
|
+
end
|
36
|
+
|
37
|
+
def redis_HMGET key, *fields
|
38
|
+
hash = (@database[key] || {})
|
39
|
+
redis_t Hash, hash
|
40
|
+
fields.collect do |field|
|
41
|
+
hash[field]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def redis_HLEN key
|
46
|
+
(@database[key] || {}).size
|
47
|
+
end
|
48
|
+
|
49
|
+
def redis_HGET key, field
|
50
|
+
(@database[key] || {})[field]
|
51
|
+
end
|
52
|
+
|
53
|
+
def redis_HGETALL key
|
54
|
+
@database[key] || {}
|
55
|
+
end
|
56
|
+
|
57
|
+
def redis_HDEL key, field
|
58
|
+
hash = @database[key] || {}
|
59
|
+
result = hash.has_key? field
|
60
|
+
hash.delete field
|
61
|
+
result
|
62
|
+
end
|
63
|
+
|
64
|
+
def redis_HINCRBY key, field, increment
|
65
|
+
hash = @database[key] ||= {}
|
66
|
+
value = redis_i(hash[field] ||= 0)
|
67
|
+
value += redis_i increment
|
68
|
+
hash[field] = value
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
end
|