ruby-redis 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/LICENSE +9 -0
  2. data/README +90 -0
  3. data/bin/ruby-redis +12 -0
  4. data/bin/ruby-redis.compiled.rbc +243 -0
  5. data/lib/redis/bin.rb +74 -0
  6. data/lib/redis/bin.rbc +1325 -0
  7. data/lib/redis/buftok.rbc +2658 -0
  8. data/lib/redis/config.rb +46 -0
  9. data/lib/redis/config.rbc +1009 -0
  10. data/lib/redis/connection.rb +69 -0
  11. data/lib/redis/connection.rbc +1354 -0
  12. data/lib/redis/database.rb +109 -0
  13. data/lib/redis/database.rbc +2275 -0
  14. data/lib/redis/hashes.rb +72 -0
  15. data/lib/redis/hashes.rbc +1843 -0
  16. data/lib/redis/hiredis.rbc +658 -0
  17. data/lib/redis/keys.rb +165 -0
  18. data/lib/redis/keys.rbc +3386 -0
  19. data/lib/redis/lists.rb +227 -0
  20. data/lib/redis/lists.rbc +5241 -0
  21. data/lib/redis/logger.rb +81 -0
  22. data/lib/redis/logger.rbc +2106 -0
  23. data/lib/redis/protocol.rb +170 -0
  24. data/lib/redis/protocol.rbc +3735 -0
  25. data/lib/redis/pubsub.rb +153 -0
  26. data/lib/redis/pubsub.rbc +3447 -0
  27. data/lib/redis/reader.rb +164 -0
  28. data/lib/redis/reader.rbc +2769 -0
  29. data/lib/redis/send.rbc +1268 -0
  30. data/lib/redis/sender.rb +49 -0
  31. data/lib/redis/sender.rbc +1057 -0
  32. data/lib/redis/server.rb +62 -0
  33. data/lib/redis/server.rbc +1177 -0
  34. data/lib/redis/sets.rb +105 -0
  35. data/lib/redis/sets.rbc +2800 -0
  36. data/lib/redis/strict.rb +67 -0
  37. data/lib/redis/strict.rbc +1419 -0
  38. data/lib/redis/strings.rb +144 -0
  39. data/lib/redis/strings.rbc +3338 -0
  40. data/lib/redis/synchrony.rb +58 -0
  41. data/lib/redis/synchrony.rbc +1397 -0
  42. data/lib/redis/version.rb +7 -0
  43. data/lib/redis/version.rbc +180 -0
  44. data/lib/redis/zsets.rb +281 -0
  45. data/lib/redis/zsets.rbc +6596 -0
  46. data/lib/redis.rb +215 -0
  47. data/lib/redis.rbc +4391 -0
  48. metadata +117 -0
@@ -0,0 +1,144 @@
1
+ require File.expand_path '../redis', File.dirname(__FILE__)
2
+
3
+ class Redis
4
+
5
+ # Note: Redis does not have a dedicated integer type.
6
+ # Integer operations will convert values to integers.
7
+
8
+ module Strings
9
+
10
+ def redis_GET key
11
+ value = @database[key]
12
+ redis_t NilClass, String, Numeric, value
13
+ value
14
+ end
15
+
16
+ def redis_APPEND key, value
17
+ new_value = redis_GET(key).to_s + value
18
+ @database[key] = new_value
19
+ new_value.size
20
+ end
21
+
22
+ def redis_SETRANGE key, offset, value
23
+ data = (redis_GET(key)||'').to_s
24
+ return data.size if value.empty?
25
+ offset = redis_pos_i offset, 'out of range'
26
+ raise 'maximum allowed size' if offset + value.size > 512*1024*1024
27
+ if data.size <= offset
28
+ data.concat 0.chr * (offset - data.size + value.size)
29
+ end
30
+ data[offset,value.size] = value
31
+ @database[key] = data
32
+ data.size
33
+ end
34
+
35
+ def redis_GETRANGE key, first, last
36
+ first = redis_i first
37
+ last = redis_i last
38
+ value = redis_GET(key) || ''
39
+ first = 0 if first < -value.size
40
+ value[first..last]
41
+ end
42
+
43
+ def redis_GETBIT key, offset
44
+ data = redis_GET key
45
+ return 0 unless data
46
+ data = data.to_s
47
+ offset = redis_pos_i offset
48
+ byte = offset / 8
49
+ bit = 0x80 >> offset % 8
50
+ return 0 if data.size <= byte
51
+ original_byte = data[byte].ord
52
+ original_bit = original_byte & bit
53
+ original_bit != 0
54
+ end
55
+
56
+ def redis_SETBIT key, offset, value
57
+ data = (redis_GET(key)||'').to_s
58
+ offset = redis_pos_i offset, 'out of range'
59
+ raise 'out of range' if offset >= 4*1024*1024*1024
60
+ byte = offset / 8
61
+ bit = 0x80 >> offset % 8
62
+ if data.size <= byte
63
+ data += 0.chr * (byte - data.size + 1)
64
+ end
65
+ original_byte = data[byte].ord
66
+ original_bit = original_byte & bit
67
+ if value == '0'
68
+ data[byte] = (original_byte & ~bit).chr
69
+ elsif value == '1'
70
+ data[byte] = (original_byte | bit).chr
71
+ else
72
+ raise 'out of range'
73
+ end
74
+ @database[key] = data
75
+ original_bit != 0
76
+ end
77
+
78
+ def redis_STRLEN key
79
+ value = redis_GET key
80
+ value ? value.size : 0
81
+ end
82
+
83
+ def redis_MGET *keys
84
+ keys.collect do |key|
85
+ value = @database[key]
86
+ (String === value) ? value : nil
87
+ end
88
+ end
89
+
90
+ def redis_GETSET key, value
91
+ old = redis_GET key
92
+ @database[key] = value
93
+ old
94
+ end
95
+
96
+ def redis_SET key, value
97
+ @database[key] = value
98
+ Response::OK
99
+ end
100
+
101
+ def redis_SETEX key, seconds, value
102
+ @database[key] = value
103
+ @database.expire key, redis_pos_i(seconds, 'invalid expire time in SETEX')
104
+ Response::OK
105
+ end
106
+
107
+ def redis_MSET *args
108
+ Hash[*args].each do |key, value|
109
+ @database[key] = value
110
+ end
111
+ Response::OK
112
+ end
113
+
114
+ def redis_MSETNX *args
115
+ hash = Hash[*args]
116
+ hash.each do |key, value|
117
+ return false if @database.has_key? key
118
+ end
119
+ hash.each do |key, value|
120
+ @database[key] = value
121
+ end
122
+ true
123
+ end
124
+
125
+ def redis_SETNX key, value
126
+ return false if @database.has_key? key
127
+ @database[key] = value
128
+ true
129
+ end
130
+
131
+ def redis_INCR key
132
+ @database[key] = redis_i(@database[key] || 0) + 1
133
+ end
134
+
135
+ def redis_INCRBY key, value
136
+ @database[key] = redis_i(@database[key] || 0) + redis_i(value)
137
+ end
138
+
139
+ def redis_DECRBY key, value
140
+ @database[key] = redis_i(@database[key] || 0) - redis_i(value)
141
+ end
142
+
143
+ end
144
+ end