source stringclasses 1
value | repo stringlengths 5 63 | repo_url stringlengths 24 82 | path stringlengths 5 167 | language stringclasses 1
value | license stringclasses 5
values | stars int64 10 51.4k | ref stringclasses 23
values | size_bytes int64 200 258k | text stringlengths 137 258k |
|---|---|---|---|---|---|---|---|---|---|
github | redis/redis-rb | https://github.com/redis/redis-rb | cluster/test/commands_on_streams_test.rb | Ruby | mit | 3,989 | master | 1,798 | # frozen_string_literal: true
require "helper"
# ruby -w -Itest test/cluster_commands_on_streams_test.rb
# @see https://redis.io/commands#stream
class TestClusterCommandsOnStreams < Minitest::Test
include Helper::Cluster
include Lint::Streams
def test_xread_with_multiple_keys
err_msg = "CROSSSLOT Keys in r... |
github | redis/redis-rb | https://github.com/redis/redis-rb | cluster/test/client_internals_test.rb | Ruby | mit | 3,989 | master | 1,888 | # frozen_string_literal: true
require "helper"
# ruby -w -Itest test/cluster_client_internals_test.rb
class TestClusterClientInternals < Minitest::Test
include Helper::Cluster
def test_handle_multiple_servers
100.times { |i| redis.set(i.to_s, "hogehoge#{i}") }
100.times { |i| assert_equal "hogehoge#{i}",... |
github | redis/redis-rb | https://github.com/redis/redis-rb | cluster/test/client_pipelining_test.rb | Ruby | mit | 3,989 | master | 2,236 | # frozen_string_literal: true
require "helper"
# ruby -w -Itest test/cluster_client_pipelining_test.rb
class TestClusterClientPipelining < Minitest::Test
include Helper::Cluster
def test_pipelining_with_a_hash_tag
p1 = p2 = p3 = p4 = p5 = p6 = nil
redis.pipelined do |r|
r.set('{Presidents.of.USA}:... |
github | redis/redis-rb | https://github.com/redis/redis-rb | cluster/test/commands_on_hyper_log_log_test.rb | Ruby | mit | 3,989 | master | 359 | # frozen_string_literal: true
require "helper"
# ruby -w -Itest test/cluster_commands_on_hyper_log_log_test.rb
# @see https://redis.io/commands#hyperloglog
class TestClusterCommandsOnHyperLogLog < Minitest::Test
include Helper::Cluster
include Lint::HyperLogLog
def test_pfmerge
assert_raises Redis::Command... |
github | redis/redis-rb | https://github.com/redis/redis-rb | cluster/test/client_replicas_test.rb | Ruby | mit | 3,989 | master | 461 | # frozen_string_literal: true
require "helper"
# ruby -w -Itest test/cluster_client_replicas_test.rb
class TestClusterClientReplicas < Minitest::Test
include Helper::Cluster
def test_client_can_command_with_replica
r = build_another_client(replica: true)
100.times do |i|
assert_equal 'OK', r.set("... |
github | redis/redis-rb | https://github.com/redis/redis-rb | cluster/test/commands_on_scripting_test.rb | Ruby | mit | 3,989 | master | 1,563 | # frozen_string_literal: true
require "helper"
# ruby -w -Itest test/cluster_commands_on_scripting_test.rb
# @see https://redis.io/commands#scripting
class TestClusterCommandsOnScripting < Minitest::Test
include Helper::Cluster
def test_eval
script = 'return {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}'
argv = %w[f... |
github | redis/redis-rb | https://github.com/redis/redis-rb | cluster/test/blocking_commands_test.rb | Ruby | mit | 3,989 | master | 384 | # frozen_string_literal: true
require "helper"
# ruby -w -Itest test/cluster_blocking_commands_test.rb
class TestClusterBlockingCommands < Minitest::Test
include Helper::Cluster
include Lint::BlockingCommands
def mock(options = {}, &blk)
commands = build_mock_commands(options)
redis_cluster_mock(comman... |
github | redis/redis-rb | https://github.com/redis/redis-rb | cluster/test/commands_on_transactions_test.rb | Ruby | mit | 3,989 | master | 1,909 | # frozen_string_literal: true
require "helper"
# ruby -w -Itest test/cluster_commands_on_transactions_test.rb
# @see https://redis.io/commands#transactions
class TestClusterCommandsOnTransactions < Minitest::Test
include Helper::Cluster
def test_discard
assert_raises(Redis::Cluster::AmbiguousNodeError) do
... |
github | redis/redis-rb | https://github.com/redis/redis-rb | cluster/test/commands_on_cluster_test.rb | Ruby | mit | 3,989 | master | 5,293 | # frozen_string_literal: true
require "helper"
# ruby -w -Itest test/cluster_commands_on_cluster_test.rb
# @see https://redis.io/commands#cluster
class TestClusterCommandsOnCluster < Minitest::Test
include Helper::Cluster
def test_cluster_addslots
assert_raises(Redis::Cluster::OrchestrationCommandNotSupporte... |
github | redis/redis-rb | https://github.com/redis/redis-rb | cluster/test/commands_on_sets_test.rb | Ruby | mit | 3,989 | master | 771 | # frozen_string_literal: true
require "helper"
# ruby -w -Itest test/cluster_commands_on_sets_test.rb
# @see https://redis.io/commands#set
class TestClusterCommandsOnSets < Minitest::Test
include Helper::Cluster
include Lint::Sets
def test_sdiff
assert_raises(Redis::CommandError) { super }
end
def tes... |
github | redis/redis-rb | https://github.com/redis/redis-rb | cluster/test/commands_on_geo_test.rb | Ruby | mit | 3,989 | master | 2,599 | # frozen_string_literal: true
require "helper"
# ruby -w -Itest test/cluster_commands_on_geo_test.rb
# @see https://redis.io/commands#geo
class TestClusterCommandsOnGeo < Minitest::Test
include Helper::Cluster
def add_sicily
redis.geoadd('Sicily',
13.361389, 38.115556, 'Palermo',
... |
github | redis/redis-rb | https://github.com/redis/redis-rb | cluster/test/commands_on_server_test.rb | Ruby | mit | 3,989 | master | 5,090 | # frozen_string_literal: true
require "helper"
# ruby -w -Itest test/cluster_commands_on_server_test.rb
# @see https://redis.io/commands#server
class TestClusterCommandsOnServer < Minitest::Test
include Helper::Cluster
def test_bgrewriteaof
assert_equal 'Background append only file rewriting started', redis.... |
github | redis/redis-rb | https://github.com/redis/redis-rb | cluster/test/commands_on_pub_sub_test.rb | Ruby | mit | 3,989 | master | 2,868 | # frozen_string_literal: true
require "helper"
# ruby -w -Itest test/cluster_commands_on_pub_sub_test.rb
# @see https://redis.io/commands#pubsub
class TestClusterCommandsOnPubSub < Minitest::Test
include Helper::Cluster
def test_publish_subscribe_unsubscribe_pubsub
sub_cnt = 0
messages = {}
thread =... |
github | redis/redis-rb | https://github.com/redis/redis-rb | cluster/test/commands_on_keys_test.rb | Ruby | mit | 3,989 | master | 3,850 | # frozen_string_literal: true
require "helper"
# ruby -w -Itest test/cluster_commands_on_keys_test.rb
# @see https://redis.io/commands#generic
class TestClusterCommandsOnKeys < Minitest::Test
include Helper::Cluster
def set_some_keys
redis.set('key1', 'Hello')
redis.set('key2', 'World')
redis.set('{... |
github | redis/redis-rb | https://github.com/redis/redis-rb | cluster/test/helper.rb | Ruby | mit | 3,989 | master | 3,862 | # frozen_string_literal: true
require_relative "../../test/helper"
$LOAD_PATH.unshift(File.expand_path('../lib', __dir__))
require "redis-clustering"
require_relative 'support/orchestrator'
module Helper
module Cluster
include Generic
DEFAULT_HOST = '127.0.0.1'
DEFAULT_PORTS = (16_380..16_385).freeze
... |
github | redis/redis-rb | https://github.com/redis/redis-rb | cluster/test/commands_on_lists_test.rb | Ruby | mit | 3,989 | master | 433 | # frozen_string_literal: true
require "helper"
# ruby -w -Itest test/cluster_commands_on_lists_test.rb
# @see https://redis.io/commands#list
class TestClusterCommandsOnLists < Minitest::Test
include Helper::Cluster
include Lint::Lists
def test_lmove
target_version "6.2" do
assert_raises(Redis::Comman... |
github | redis/redis-rb | https://github.com/redis/redis-rb | cluster/test/client_transactions_test.rb | Ruby | mit | 3,989 | master | 2,954 | # frozen_string_literal: true
require "helper"
# ruby -w -Itest test/cluster_client_transactions_test.rb
class TestClusterClientTransactions < Minitest::Test
include Helper::Cluster
def test_cluster_client_does_support_transaction_by_single_key
actual = redis.multi do |tx|
tx.set('counter', '0')
... |
github | redis/redis-rb | https://github.com/redis/redis-rb | cluster/test/commands_on_value_types_test.rb | Ruby | mit | 3,989 | master | 627 | # frozen_string_literal: true
require "helper"
# ruby -w -Itest test/cluster_commands_on_value_types_test.rb
class TestClusterCommandsOnValueTypes < Minitest::Test
include Helper::Cluster
include Lint::ValueTypes
def test_move
assert_raises(Redis::CommandError, 'ERR MOVE is not allowed in cluster mode') do... |
github | redis/redis-rb | https://github.com/redis/redis-rb | cluster/test/commands_on_strings_test.rb | Ruby | mit | 3,989 | master | 324 | # frozen_string_literal: true
require "helper"
# ruby -w -Itest test/cluster_commands_on_strings_test.rb
# @see https://redis.io/commands#string
class TestClusterCommandsOnStrings < Minitest::Test
include Helper::Cluster
include Lint::Strings
def mock(*args, &block)
redis_cluster_mock(*args, &block)
end
... |
github | redis/redis-rb | https://github.com/redis/redis-rb | cluster/test/commands_on_sorted_sets_test.rb | Ruby | mit | 3,989 | master | 1,527 | # frozen_string_literal: true
require "helper"
# ruby -w -Itest test/cluster_commands_on_sorted_sets_test.rb
# @see https://redis.io/commands#sorted_set
class TestClusterCommandsOnSortedSets < Minitest::Test
include Helper::Cluster
include Lint::SortedSets
def test_zrangestore
assert_raises(Redis::CommandE... |
github | redis/redis-rb | https://github.com/redis/redis-rb | cluster/test/commands_on_hashes_test.rb | Ruby | mit | 3,989 | master | 248 | # frozen_string_literal: true
require "helper"
# ruby -w -Itest test/cluster_commands_on_hashes_test.rb
# @see https://redis.io/commands#hash
class TestClusterCommandsOnHashes < Minitest::Test
include Helper::Cluster
include Lint::Hashes
end |
github | redis/redis-rb | https://github.com/redis/redis-rb | cluster/test/commands_on_connection_test.rb | Ruby | mit | 3,989 | master | 919 | # frozen_string_literal: true
require "helper"
require 'lint/authentication'
# ruby -w -Itest test/cluster_commands_on_connection_test.rb
# @see https://redis.io/commands#connection
class TestClusterCommandsOnConnection < Minitest::Test
include Helper::Cluster
include Lint::Authentication
def test_echo
ass... |
github | redis/redis-rb | https://github.com/redis/redis-rb | cluster/test/support/orchestrator.rb | Ruby | mit | 3,989 | master | 7,817 | # frozen_string_literal: true
require 'redis'
class ClusterOrchestrator
SLOT_SIZE = 16_384
def initialize(node_addrs, timeout: 30.0)
raise 'Redis Cluster requires at least 3 master nodes.' if node_addrs.size < 3
@clients = node_addrs.map do |addr|
Redis.new(url: addr, timeout: timeout, reconnect_a... |
github | redis/redis-rb | https://github.com/redis/redis-rb | cluster/lib/redis/cluster.rb | Ruby | mit | 3,989 | master | 5,097 | # frozen_string_literal: true
require "redis"
class Redis
class Cluster < ::Redis
# Raised when client connected to redis as cluster mode
# and failed to fetch cluster state information by commands.
class InitialSetupError < BaseError
end
# Raised when client connected to redis as cluster mode
... |
github | redis/redis-rb | https://github.com/redis/redis-rb | cluster/lib/redis/cluster/transaction_adapter.rb | Ruby | mit | 3,989 | master | 2,537 | # frozen_string_literal: true
require 'redis_client/cluster/transaction'
class Redis
class Cluster
class TransactionAdapter
class Internal < RedisClient::Cluster::Transaction
def initialize(client, router, command_builder, node: nil, slot: nil, asking: false)
@client = client
s... |
github | redis/redis-rb | https://github.com/redis/redis-rb | cluster/lib/redis/cluster/client.rb | Ruby | mit | 3,989 | master | 4,168 | # frozen_string_literal: true
require 'redis-cluster-client'
require 'redis/cluster/transaction_adapter'
class Redis
class Cluster
class Client < RedisClient::Cluster
ERROR_MAPPING = ::Redis::Client::ERROR_MAPPING.merge(
RedisClient::Cluster::InitialSetupError => Redis::Cluster::InitialSetupError,... |
github | redis/redis-rb | https://github.com/redis/redis-rb | lib/redis.rb | Ruby | mit | 3,989 | master | 5,486 | # frozen_string_literal: true
require "redis-client"
require "monitor"
require "redis/errors"
require "redis/commands"
class Redis
BASE_PATH = __dir__
Deprecated = Class.new(StandardError)
class << self
attr_accessor :silence_deprecations, :raise_deprecations
def deprecate!(message)
unless sile... |
github | redis/redis-rb | https://github.com/redis/redis-rb | lib/redis/client.rb | Ruby | mit | 3,989 | master | 3,309 | # frozen_string_literal: true
class Redis
class Client < ::RedisClient
ERROR_MAPPING = {
RedisClient::ConnectionError => Redis::ConnectionError,
RedisClient::CommandError => Redis::CommandError,
RedisClient::ReadTimeoutError => Redis::TimeoutError,
RedisClient::CannotConnectError => Redis... |
github | redis/redis-rb | https://github.com/redis/redis-rb | lib/redis/errors.rb | Ruby | mit | 3,989 | master | 1,602 | # frozen_string_literal: true
class Redis
# Base error for all redis-rb errors.
class BaseError < StandardError
end
# Raised by the connection when a protocol error occurs.
class ProtocolError < BaseError
def initialize(reply_type)
super(<<-EOS.gsub(/(?:^|\n)\s*/, " "))
Got '#{reply_type}'... |
github | redis/redis-rb | https://github.com/redis/redis-rb | lib/redis/subscribe.rb | Ruby | mit | 3,989 | master | 2,901 | # frozen_string_literal: true
class Redis
class SubscribedClient
def initialize(client)
@client = client
@write_monitor = Monitor.new
end
def call_v(command)
@write_monitor.synchronize do
@client.call_v(command)
end
end
def subscribe(*channels, &block)
subs... |
github | redis/redis-rb | https://github.com/redis/redis-rb | lib/redis/distributed.rb | Ruby | mit | 3,989 | master | 31,194 | # frozen_string_literal: true
require "redis/hash_ring"
class Redis
class Distributed
class CannotDistribute < RuntimeError
def initialize(command)
@command = command
end
def message
"#{@command.to_s.upcase} cannot be used in Redis::Distributed because the keys involved need "... |
github | redis/redis-rb | https://github.com/redis/redis-rb | lib/redis/pipeline.rb | Ruby | mit | 3,989 | master | 2,819 | # frozen_string_literal: true
require "delegate"
class Redis
class PipelinedConnection
attr_accessor :db
def initialize(pipeline, futures = [], exception: true)
@pipeline = pipeline
@futures = futures
@exception = exception
end
include Commands
def pipelined
yield self... |
github | redis/redis-rb | https://github.com/redis/redis-rb | lib/redis/hash_ring.rb | Ruby | mit | 3,989 | master | 2,097 | # frozen_string_literal: true
require 'zlib'
require 'digest/md5'
class Redis
class HashRing
POINTS_PER_SERVER = 160 # this is the default in libmemcached
attr_reader :ring, :sorted_keys, :replicas, :nodes
# nodes is a list of objects that have a proper to_s representation.
# replicas indicates ho... |
github | redis/redis-rb | https://github.com/redis/redis-rb | lib/redis/commands.rb | Ruby | mit | 3,989 | master | 6,024 | # frozen_string_literal: true
require "redis/commands/bitmaps"
require "redis/commands/cluster"
require "redis/commands/connection"
require "redis/commands/geo"
require "redis/commands/hashes"
require "redis/commands/hyper_log_log"
require "redis/commands/keys"
require "redis/commands/lists"
require "redis/commands/pu... |
github | redis/redis-rb | https://github.com/redis/redis-rb | lib/redis/commands/transactions.rb | Ruby | mit | 3,989 | master | 3,037 | # frozen_string_literal: true
class Redis
module Commands
module Transactions
# Mark the start of a transaction block.
#
# @example With a block
# redis.multi do |multi|
# multi.set("key", "value")
# multi.incr("counter")
# end # => ["OK", 6]
#
# ... |
github | redis/redis-rb | https://github.com/redis/redis-rb | lib/redis/commands/connection.rb | Ruby | mit | 3,989 | master | 1,242 | # frozen_string_literal: true
class Redis
module Commands
module Connection
# Authenticate to the server.
#
# @param [Array<String>] args includes both username and password
# or only password
# @return [String] `OK`
# @see https://redis.io/commands/auth AUTH command
d... |
github | redis/redis-rb | https://github.com/redis/redis-rb | lib/redis/commands/cluster.rb | Ruby | mit | 3,989 | master | 811 | # frozen_string_literal: true
class Redis
module Commands
module Cluster
# Sends `CLUSTER *` command to random node and returns its reply.
#
# @see https://redis.io/commands#cluster Reference of cluster command
#
# @param subcommand [String, Symbol] the subcommand of cluster command... |
github | redis/redis-rb | https://github.com/redis/redis-rb | lib/redis/commands/sorted_sets.rb | Ruby | mit | 3,989 | master | 34,873 | # frozen_string_literal: true
class Redis
module Commands
module SortedSets
# Get the number of members in a sorted set.
#
# @example
# redis.zcard("zset")
# # => 4
#
# @param [String] key
# @return [Integer]
def zcard(key)
send_command([:zcard,... |
github | redis/redis-rb | https://github.com/redis/redis-rb | lib/redis/commands/bitmaps.rb | Ruby | mit | 3,989 | master | 2,840 | # frozen_string_literal: true
class Redis
module Commands
module Bitmaps
# Sets or clears the bit at offset in the string value stored at key.
#
# @param [String] key
# @param [Integer] offset bit offset
# @param [Integer] value bit value `0` or `1`
# @return [Integer] the ori... |
github | redis/redis-rb | https://github.com/redis/redis-rb | lib/redis/commands/hyper_log_log.rb | Ruby | mit | 3,989 | master | 1,332 | # frozen_string_literal: true
class Redis
module Commands
module HyperLogLog
# Add one or more members to a HyperLogLog structure.
#
# @param [String] key
# @param [String, Array<String>] member one member, or array of members
# @return [Boolean] true if at least 1 HyperLogLog inter... |
github | redis/redis-rb | https://github.com/redis/redis-rb | lib/redis/commands/geo.rb | Ruby | mit | 3,989 | master | 3,490 | # frozen_string_literal: true
class Redis
module Commands
module Geo
# Adds the specified geospatial items (latitude, longitude, name) to the specified key
#
# @param [String] key
# @param [Array] member arguemnts for member or members: longitude, latitude, name
# @return [Integer] ... |
github | redis/redis-rb | https://github.com/redis/redis-rb | lib/redis/commands/keys.rb | Ruby | mit | 3,989 | master | 16,314 | # frozen_string_literal: true
class Redis
module Commands
module Keys
# Scan the keyspace
#
# @example Retrieve the first batch of keys
# redis.scan(0)
# # => ["4", ["key:21", "key:47", "key:42"]]
# @example Retrieve a batch of keys matching a pattern
# redis.sca... |
github | redis/redis-rb | https://github.com/redis/redis-rb | lib/redis/commands/sets.rb | Ruby | mit | 3,989 | master | 7,132 | # frozen_string_literal: true
class Redis
module Commands
module Sets
# Get the number of members in a set.
#
# @param [String] key
# @return [Integer]
def scard(key)
send_command([:scard, key])
end
# Add one or more members to a set.
#
# @param [Str... |
github | redis/redis-rb | https://github.com/redis/redis-rb | lib/redis/commands/pubsub.rb | Ruby | mit | 3,989 | master | 2,994 | # frozen_string_literal: true
class Redis
module Commands
module Pubsub
# Post a message to a channel.
def publish(channel, message)
send_command([:publish, channel, message])
end
def subscribed?
!@subscription_client.nil?
end
# Listen for messages published ... |
github | redis/redis-rb | https://github.com/redis/redis-rb | lib/redis/commands/server.rb | Ruby | mit | 3,989 | master | 5,210 | # frozen_string_literal: true
class Redis
module Commands
module Server
# Asynchronously rewrite the append-only file.
#
# @return [String] `OK`
def bgrewriteaof
send_command([:bgrewriteaof])
end
# Asynchronously save the dataset to disk.
#
# @return [Stri... |
github | redis/redis-rb | https://github.com/redis/redis-rb | lib/redis/commands/strings.rb | Ruby | mit | 3,989 | master | 9,891 | # frozen_string_literal: true
class Redis
module Commands
module Strings
# Decrement the integer value of a key by one.
#
# @example
# redis.decr("value")
# # => 4
#
# @param [String] key
# @return [Integer] value after decrementing it
def decr(key)
... |
github | redis/redis-rb | https://github.com/redis/redis-rb | lib/redis/commands/scripting.rb | Ruby | mit | 3,989 | master | 3,815 | # frozen_string_literal: true
class Redis
module Commands
module Scripting
# Control remote script registry.
#
# @example Load a script
# sha = redis.script(:load, "return 1")
# # => <sha of this script>
# @example Check if a script exists
# redis.script(:exists,... |
github | redis/redis-rb | https://github.com/redis/redis-rb | lib/redis/commands/lists.rb | Ruby | mit | 3,989 | master | 12,959 | # frozen_string_literal: true
class Redis
module Commands
module Lists
# Get the length of a list.
#
# @param [String] key
# @return [Integer]
def llen(key)
send_command([:llen, key])
end
# Remove the first/last element in a list, append/prepend it to another li... |
github | redis/redis-rb | https://github.com/redis/redis-rb | lib/redis/commands/hashes.rb | Ruby | mit | 3,989 | master | 11,683 | # frozen_string_literal: true
class Redis
module Commands
module Hashes
# Get the number of fields in a hash.
#
# @param [String] key
# @return [Integer] number of fields in the hash
def hlen(key)
send_command([:hlen, key])
end
# Set one or more hash values.
... |
github | redis/redis-rb | https://github.com/redis/redis-rb | lib/redis/commands/streams.rb | Ruby | mit | 3,989 | master | 18,715 | # frozen_string_literal: true
class Redis
module Commands
module Streams
# Returns the stream information each subcommand.
#
# @example stream
# redis.xinfo(:stream, 'mystream')
# @example groups
# redis.xinfo(:groups, 'mystream')
# @example consumers
# redis... |
github | redis/redis-rb | https://github.com/redis/redis-rb | examples/sets.rb | Ruby | mit | 3,989 | master | 534 | # frozen_string_literal: true
require 'rubygems'
require 'redis'
r = Redis.new
r.del 'foo-tags'
r.del 'bar-tags'
puts
p "create a set of tags on foo-tags"
r.sadd 'foo-tags', 'one'
r.sadd 'foo-tags', 'two'
r.sadd 'foo-tags', 'three'
puts
p "create a set of tags on bar-tags"
r.sadd 'bar-tags', 'three'
r.sadd 'bar-... |
github | redis/redis-rb | https://github.com/redis/redis-rb | examples/dist_redis.rb | Ruby | mit | 3,989 | master | 860 | # frozen_string_literal: true
require "redis"
require "redis/distributed"
r = Redis::Distributed.new %w[
redis://localhost:6379
redis://localhost:6380
redis://localhost:6381
redis://localhost:6382
]
r.flushdb
r['urmom'] = 'urmom'
r['urdad'] = 'urdad'
r['urmom1'] = 'urmom1'
r['urdad1'] = 'urdad1'
r['urmom2']... |
github | redis/redis-rb | https://github.com/redis/redis-rb | examples/sentinel.rb | Ruby | mit | 3,989 | master | 1,029 | # frozen_string_literal: true
require 'redis'
# This example creates a master-slave setup with a sentinel, then connects to
# it and sends write commands in a loop.
#
# After 30 seconds, the master dies. You will be able to see how a new master
# is elected and things continue to work as if nothing happened.
#
# To r... |
github | redis/redis-rb | https://github.com/redis/redis-rb | examples/pubsub.rb | Ruby | mit | 3,989 | master | 861 | # frozen_string_literal: true
require "redis"
puts <<~EOS
To play with this example use redis-cli from another terminal, like this:
$ redis-cli publish one hello
Finally force the example to exit sending the 'exit' message with:
$ redis-cli publish two exit
EOS
redis = Redis.new
trap(:INT) { puts; e... |
github | redis/redis-rb | https://github.com/redis/redis-rb | examples/incr-decr.rb | Ruby | mit | 3,989 | master | 229 | # frozen_string_literal: true
require 'redis'
r = Redis.new
puts
p 'incr'
r.del 'counter'
p r.incr('counter')
p r.incr('counter')
p r.incr('counter')
puts
p 'decr'
p r.decr('counter')
p r.decr('counter')
p r.decr('counter') |
github | redis/redis-rb | https://github.com/redis/redis-rb | examples/list.rb | Ruby | mit | 3,989 | master | 474 | # frozen_string_literal: true
require 'rubygems'
require 'redis'
r = Redis.new
r.del 'logs'
puts
p "pushing log messages into a LIST"
r.rpush 'logs', 'some log message'
r.rpush 'logs', 'another log message'
r.rpush 'logs', 'yet another log message'
r.rpush 'logs', 'also another log message'
puts
p 'contents of lo... |
github | redis/redis-rb | https://github.com/redis/redis-rb | examples/consistency.rb | Ruby | mit | 3,989 | master | 3,775 | # frozen_string_literal: true
# This file implements a simple consistency test for Redis-rb (or any other
# Redis environment if you pass a different client object) where a client
# writes to the database using INCR in order to increment keys, but actively
# remember the value the key should have. Before every write a... |
github | redis/redis-rb | https://github.com/redis/redis-rb | examples/unicorn/unicorn.rb | Ruby | mit | 3,989 | master | 558 | # frozen_string_literal: true
require "redis"
worker_processes 3
# If you set the connection to Redis *before* forking,
# you will cause forks to share a file descriptor.
#
# This causes a concurrency problem by which one fork
# can read or write to the socket while others are
# performing other operations.
#
# Most... |
github | redis/redis-rb | https://github.com/redis/redis-rb | test/helper.rb | Ruby | mit | 3,989 | master | 5,709 | # frozen_string_literal: true
$LOAD_PATH.unshift(File.expand_path('../lib', __dir__))
require "minitest/autorun"
require "mocha/minitest"
$VERBOSE = true
ENV["DRIVER"] ||= "ruby"
require "redis"
Redis.silence_deprecations = true
require "redis/distributed"
require_relative "support/redis_mock"
if ENV["DRIVER"] ... |
github | redis/redis-rb | https://github.com/redis/redis-rb | test/redis/internals_test.rb | Ruby | mit | 3,989 | master | 8,159 | # frozen_string_literal: true
require "helper"
class TestInternals < Minitest::Test
include Helper::Client
def test_large_payload
# see: https://github.com/redis/redis-rb/issues/962
# large payloads will trigger write_nonblock to write a portion
# of the payload in connection/ruby.rb _write_to_socket... |
github | redis/redis-rb | https://github.com/redis/redis-rb | test/redis/error_replies_test.rb | Ruby | mit | 3,989 | master | 1,099 | # frozen_string_literal: true
require "helper"
class TestErrorReplies < Minitest::Test
include Helper::Client
# Every test shouldn't disconnect from the server. Also, when error replies are
# in play, the protocol should never get into an invalid state where there are
# pending replies in the connection. Cal... |
github | redis/redis-rb | https://github.com/redis/redis-rb | test/redis/connection_handling_test.rb | Ruby | mit | 3,989 | master | 3,055 | # frozen_string_literal: true
require "helper"
require 'lint/authentication'
class TestConnectionHandling < Minitest::Test
include Helper::Client
include Lint::Authentication
def test_id
commands = {
client: ->(cmd, name) { @name = [cmd, name]; "+OK" },
ping: -> { "+PONG" }
}
redis_moc... |
github | redis/redis-rb | https://github.com/redis/redis-rb | test/redis/persistence_control_commands_test.rb | Ruby | mit | 3,989 | master | 513 | # frozen_string_literal: true
require "helper"
class TestPersistenceControlCommands < Minitest::Test
include Helper::Client
def test_save
redis_mock(save: -> { "+SAVE" }) do |redis|
assert_equal "SAVE", redis.save
end
end
def test_bgsave
redis_mock(bgsave: -> { "+BGSAVE" }) do |redis|
... |
github | redis/redis-rb | https://github.com/redis/redis-rb | test/redis/ssl_test.rb | Ruby | mit | 3,989 | master | 1,944 | # frozen_string_literal: true
require "helper"
class SslTest < Minitest::Test
include Helper::Client
def test_connection_to_non_ssl_server
assert_raises(Redis::CannotConnectError) do
redis = Redis.new(OPTIONS.merge(ssl: true, timeout: LOW_TIMEOUT))
redis.ping
end
end
def test_verified_ss... |
github | redis/redis-rb | https://github.com/redis/redis-rb | test/redis/remote_server_control_commands_test.rb | Ruby | mit | 3,989 | master | 2,934 | # frozen_string_literal: true
require "helper"
class TestRemoteServerControlCommands < Minitest::Test
include Helper::Client
def test_info
keys = [
"redis_version",
"uptime_in_seconds",
"uptime_in_days",
"connected_clients",
"used_memory",
"total_connections_received",
... |
github | redis/redis-rb | https://github.com/redis/redis-rb | test/redis/fork_safety_test.rb | Ruby | mit | 3,989 | master | 505 | # frozen_string_literal: true
require "helper"
class TestForkSafety < Minitest::Test
include Helper::Client
def setup
skip("Fork unavailable") unless Process.respond_to?(:fork)
end
def test_fork_safety
redis = Redis.new(OPTIONS)
pid = fork do
1000.times do
assert_equal "OK", redis.... |
github | redis/redis-rb | https://github.com/redis/redis-rb | test/redis/unknown_commands_test.rb | Ruby | mit | 3,989 | master | 243 | # frozen_string_literal: true
require "helper"
class TestUnknownCommands < Minitest::Test
include Helper::Client
def test_should_try_to_work
assert_raises Redis::CommandError do
r.not_yet_implemented_command
end
end
end |
github | redis/redis-rb | https://github.com/redis/redis-rb | test/redis/transactions_test.rb | Ruby | mit | 3,989 | master | 7,402 | # frozen_string_literal: true
require "helper"
class TestTransactions < Minitest::Test
include Helper::Client
def test_multi_discard
assert_raises(LocalJumpError) do
r.multi
end
end
def test_multi_exec_with_a_block
r.multi do |multi|
multi.set "foo", "s1"
end
assert_equal "s... |
github | redis/redis-rb | https://github.com/redis/redis-rb | test/redis/commands_on_value_types_test.rb | Ruby | mit | 3,989 | master | 5,493 | # frozen_string_literal: true
require "helper"
class TestCommandsOnValueTypes < Minitest::Test
include Helper::Client
include Lint::ValueTypes
def test_del
r.set "foo", "s1"
r.set "bar", "s2"
r.set "baz", "s3"
assert_equal ["bar", "baz", "foo"], r.keys("*").sort
assert_equal 0, r.del("")
... |
github | redis/redis-rb | https://github.com/redis/redis-rb | test/redis/scripting_test.rb | Ruby | mit | 3,989 | master | 2,170 | # frozen_string_literal: true
require "helper"
class TestScripting < Minitest::Test
include Helper::Client
def to_sha(script)
r.script(:load, script)
end
def test_script_exists
a = to_sha("return 1")
b = a.succ
assert_equal true, r.script(:exists, a)
assert_equal false, r.script(:exists... |
github | redis/redis-rb | https://github.com/redis/redis-rb | test/redis/encoding_test.rb | Ruby | mit | 3,989 | master | 430 | # frozen_string_literal: true
require "helper"
class TestEncoding < Minitest::Test
include Helper::Client
def test_returns_properly_encoded_strings
r.set "foo", "שלום"
assert_equal "Shalom שלום", "Shalom #{r.get('foo')}"
refute_predicate "\xFF", :valid_encoding?
r.set("bar", "\xFF")
bytes =... |
github | redis/redis-rb | https://github.com/redis/redis-rb | test/redis/url_param_test.rb | Ruby | mit | 3,989 | master | 3,003 | # frozen_string_literal: true
require "helper"
class TestUrlParam < Minitest::Test
include Helper::Client
def test_url_defaults_to_localhost
redis = Redis.new
assert_equal "localhost", redis._client.host
assert_equal 6379, redis._client.port
assert_equal 0, redis._client.db
assert_nil redis.... |
github | redis/redis-rb | https://github.com/redis/redis-rb | test/redis/sorting_test.rb | Ruby | mit | 3,989 | master | 1,490 | # frozen_string_literal: true
require "helper"
class TestSorting < Minitest::Test
include Helper::Client
def test_sort
r.set("foo:1", "s1")
r.set("foo:2", "s2")
r.rpush("bar", "1")
r.rpush("bar", "2")
assert_equal ["s1"], r.sort("bar", get: "foo:*", limit: [0, 1])
assert_equal ["s2"], r... |
github | redis/redis-rb | https://github.com/redis/redis-rb | test/redis/helper_test.rb | Ruby | mit | 3,989 | master | 367 | # frozen_string_literal: true
require "helper"
class TestHelper < Minitest::Test
include Helper
def test_version_comparison
v = Version.new("2.0.1")
assert v > "1"
assert v > "2"
assert v < "3"
assert v < "10"
assert v < "2.1"
assert v < "2.0.2"
assert v < "2.0.1.1"
assert v... |
github | redis/redis-rb | https://github.com/redis/redis-rb | test/redis/blocking_commands_test.rb | Ruby | mit | 3,989 | master | 1,561 | # frozen_string_literal: true
require "helper"
class TestBlockingCommands < Minitest::Test
include Helper::Client
include Lint::BlockingCommands
def assert_takes_longer_than_client_timeout
timeout = LOW_TIMEOUT
delay = timeout * 5
mock(delay: delay) do |r|
t1 = Time.now
yield(r)
... |
github | redis/redis-rb | https://github.com/redis/redis-rb | test/redis/bitpos_test.rb | Ruby | mit | 3,989 | master | 1,403 | # frozen_string_literal: true
require "helper"
class TestBitpos < Minitest::Test
include Helper::Client
def test_bitpos_empty_zero
r.del "foo"
assert_equal(0, r.bitpos("foo", 0))
end
def test_bitpos_empty_one
r.del "foo"
assert_equal(-1, r.bitpos("foo", 1))
end
def test_bitpos_zero
... |
github | redis/redis-rb | https://github.com/redis/redis-rb | test/redis/client_test.rb | Ruby | mit | 3,989 | master | 1,301 | # frozen_string_literal: true
require "helper"
class TestClient < Minitest::Test
include Helper::Client
def test_call
result = r.call("PING")
assert_equal result, "PONG"
end
def test_call_with_arguments
result = r.call("SET", "foo", "bar")
assert_equal result, "OK"
end
def test_with_blo... |
github | redis/redis-rb | https://github.com/redis/redis-rb | test/redis/connection_test.rb | Ruby | mit | 3,989 | master | 2,634 | # frozen_string_literal: true
require "helper"
class TestConnection < Minitest::Test
include Helper::Client
def test_provides_a_meaningful_inspect
assert_equal "#<Redis client v#{Redis::VERSION} for redis://localhost:#{PORT}/15>", r.inspect
end
def test_connection_with_user_and_password
target_versi... |
github | redis/redis-rb | https://github.com/redis/redis-rb | test/redis/commands_on_streams_test.rb | Ruby | mit | 3,989 | master | 237 | # frozen_string_literal: true
require "helper"
# ruby -w -Itest test/commands_on_streams_test.rb
# @see https://redis.io/commands#stream
class TestCommandsOnStreams < Minitest::Test
include Helper::Client
include Lint::Streams
end |
github | redis/redis-rb | https://github.com/redis/redis-rb | test/redis/thread_safety_test.rb | Ruby | mit | 3,989 | master | 509 | # frozen_string_literal: true
require "helper"
class TestThreadSafety < Minitest::Test
include Helper::Client
def test_thread_safety
redis = Redis.new(OPTIONS)
redis.set "foo", 1
redis.set "bar", 2
sample = 100
t1 = Thread.new do
@foos = Array.new(sample) { redis.get "foo" }
end
... |
github | redis/redis-rb | https://github.com/redis/redis-rb | test/redis/pipelining_commands_test.rb | Ruby | mit | 3,989 | master | 7,031 | # frozen_string_literal: true
require "helper"
class TestPipeliningCommands < Minitest::Test
include Helper::Client
def test_bulk_commands
r.pipelined do |p|
p.lpush "foo", "s1"
p.lpush "foo", "s2"
end
assert_equal 2, r.llen("foo")
assert_equal "s2", r.lpop("foo")
assert_equal "s... |
github | redis/redis-rb | https://github.com/redis/redis-rb | test/redis/commands_on_geo_test.rb | Ruby | mit | 3,989 | master | 3,658 | # frozen_string_literal: true
require "helper"
class TestCommandsGeo < Minitest::Test
include Helper::Client
def setup
super
added_items_count = r.geoadd("Sicily", 13.361389, 38.115556, "Palermo", 15.087269, 37.502669, "Catania")
assert_equal 2, added_items_count
end
def test_geoadd_with_array_... |
github | redis/redis-rb | https://github.com/redis/redis-rb | test/redis/publish_subscribe_test.rb | Ruby | mit | 3,989 | master | 8,501 | # frozen_string_literal: true
require "helper"
class TestPublishSubscribe < Minitest::Test
include Helper::Client
def setup
@threads = {}
super
end
def teardown
super
@threads.each do |thread, redis|
if redis.subscribed?
redis.unsubscribe
redis.punsubscribe
end
... |
github | redis/redis-rb | https://github.com/redis/redis-rb | test/redis/scanning_test.rb | Ruby | mit | 3,989 | master | 9,548 | # frozen_string_literal: true
require "helper"
class TestScanning < Minitest::Test
include Helper::Client
def test_scan_basic
r.debug :populate, 1000
cursor = 0
all_keys = []
loop do
cursor, keys = r.scan cursor
all_keys += keys
break if cursor == "0"
end
assert_equal ... |
github | redis/redis-rb | https://github.com/redis/redis-rb | test/sentinel/sentinel_command_test.rb | Ruby | mit | 3,989 | master | 1,818 | # frozen_string_literal: true
require "helper"
# @see https://redis.io/topics/sentinel#sentinel-commands Sentinel commands
class SentinelCommandsTest < Minitest::Test
include Helper::Sentinel
def test_sentinel_command_master
wait_for_quorum
redis = build_sentinel_client
result = redis.sentinel('mast... |
github | redis/redis-rb | https://github.com/redis/redis-rb | test/sentinel/sentinel_test.rb | Ruby | mit | 3,989 | master | 13,239 | # frozen_string_literal: true
require "helper"
class SentinelTest < Minitest::Test
include Helper::Sentinel
def test_sentinel_master_role_connection
wait_for_quorum
actual = redis.role
assert_equal 'master', actual[0]
end
def test_sentinel_slave_role_connection
wait_for_quorum
redis =... |
github | redis/redis-rb | https://github.com/redis/redis-rb | test/distributed/commands_on_lists_test.rb | Ruby | mit | 3,989 | master | 602 | # frozen_string_literal: true
require "helper"
class TestDistributedCommandsOnLists < Minitest::Test
include Helper::Distributed
include Lint::Lists
def test_lmove
target_version "6.2" do
assert_raises Redis::Distributed::CannotDistribute do
r.lmove('foo', 'bar', 'LEFT', 'RIGHT')
end
... |
github | redis/redis-rb | https://github.com/redis/redis-rb | test/distributed/commands_on_strings_test.rb | Ruby | mit | 3,989 | master | 1,733 | # frozen_string_literal: true
require "helper"
class TestDistributedCommandsOnStrings < Minitest::Test
include Helper::Distributed
include Lint::Strings
def test_mget
r.set("foo", "s1")
r.set("bar", "s2")
assert_equal ["s1", "s2"], r.mget("foo", "bar")
assert_equal ["s1", "s2", nil], r.mget("f... |
github | redis/redis-rb | https://github.com/redis/redis-rb | test/distributed/internals_test.rb | Ruby | mit | 3,989 | master | 2,397 | # frozen_string_literal: true
require "helper"
class TestDistributedInternals < Minitest::Test
include Helper::Distributed
def test_provides_a_meaningful_inspect
nodes = ["redis://127.0.0.1:#{PORT}/15", *NODES]
redis = Redis::Distributed.new nodes
assert_equal "#<Redis client v#{Redis::VERSION} for ... |
github | redis/redis-rb | https://github.com/redis/redis-rb | test/distributed/remote_server_control_commands_test.rb | Ruby | mit | 3,989 | master | 1,343 | # frozen_string_literal: true
require "helper"
class TestDistributedRemoteServerControlCommands < Minitest::Test
include Helper::Distributed
def test_info
keys = [
"redis_version",
"uptime_in_seconds",
"uptime_in_days",
"connected_clients",
"used_memory",
"total_connection... |
github | redis/redis-rb | https://github.com/redis/redis-rb | test/distributed/sorting_test.rb | Ruby | mit | 3,989 | master | 376 | # frozen_string_literal: true
require "helper"
class TestDistributedSorting < Minitest::Test
include Helper::Distributed
def test_sort
assert_raises(Redis::Distributed::CannotDistribute) do
r.set("foo:1", "s1")
r.set("foo:2", "s2")
r.rpush("bar", "1")
r.rpush("bar", "2")
r.sor... |
github | redis/redis-rb | https://github.com/redis/redis-rb | test/distributed/connection_handling_test.rb | Ruby | mit | 3,989 | master | 345 | # frozen_string_literal: true
require "helper"
class TestDistributedConnectionHandling < Minitest::Test
include Helper::Distributed
def test_ping
assert_equal ["PONG"], r.ping
end
def test_select
r.set "foo", "bar"
r.select 14
assert_nil r.get("foo")
r.select 15
assert_equal "bar"... |
github | redis/redis-rb | https://github.com/redis/redis-rb | test/distributed/commands_on_value_types_test.rb | Ruby | mit | 3,989 | master | 2,557 | # frozen_string_literal: true
require "helper"
class TestDistributedCommandsOnValueTypes < Minitest::Test
include Helper::Distributed
include Lint::ValueTypes
def test_del
r.set "foo", "s1"
r.set "bar", "s2"
r.set "baz", "s3"
assert_equal ["bar", "baz", "foo"], r.keys("*").sort
assert_equ... |
github | redis/redis-rb | https://github.com/redis/redis-rb | test/distributed/scripting_test.rb | Ruby | mit | 3,989 | master | 2,506 | # frozen_string_literal: true
require "helper"
class TestDistributedScripting < Minitest::Test
include Helper::Distributed
def to_sha(script)
r.script(:load, script).first
end
def test_script_exists
a = to_sha("return 1")
b = a.succ
assert_equal [true], r.script(:exists, a)
assert_equal... |
github | redis/redis-rb | https://github.com/redis/redis-rb | test/distributed/publish_subscribe_test.rb | Ruby | mit | 3,989 | master | 1,946 | # frozen_string_literal: true
require "helper"
class TestDistributedPublishSubscribe < Minitest::Test
include Helper::Distributed
def test_subscribe_and_unsubscribe
assert_raises Redis::Distributed::CannotDistribute do
r.subscribe("foo", "bar") {}
end
assert_raises Redis::Distributed::CannotDi... |
github | redis/redis-rb | https://github.com/redis/redis-rb | test/distributed/commands_on_sorted_sets_test.rb | Ruby | mit | 3,989 | master | 2,066 | # frozen_string_literal: true
require "helper"
class TestDistributedCommandsOnSortedSets < Minitest::Test
include Helper::Distributed
include Lint::SortedSets
def test_zrangestore
assert_raises(Redis::Distributed::CannotDistribute) { super }
end
def test_zinter
assert_raises(Redis::Distributed::Ca... |
github | redis/redis-rb | https://github.com/redis/redis-rb | test/distributed/blocking_commands_test.rb | Ruby | mit | 3,989 | master | 744 | # frozen_string_literal: true
require "helper"
class TestDistributedBlockingCommands < Minitest::Test
include Helper::Distributed
include Lint::BlockingCommands
def test_blmove_raises
target_version "6.2" do
assert_raises(Redis::Distributed::CannotDistribute) do
r.blmove('foo', 'bar', 'LEFT',... |
github | redis/redis-rb | https://github.com/redis/redis-rb | test/distributed/commands_on_sets_test.rb | Ruby | mit | 3,989 | master | 2,071 | # frozen_string_literal: true
require "helper"
class TestDistributedCommandsOnSets < Minitest::Test
include Helper::Distributed
include Lint::Sets
def test_smove
assert_raises Redis::Distributed::CannotDistribute do
r.sadd 'foo', 's1'
r.sadd 'bar', 's2'
r.smove('foo', 'bar', 's1')
en... |
github | redis/redis-rb | https://github.com/redis/redis-rb | test/distributed/persistence_control_commands_test.rb | Ruby | mit | 3,989 | master | 535 | # frozen_string_literal: true
require "helper"
class TestDistributedPersistenceControlCommands < Minitest::Test
include Helper::Distributed
def test_save
redis_mock(save: -> { "+SAVE" }) do |redis|
assert_equal ["SAVE"], redis.save
end
end
def test_bgsave
redis_mock(bgsave: -> { "+BGSAVE" ... |
github | redis/redis-rb | https://github.com/redis/redis-rb | test/distributed/distributed_test.rb | Ruby | mit | 3,989 | master | 1,337 | # frozen_string_literal: true
require "helper"
class TestDistributed < Minitest::Test
include Helper::Distributed
def test_handle_multiple_servers
@r = Redis::Distributed.new ["redis://127.0.0.1:#{PORT}/15", *NODES]
100.times do |idx|
@r.set(idx.to_s, "foo#{idx}")
end
100.times do |idx|
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.