hiredis-client 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +5 -0
  3. data/ext/redis_client/hiredis/export.clang +2 -0
  4. data/ext/redis_client/hiredis/export.gcc +7 -0
  5. data/ext/redis_client/hiredis/extconf.rb +69 -0
  6. data/ext/redis_client/hiredis/hiredis_connection.c +708 -0
  7. data/ext/redis_client/hiredis/vendor/.gitignore +9 -0
  8. data/ext/redis_client/hiredis/vendor/.travis.yml +131 -0
  9. data/ext/redis_client/hiredis/vendor/CHANGELOG.md +364 -0
  10. data/ext/redis_client/hiredis/vendor/CMakeLists.txt +165 -0
  11. data/ext/redis_client/hiredis/vendor/COPYING +29 -0
  12. data/ext/redis_client/hiredis/vendor/Makefile +308 -0
  13. data/ext/redis_client/hiredis/vendor/README.md +664 -0
  14. data/ext/redis_client/hiredis/vendor/adapters/ae.h +130 -0
  15. data/ext/redis_client/hiredis/vendor/adapters/glib.h +156 -0
  16. data/ext/redis_client/hiredis/vendor/adapters/ivykis.h +84 -0
  17. data/ext/redis_client/hiredis/vendor/adapters/libev.h +179 -0
  18. data/ext/redis_client/hiredis/vendor/adapters/libevent.h +175 -0
  19. data/ext/redis_client/hiredis/vendor/adapters/libuv.h +117 -0
  20. data/ext/redis_client/hiredis/vendor/adapters/macosx.h +115 -0
  21. data/ext/redis_client/hiredis/vendor/adapters/qt.h +135 -0
  22. data/ext/redis_client/hiredis/vendor/alloc.c +86 -0
  23. data/ext/redis_client/hiredis/vendor/alloc.h +91 -0
  24. data/ext/redis_client/hiredis/vendor/appveyor.yml +24 -0
  25. data/ext/redis_client/hiredis/vendor/async.c +887 -0
  26. data/ext/redis_client/hiredis/vendor/async.h +147 -0
  27. data/ext/redis_client/hiredis/vendor/async_private.h +75 -0
  28. data/ext/redis_client/hiredis/vendor/dict.c +352 -0
  29. data/ext/redis_client/hiredis/vendor/dict.h +126 -0
  30. data/ext/redis_client/hiredis/vendor/fmacros.h +12 -0
  31. data/ext/redis_client/hiredis/vendor/hiredis-config.cmake.in +13 -0
  32. data/ext/redis_client/hiredis/vendor/hiredis.c +1174 -0
  33. data/ext/redis_client/hiredis/vendor/hiredis.h +336 -0
  34. data/ext/redis_client/hiredis/vendor/hiredis.pc.in +12 -0
  35. data/ext/redis_client/hiredis/vendor/hiredis_ssl-config.cmake.in +13 -0
  36. data/ext/redis_client/hiredis/vendor/hiredis_ssl.h +157 -0
  37. data/ext/redis_client/hiredis/vendor/hiredis_ssl.pc.in +12 -0
  38. data/ext/redis_client/hiredis/vendor/net.c +612 -0
  39. data/ext/redis_client/hiredis/vendor/net.h +56 -0
  40. data/ext/redis_client/hiredis/vendor/read.c +739 -0
  41. data/ext/redis_client/hiredis/vendor/read.h +129 -0
  42. data/ext/redis_client/hiredis/vendor/sds.c +1289 -0
  43. data/ext/redis_client/hiredis/vendor/sds.h +278 -0
  44. data/ext/redis_client/hiredis/vendor/sdsalloc.h +44 -0
  45. data/ext/redis_client/hiredis/vendor/sockcompat.c +248 -0
  46. data/ext/redis_client/hiredis/vendor/sockcompat.h +92 -0
  47. data/ext/redis_client/hiredis/vendor/ssl.c +544 -0
  48. data/ext/redis_client/hiredis/vendor/test.c +1401 -0
  49. data/ext/redis_client/hiredis/vendor/test.sh +78 -0
  50. data/ext/redis_client/hiredis/vendor/win32.h +56 -0
  51. data/hiredis-client.gemspec +33 -0
  52. data/lib/hiredis-client.rb +11 -0
  53. data/lib/redis_client/hiredis_connection.rb +94 -0
  54. metadata +114 -0
@@ -0,0 +1,78 @@
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}
@@ -0,0 +1,56 @@
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 */
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../lib/redis_client/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "hiredis-client"
7
+ spec.version = RedisClient::VERSION
8
+ spec.authors = ["Jean Boussier"]
9
+ spec.email = ["jean.boussier@gmail.com"]
10
+
11
+ spec.summary = "Hiredis binding for redis-client"
12
+ spec.homepage = "https://github.com/redis-rb/redis-client"
13
+ spec.license = "MIT"
14
+ spec.required_ruby_version = ">= 2.5.0"
15
+
16
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
17
+
18
+ spec.metadata["homepage_uri"] = spec.homepage
19
+ spec.metadata["source_code_uri"] = spec.homepage
20
+ spec.metadata["changelog_uri"] = File.join(spec.homepage, "blob/master/CHANGELOG.md")
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
+ `git ls-files -z`.split("\x0").reject do |f|
26
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features|benchmark)/|\.(?:git|rubocop))})
27
+ end
28
+ end
29
+ spec.require_paths = ["lib"]
30
+ spec.extensions = ["ext/redis_client/hiredis/extconf.rb"]
31
+
32
+ spec.add_runtime_dependency "redis-client", RedisClient::VERSION
33
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "redis-client"
4
+
5
+ begin
6
+ require "redis_client/hiredis_connection"
7
+ rescue LoadError
8
+ else
9
+ RedisClient.register_driver(:hiredis) { RedisClient::HiredisConnection }
10
+ RedisClient.default_driver = :hiredis
11
+ end
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "openssl"
4
+ require "redis_client/hiredis_connection.so"
5
+ require "redis_client/connection_mixin"
6
+
7
+ class RedisClient
8
+ class HiredisConnection
9
+ include ConnectionMixin
10
+
11
+ class << self
12
+ def ssl_context(ssl_params)
13
+ HiredisConnection::SSLContext.new(
14
+ ca_file: ssl_params[:ca_file],
15
+ ca_path: ssl_params[:ca_path],
16
+ cert: ssl_params[:cert],
17
+ key: ssl_params[:key],
18
+ hostname: ssl_params[:hostname],
19
+ )
20
+ end
21
+ end
22
+
23
+ class SSLContext
24
+ def initialize(ca_file: nil, ca_path: nil, cert: nil, key: nil, hostname: nil)
25
+ if (error = init(ca_file, ca_path, cert, key, hostname))
26
+ raise error
27
+ end
28
+ end
29
+ end
30
+
31
+ def initialize(config, connect_timeout:, read_timeout:, write_timeout:)
32
+ self.connect_timeout = connect_timeout
33
+ self.read_timeout = read_timeout
34
+ self.write_timeout = write_timeout
35
+
36
+ if config.path
37
+ connect_unix(config.path)
38
+ else
39
+ connect_tcp(config.host, config.port)
40
+ end
41
+
42
+ if config.ssl
43
+ init_ssl(config.ssl_context)
44
+ end
45
+ end
46
+
47
+ def connect_timeout=(timeout)
48
+ self.connect_timeout_us = timeout ? (timeout * 1_000_000).to_i : 0
49
+ @connect_timeout = timeout
50
+ end
51
+
52
+ def read_timeout=(timeout)
53
+ self.read_timeout_us = timeout ? (timeout * 1_000_000).to_i : 0
54
+ @read_timeout = timeout
55
+ end
56
+
57
+ def write_timeout=(timeout)
58
+ self.write_timeout_us = timeout ? (timeout * 1_000_000).to_i : 0
59
+ @write_timeout = timeout
60
+ end
61
+
62
+ def read(timeout = nil)
63
+ if timeout.nil?
64
+ _read
65
+ else
66
+ previous_timeout = @read_timeout
67
+ self.read_timeout = timeout
68
+ begin
69
+ _read
70
+ ensure
71
+ self.read_timeout = previous_timeout
72
+ end
73
+ end
74
+ rescue SystemCallError, IOError => error
75
+ raise ConnectionError, error.message
76
+ end
77
+
78
+ def write(command)
79
+ _write(command)
80
+ flush
81
+ rescue SystemCallError, IOError => error
82
+ raise ConnectionError, error.message
83
+ end
84
+
85
+ def write_multi(commands)
86
+ commands.each do |command|
87
+ _write(command)
88
+ end
89
+ flush
90
+ rescue SystemCallError, IOError => error
91
+ raise ConnectionError, error.message
92
+ end
93
+ end
94
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hiredis-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
5
+ platform: ruby
6
+ authors:
7
+ - Jean Boussier
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-05-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: redis-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 0.4.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 0.4.0
27
+ description:
28
+ email:
29
+ - jean.boussier@gmail.com
30
+ executables: []
31
+ extensions:
32
+ - ext/redis_client/hiredis/extconf.rb
33
+ extra_rdoc_files: []
34
+ files:
35
+ - README.md
36
+ - ext/redis_client/hiredis/export.clang
37
+ - ext/redis_client/hiredis/export.gcc
38
+ - ext/redis_client/hiredis/extconf.rb
39
+ - ext/redis_client/hiredis/hiredis_connection.c
40
+ - ext/redis_client/hiredis/vendor/.gitignore
41
+ - ext/redis_client/hiredis/vendor/.travis.yml
42
+ - ext/redis_client/hiredis/vendor/CHANGELOG.md
43
+ - ext/redis_client/hiredis/vendor/CMakeLists.txt
44
+ - ext/redis_client/hiredis/vendor/COPYING
45
+ - ext/redis_client/hiredis/vendor/Makefile
46
+ - ext/redis_client/hiredis/vendor/README.md
47
+ - ext/redis_client/hiredis/vendor/adapters/ae.h
48
+ - ext/redis_client/hiredis/vendor/adapters/glib.h
49
+ - ext/redis_client/hiredis/vendor/adapters/ivykis.h
50
+ - ext/redis_client/hiredis/vendor/adapters/libev.h
51
+ - ext/redis_client/hiredis/vendor/adapters/libevent.h
52
+ - ext/redis_client/hiredis/vendor/adapters/libuv.h
53
+ - ext/redis_client/hiredis/vendor/adapters/macosx.h
54
+ - ext/redis_client/hiredis/vendor/adapters/qt.h
55
+ - ext/redis_client/hiredis/vendor/alloc.c
56
+ - ext/redis_client/hiredis/vendor/alloc.h
57
+ - ext/redis_client/hiredis/vendor/appveyor.yml
58
+ - ext/redis_client/hiredis/vendor/async.c
59
+ - ext/redis_client/hiredis/vendor/async.h
60
+ - ext/redis_client/hiredis/vendor/async_private.h
61
+ - ext/redis_client/hiredis/vendor/dict.c
62
+ - ext/redis_client/hiredis/vendor/dict.h
63
+ - ext/redis_client/hiredis/vendor/fmacros.h
64
+ - ext/redis_client/hiredis/vendor/hiredis-config.cmake.in
65
+ - ext/redis_client/hiredis/vendor/hiredis.c
66
+ - ext/redis_client/hiredis/vendor/hiredis.h
67
+ - ext/redis_client/hiredis/vendor/hiredis.pc.in
68
+ - ext/redis_client/hiredis/vendor/hiredis_ssl-config.cmake.in
69
+ - ext/redis_client/hiredis/vendor/hiredis_ssl.h
70
+ - ext/redis_client/hiredis/vendor/hiredis_ssl.pc.in
71
+ - ext/redis_client/hiredis/vendor/net.c
72
+ - ext/redis_client/hiredis/vendor/net.h
73
+ - ext/redis_client/hiredis/vendor/read.c
74
+ - ext/redis_client/hiredis/vendor/read.h
75
+ - ext/redis_client/hiredis/vendor/sds.c
76
+ - ext/redis_client/hiredis/vendor/sds.h
77
+ - ext/redis_client/hiredis/vendor/sdsalloc.h
78
+ - ext/redis_client/hiredis/vendor/sockcompat.c
79
+ - ext/redis_client/hiredis/vendor/sockcompat.h
80
+ - ext/redis_client/hiredis/vendor/ssl.c
81
+ - ext/redis_client/hiredis/vendor/test.c
82
+ - ext/redis_client/hiredis/vendor/test.sh
83
+ - ext/redis_client/hiredis/vendor/win32.h
84
+ - hiredis-client.gemspec
85
+ - lib/hiredis-client.rb
86
+ - lib/redis_client/hiredis_connection.rb
87
+ homepage: https://github.com/redis-rb/redis-client
88
+ licenses:
89
+ - MIT
90
+ metadata:
91
+ allowed_push_host: https://rubygems.org
92
+ homepage_uri: https://github.com/redis-rb/redis-client
93
+ source_code_uri: https://github.com/redis-rb/redis-client
94
+ changelog_uri: https://github.com/redis-rb/redis-client/blob/master/CHANGELOG.md
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: 2.5.0
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubygems_version: 3.3.7
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: Hiredis binding for redis-client
114
+ test_files: []