hiredis-client 0.14.1 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3506adf6e5b2e5da54f4fc75e762a0fd4f23b9bd9ea225a468b2ae96360d0273
4
- data.tar.gz: 484b29d8fb080fad9076e71f1db9a1703b9b2a3a5ae173b6a5073d5abb2bfbe6
3
+ metadata.gz: 61bc01f80337772a560ed39e2ee0ecf4c783f9190dba9d58d8a4a4b9508b2ec6
4
+ data.tar.gz: 9ea97d9bf65cf629ca7501534faa2644dd8c8afc2e9d74b973d8d661909cd327
5
5
  SHA512:
6
- metadata.gz: 3e238fe1e94a808f6c1966c8c2ce1136fa173594cfa824156199c3509b3b61c8b9f97a75336458edf7c50dcddc7a7d08833358a9f34bf64f141587fb1f19fa74
7
- data.tar.gz: a6ddda3ab9d41f591cd82c1319fd43fc701cbb0c515768e0d940bc095fc69c69334bbf932c860ab37944a7f73e141a5e6b25fc4a2de454fb726f4dd199fadf48
6
+ metadata.gz: e334396d8518211eda9f1c60151b140cc713049ec32b68b57de0f16977c76693b3a4de7b93c70a56dbb1ef1826717754d0e8ccc92247c7f26f01e853f8093ea0
7
+ data.tar.gz: 9e3597f5cde32b9289c5d35554046b4e40bda564656eb94dafe65521e22049baa19decbda89b215343187e054a30372ed7d2c96f9297dbfb285ac9ab10e1fc2b
@@ -39,6 +39,7 @@
39
39
  #include "hiredis.h"
40
40
  #include "net.h"
41
41
  #include "hiredis_ssl.h"
42
+ #include <poll.h>
42
43
 
43
44
  #if !defined(RUBY_ASSERT)
44
45
  # define RUBY_ASSERT(condition) ((void)0)
@@ -797,6 +798,93 @@ static VALUE hiredis_close(VALUE self) {
797
798
  return Qnil;
798
799
  }
799
800
 
801
+ static inline double diff_timespec_ms(const struct timespec *time1, const struct timespec *time0) {
802
+ return ((time1->tv_sec - time0->tv_sec) * 1000.0)
803
+ + (time1->tv_nsec - time0->tv_nsec) / 1000000.0;
804
+ }
805
+
806
+ static inline int timeval_to_msec(struct timeval duration) {
807
+ return duration.tv_sec * 1000 + duration.tv_usec / 1000;
808
+ }
809
+
810
+ typedef struct {
811
+ hiredis_connection_t *connection;
812
+ struct timespec start;
813
+ struct timespec end;
814
+ int return_value;
815
+ } hiredis_measure_round_trip_delay_args_t;
816
+
817
+ static const size_t pong_length = 7;
818
+
819
+ static void *hiredis_measure_round_trip_delay_safe(void *_args) {
820
+ hiredis_measure_round_trip_delay_args_t *args = _args;
821
+ hiredis_connection_t *connection = args->connection;
822
+ redisReader *reader = connection->context->reader;
823
+
824
+ if (reader->len - reader->pos != 0) {
825
+ args->return_value = REDIS_ERR;
826
+ return NULL;
827
+ }
828
+
829
+ redisAppendFormattedCommand(connection->context, "PING\r\n", 6);
830
+
831
+ clock_gettime(CLOCK_MONOTONIC, &args->start);
832
+
833
+ int wdone = 0;
834
+ do {
835
+ if (redisBufferWrite(connection->context, &wdone) == REDIS_ERR) {
836
+ args->return_value = REDIS_ERR;
837
+ return NULL;
838
+ }
839
+ } while (!wdone);
840
+
841
+ struct pollfd wfd[1];
842
+ wfd[0].fd = connection->context->fd;
843
+ wfd[0].events = POLLIN;
844
+ int retval = poll(wfd, 1, timeval_to_msec(connection->read_timeout));
845
+ if (retval == -1) {
846
+ args->return_value = REDIS_ERR_IO;
847
+ return NULL;
848
+ } else if (!retval) {
849
+ args->return_value = REDIS_ERR_IO;
850
+ return NULL;
851
+ }
852
+
853
+ redisBufferRead(connection->context);
854
+
855
+ if (reader->len - reader->pos != pong_length) {
856
+ args->return_value = REDIS_ERR;
857
+ return NULL;
858
+ }
859
+
860
+ if (strncmp(reader->buf + reader->pos, "+PONG\r\n", pong_length) != 0) {
861
+ args->return_value = REDIS_ERR;
862
+ return NULL;
863
+ }
864
+ reader->pos += pong_length;
865
+
866
+ clock_gettime(CLOCK_MONOTONIC, &args->end);
867
+ args->return_value = REDIS_OK;
868
+ return NULL;
869
+ }
870
+
871
+ static VALUE hiredis_measure_round_trip_delay(VALUE self) {
872
+ CONNECTION(self, connection);
873
+ ENSURE_CONNECTED(connection);
874
+
875
+ hiredis_measure_round_trip_delay_args_t args = {
876
+ .connection = connection,
877
+ };
878
+ rb_thread_call_without_gvl(hiredis_measure_round_trip_delay_safe, &args, RUBY_UBF_IO, 0);
879
+
880
+ if (args.return_value != REDIS_OK) {
881
+ hiredis_raise_error_and_disconnect(connection, rb_eRedisClientReadTimeoutError);
882
+ return Qnil; // unreachable;
883
+ }
884
+
885
+ return DBL2NUM(diff_timespec_ms(&args.end, &args.start));
886
+ }
887
+
800
888
  RUBY_FUNC_EXPORTED void Init_hiredis_connection(void) {
801
889
  // Qfalse == NULL, so we can't return Qfalse in `reply_create_bool()`
802
890
  RUBY_ASSERT((void *)Qfalse == NULL);
@@ -843,6 +931,7 @@ RUBY_FUNC_EXPORTED void Init_hiredis_connection(void) {
843
931
  rb_define_private_method(rb_cHiredisConnection, "_read", hiredis_read, 0);
844
932
  rb_define_private_method(rb_cHiredisConnection, "flush", hiredis_flush, 0);
845
933
  rb_define_private_method(rb_cHiredisConnection, "_close", hiredis_close, 0);
934
+ rb_define_method(rb_cHiredisConnection, "measure_round_trip_delay", hiredis_measure_round_trip_delay, 0);
846
935
 
847
936
  VALUE rb_cHiredisSSLContext = rb_define_class_under(rb_cHiredisConnection, "SSLContext", rb_cObject);
848
937
  rb_define_alloc_func(rb_cHiredisSSLContext, hiredis_ssl_context_alloc);
@@ -10,6 +10,17 @@ class RedisClient
10
10
 
11
11
  class << self
12
12
  def ssl_context(ssl_params)
13
+ unless ssl_params[:ca_file] || ssl_params[:ca_path]
14
+ default_ca_file = OpenSSL::X509::DEFAULT_CERT_FILE
15
+ default_ca_path = OpenSSL::X509::DEFAULT_CERT_DIR
16
+
17
+ if File.readable? default_ca_file
18
+ ssl_params[:ca_file] = default_ca_file
19
+ elsif File.directory? default_ca_path
20
+ ssl_params[:ca_path] = default_ca_path
21
+ end
22
+ end
23
+
13
24
  HiredisConnection::SSLContext.new(
14
25
  ca_file: ssl_params[:ca_file],
15
26
  ca_path: ssl_params[:ca_path],
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hiredis-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.1
4
+ version: 0.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean Boussier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-30 00:00:00.000000000 Z
11
+ date: 2023-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis-client
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.14.1
19
+ version: 0.16.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 0.14.1
26
+ version: 0.16.0
27
27
  description:
28
28
  email:
29
29
  - jean.boussier@gmail.com
@@ -105,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
105
  - !ruby/object:Gem::Version
106
106
  version: '0'
107
107
  requirements: []
108
- rubygems_version: 3.4.6
108
+ rubygems_version: 3.4.10
109
109
  signing_key:
110
110
  specification_version: 4
111
111
  summary: Hiredis binding for redis-client