redis-client 0.2.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +19 -0
  3. data/Gemfile +1 -2
  4. data/Gemfile.lock +2 -3
  5. data/README.md +71 -8
  6. data/Rakefile +43 -23
  7. data/lib/redis_client/command_builder.rb +91 -0
  8. data/lib/redis_client/config.rb +19 -50
  9. data/lib/redis_client/connection_mixin.rb +40 -0
  10. data/lib/redis_client/decorator.rb +84 -0
  11. data/lib/redis_client/pooled.rb +38 -30
  12. data/lib/redis_client/ruby_connection/buffered_io.rb +153 -0
  13. data/lib/redis_client/{resp3.rb → ruby_connection/resp3.rb} +0 -26
  14. data/lib/redis_client/{connection.rb → ruby_connection.rb} +26 -31
  15. data/lib/redis_client/version.rb +1 -1
  16. data/lib/redis_client.rb +183 -36
  17. data/redis-client.gemspec +2 -4
  18. metadata +12 -59
  19. data/.rubocop.yml +0 -190
  20. data/ext/redis_client/hiredis/export.clang +0 -2
  21. data/ext/redis_client/hiredis/export.gcc +0 -7
  22. data/ext/redis_client/hiredis/extconf.rb +0 -61
  23. data/ext/redis_client/hiredis/hiredis_connection.c +0 -708
  24. data/ext/redis_client/hiredis/vendor/.gitignore +0 -9
  25. data/ext/redis_client/hiredis/vendor/.travis.yml +0 -131
  26. data/ext/redis_client/hiredis/vendor/CHANGELOG.md +0 -364
  27. data/ext/redis_client/hiredis/vendor/CMakeLists.txt +0 -165
  28. data/ext/redis_client/hiredis/vendor/COPYING +0 -29
  29. data/ext/redis_client/hiredis/vendor/Makefile +0 -308
  30. data/ext/redis_client/hiredis/vendor/README.md +0 -664
  31. data/ext/redis_client/hiredis/vendor/adapters/ae.h +0 -130
  32. data/ext/redis_client/hiredis/vendor/adapters/glib.h +0 -156
  33. data/ext/redis_client/hiredis/vendor/adapters/ivykis.h +0 -84
  34. data/ext/redis_client/hiredis/vendor/adapters/libev.h +0 -179
  35. data/ext/redis_client/hiredis/vendor/adapters/libevent.h +0 -175
  36. data/ext/redis_client/hiredis/vendor/adapters/libuv.h +0 -117
  37. data/ext/redis_client/hiredis/vendor/adapters/macosx.h +0 -115
  38. data/ext/redis_client/hiredis/vendor/adapters/qt.h +0 -135
  39. data/ext/redis_client/hiredis/vendor/alloc.c +0 -86
  40. data/ext/redis_client/hiredis/vendor/alloc.h +0 -91
  41. data/ext/redis_client/hiredis/vendor/appveyor.yml +0 -24
  42. data/ext/redis_client/hiredis/vendor/async.c +0 -887
  43. data/ext/redis_client/hiredis/vendor/async.h +0 -147
  44. data/ext/redis_client/hiredis/vendor/async_private.h +0 -75
  45. data/ext/redis_client/hiredis/vendor/dict.c +0 -352
  46. data/ext/redis_client/hiredis/vendor/dict.h +0 -126
  47. data/ext/redis_client/hiredis/vendor/fmacros.h +0 -12
  48. data/ext/redis_client/hiredis/vendor/hiredis-config.cmake.in +0 -13
  49. data/ext/redis_client/hiredis/vendor/hiredis.c +0 -1174
  50. data/ext/redis_client/hiredis/vendor/hiredis.h +0 -336
  51. data/ext/redis_client/hiredis/vendor/hiredis.pc.in +0 -12
  52. data/ext/redis_client/hiredis/vendor/hiredis_ssl-config.cmake.in +0 -13
  53. data/ext/redis_client/hiredis/vendor/hiredis_ssl.h +0 -157
  54. data/ext/redis_client/hiredis/vendor/hiredis_ssl.pc.in +0 -12
  55. data/ext/redis_client/hiredis/vendor/net.c +0 -612
  56. data/ext/redis_client/hiredis/vendor/net.h +0 -56
  57. data/ext/redis_client/hiredis/vendor/read.c +0 -739
  58. data/ext/redis_client/hiredis/vendor/read.h +0 -129
  59. data/ext/redis_client/hiredis/vendor/sds.c +0 -1289
  60. data/ext/redis_client/hiredis/vendor/sds.h +0 -278
  61. data/ext/redis_client/hiredis/vendor/sdsalloc.h +0 -44
  62. data/ext/redis_client/hiredis/vendor/sockcompat.c +0 -248
  63. data/ext/redis_client/hiredis/vendor/sockcompat.h +0 -92
  64. data/ext/redis_client/hiredis/vendor/ssl.c +0 -544
  65. data/ext/redis_client/hiredis/vendor/test.c +0 -1401
  66. data/ext/redis_client/hiredis/vendor/test.sh +0 -78
  67. data/ext/redis_client/hiredis/vendor/win32.h +0 -56
  68. data/lib/redis_client/buffered_io.rb +0 -151
  69. data/lib/redis_client/hiredis_connection.rb +0 -80
@@ -1,78 +0,0 @@
1
- #!/bin/sh -ue
2
-
3
- REDIS_SERVER=${REDIS_SERVER:-redis-server}
4
- REDIS_PORT=${REDIS_PORT:-56379}
5
- REDIS_SSL_PORT=${REDIS_SSL_PORT:-56443}
6
- TEST_SSL=${TEST_SSL:-0}
7
- SKIPS_AS_FAILS=${SKIPS_AS_FAILS-:0}
8
- SSL_TEST_ARGS=
9
- SKIPS_ARG=
10
-
11
- tmpdir=$(mktemp -d)
12
- PID_FILE=${tmpdir}/hiredis-test-redis.pid
13
- SOCK_FILE=${tmpdir}/hiredis-test-redis.sock
14
-
15
- if [ "$TEST_SSL" = "1" ]; then
16
- SSL_CA_CERT=${tmpdir}/ca.crt
17
- SSL_CA_KEY=${tmpdir}/ca.key
18
- SSL_CERT=${tmpdir}/redis.crt
19
- SSL_KEY=${tmpdir}/redis.key
20
-
21
- openssl genrsa -out ${tmpdir}/ca.key 4096
22
- openssl req \
23
- -x509 -new -nodes -sha256 \
24
- -key ${SSL_CA_KEY} \
25
- -days 3650 \
26
- -subj '/CN=Hiredis Test CA' \
27
- -out ${SSL_CA_CERT}
28
- openssl genrsa -out ${SSL_KEY} 2048
29
- openssl req \
30
- -new -sha256 \
31
- -key ${SSL_KEY} \
32
- -subj '/CN=Hiredis Test Cert' | \
33
- openssl x509 \
34
- -req -sha256 \
35
- -CA ${SSL_CA_CERT} \
36
- -CAkey ${SSL_CA_KEY} \
37
- -CAserial ${tmpdir}/ca.txt \
38
- -CAcreateserial \
39
- -days 365 \
40
- -out ${SSL_CERT}
41
-
42
- SSL_TEST_ARGS="--ssl-host 127.0.0.1 --ssl-port ${REDIS_SSL_PORT} --ssl-ca-cert ${SSL_CA_CERT} --ssl-cert ${SSL_CERT} --ssl-key ${SSL_KEY}"
43
- fi
44
-
45
- cleanup() {
46
- set +e
47
- kill $(cat ${PID_FILE})
48
- rm -rf ${tmpdir}
49
- }
50
- trap cleanup INT TERM EXIT
51
-
52
- cat > ${tmpdir}/redis.conf <<EOF
53
- daemonize yes
54
- pidfile ${PID_FILE}
55
- port ${REDIS_PORT}
56
- bind 127.0.0.1
57
- unixsocket ${SOCK_FILE}
58
- EOF
59
-
60
- if [ "$TEST_SSL" = "1" ]; then
61
- cat >> ${tmpdir}/redis.conf <<EOF
62
- tls-port ${REDIS_SSL_PORT}
63
- tls-ca-cert-file ${SSL_CA_CERT}
64
- tls-cert-file ${SSL_CERT}
65
- tls-key-file ${SSL_KEY}
66
- EOF
67
- fi
68
-
69
- cat ${tmpdir}/redis.conf
70
- ${REDIS_SERVER} ${tmpdir}/redis.conf
71
-
72
- # Wait until we detect the unix socket
73
- while [ ! -S "${SOCK_FILE}" ]; do sleep 1; done
74
-
75
- # Treat skips as failures if directed
76
- [ "$SKIPS_AS_FAILS" = 1 ] && SKIPS_ARG="--skips-as-fails"
77
-
78
- ${TEST_PREFIX:-} ./hiredis-test -h 127.0.0.1 -p ${REDIS_PORT} -s ${SOCK_FILE} ${SSL_TEST_ARGS} ${SKIPS_ARG}
@@ -1,56 +0,0 @@
1
- #ifndef _WIN32_HELPER_INCLUDE
2
- #define _WIN32_HELPER_INCLUDE
3
- #ifdef _MSC_VER
4
-
5
- #include <winsock2.h> /* for struct timeval */
6
-
7
- #ifndef inline
8
- #define inline __inline
9
- #endif
10
-
11
- #ifndef strcasecmp
12
- #define strcasecmp stricmp
13
- #endif
14
-
15
- #ifndef strncasecmp
16
- #define strncasecmp strnicmp
17
- #endif
18
-
19
- #ifndef va_copy
20
- #define va_copy(d,s) ((d) = (s))
21
- #endif
22
-
23
- #ifndef snprintf
24
- #define snprintf c99_snprintf
25
-
26
- __inline int c99_vsnprintf(char* str, size_t size, const char* format, va_list ap)
27
- {
28
- int count = -1;
29
-
30
- if (size != 0)
31
- count = _vsnprintf_s(str, size, _TRUNCATE, format, ap);
32
- if (count == -1)
33
- count = _vscprintf(format, ap);
34
-
35
- return count;
36
- }
37
-
38
- __inline int c99_snprintf(char* str, size_t size, const char* format, ...)
39
- {
40
- int count;
41
- va_list ap;
42
-
43
- va_start(ap, format);
44
- count = c99_vsnprintf(str, size, format, ap);
45
- va_end(ap);
46
-
47
- return count;
48
- }
49
- #endif
50
- #endif /* _MSC_VER */
51
-
52
- #ifdef _WIN32
53
- #define strerror_r(errno,buf,len) strerror_s(buf,len,errno)
54
- #endif /* _WIN32 */
55
-
56
- #endif /* _WIN32_HELPER_INCLUDE */
@@ -1,151 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "io/wait" unless IO.method_defined?(:wait_readable) && IO.method_defined?(:wait_writable)
4
-
5
- class RedisClient
6
- class BufferedIO
7
- EOL = "\r\n".b.freeze
8
- EOL_SIZE = EOL.bytesize
9
-
10
- attr_accessor :read_timeout, :write_timeout
11
-
12
- def initialize(io, read_timeout:, write_timeout:, chunk_size: 4096)
13
- @io = io
14
- @buffer = "".b
15
- @offset = 0
16
- @chunk_size = chunk_size
17
- @read_timeout = read_timeout
18
- @write_timeout = write_timeout
19
- @blocking_reads = false
20
- end
21
-
22
- def close
23
- @io.to_io.close
24
- end
25
-
26
- def closed?
27
- @io.to_io.closed?
28
- end
29
-
30
- def eof?
31
- @offset >= @buffer.bytesize && @io.eof?
32
- end
33
-
34
- def with_timeout(new_timeout)
35
- new_timeout = false if new_timeout == 0
36
-
37
- previous_read_timeout = @read_timeout
38
- previous_blocking_reads = @blocking_reads
39
-
40
- if new_timeout
41
- @read_timeout = new_timeout
42
- else
43
- @blocking_reads = true
44
- end
45
-
46
- begin
47
- yield
48
- ensure
49
- @read_timeout = previous_read_timeout
50
- @blocking_reads = previous_blocking_reads
51
- end
52
- end
53
-
54
- def skip(offset)
55
- ensure_remaining(offset)
56
- @offset += offset
57
- nil
58
- end
59
-
60
- def write(string)
61
- total = remaining = string.bytesize
62
- loop do
63
- case bytes_written = @io.write_nonblock(string, exception: false)
64
- when Integer
65
- remaining -= bytes_written
66
- if remaining > 0
67
- string = string.byteslice(bytes_written..-1)
68
- else
69
- return total
70
- end
71
- when :wait_readable
72
- @io.to_io.wait_readable(@read_timeout) or raise ReadTimeoutError
73
- when :wait_writable
74
- @io.to_io.wait_writable(@write_timeout) or raise WriteTimeoutError
75
- when nil
76
- raise Errno::ECONNRESET
77
- else
78
- raise "Unexpected `write_nonblock` return: #{bytes.inspect}"
79
- end
80
- end
81
- end
82
-
83
- def getbyte
84
- ensure_remaining(1)
85
- byte = @buffer.getbyte(@offset)
86
- @offset += 1
87
- byte
88
- end
89
-
90
- def gets_chomp
91
- fill_buffer(false) if @offset >= @buffer.bytesize
92
- until eol_index = @buffer.index(EOL, @offset)
93
- fill_buffer(false)
94
- end
95
-
96
- line = @buffer.byteslice(@offset, eol_index - @offset)
97
- @offset = eol_index + EOL_SIZE
98
- line
99
- end
100
-
101
- def read_chomp(bytes)
102
- ensure_remaining(bytes + EOL_SIZE)
103
- str = @buffer.byteslice(@offset, bytes)
104
- @offset += bytes + EOL_SIZE
105
- str
106
- end
107
-
108
- private
109
-
110
- def ensure_remaining(bytes)
111
- needed = bytes - (@buffer.bytesize - @offset)
112
- if needed > 0
113
- fill_buffer(true, needed)
114
- end
115
- end
116
-
117
- def fill_buffer(strict, size = @chunk_size)
118
- remaining = size
119
- empty_buffer = @offset >= @buffer.bytesize
120
-
121
- loop do
122
- bytes = if empty_buffer
123
- @io.read_nonblock([remaining, @chunk_size].max, @buffer, exception: false)
124
- else
125
- @io.read_nonblock([remaining, @chunk_size].max, exception: false)
126
- end
127
- case bytes
128
- when String
129
- if empty_buffer
130
- @offset = 0
131
- empty_buffer = false
132
- else
133
- @buffer << bytes
134
- end
135
- remaining -= bytes.bytesize
136
- return if !strict || remaining <= 0
137
- when :wait_readable
138
- unless @io.to_io.wait_readable(@read_timeout)
139
- raise ReadTimeoutError unless @blocking_reads
140
- end
141
- when :wait_writable
142
- @io.to_io.wait_writable(@write_timeout) or raise WriteTimeoutError
143
- when nil
144
- raise Errno::ECONNRESET
145
- else
146
- raise "Unexpected `read_nonblock` return: #{bytes.inspect}"
147
- end
148
- end
149
- end
150
- end
151
- end
@@ -1,80 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "redis_client/hiredis_connection.so"
4
-
5
- class RedisClient
6
- class HiredisConnection
7
- include Connection::Common
8
-
9
- class SSLContext
10
- def initialize(ca_file: nil, ca_path: nil, cert: nil, key: nil, hostname: nil)
11
- if (error = init(ca_file, ca_path, cert, key, hostname))
12
- raise error
13
- end
14
- end
15
- end
16
-
17
- def initialize(config, connect_timeout:, read_timeout:, write_timeout:)
18
- self.connect_timeout = connect_timeout
19
- self.read_timeout = read_timeout
20
- self.write_timeout = write_timeout
21
-
22
- if config.path
23
- connect_unix(config.path)
24
- else
25
- connect_tcp(config.host, config.port)
26
- end
27
-
28
- if config.ssl
29
- init_ssl(config.hiredis_ssl_context)
30
- end
31
- end
32
-
33
- def connect_timeout=(timeout)
34
- self.connect_timeout_us = timeout ? (timeout * 1_000_000).to_i : 0
35
- @connect_timeout = timeout
36
- end
37
-
38
- def read_timeout=(timeout)
39
- self.read_timeout_us = timeout ? (timeout * 1_000_000).to_i : 0
40
- @read_timeout = timeout
41
- end
42
-
43
- def write_timeout=(timeout)
44
- self.write_timeout_us = timeout ? (timeout * 1_000_000).to_i : 0
45
- @write_timeout = timeout
46
- end
47
-
48
- def read(timeout = nil)
49
- if timeout.nil?
50
- _read
51
- else
52
- previous_timeout = @read_timeout
53
- self.read_timeout = timeout
54
- begin
55
- _read
56
- ensure
57
- self.read_timeout = previous_timeout
58
- end
59
- end
60
- rescue SystemCallError, IOError => error
61
- raise ConnectionError, error.message
62
- end
63
-
64
- def write(command)
65
- _write(command)
66
- flush
67
- rescue SystemCallError, IOError => error
68
- raise ConnectionError, error.message
69
- end
70
-
71
- def write_multi(commands)
72
- commands.each do |command|
73
- _write(command)
74
- end
75
- flush
76
- rescue SystemCallError, IOError => error
77
- raise ConnectionError, error.message
78
- end
79
- end
80
- end