Class: RedisClient::Namespace Deprecated

Inherits:
Object
  • Object
show all
Defined in:
lib/redis_client/namespace.rb,
lib/redis_client/namespace/version.rb,
lib/redis_client/namespace/middleware.rb,
lib/redis_client/namespace/command_builder.rb

Overview

Deprecated.

Use Middleware instead

RedisClient::Namespace provides transparent key namespacing for redis-client.

DEPRECATED: Using this class as a command_builder is deprecated. Please use RedisClient::Namespace::Middleware instead for full namespace support including automatic removal of namespace prefixes from command results.

The command_builder approach only transforms outgoing commands but cannot process incoming results to remove namespace prefixes from keys returned by commands like KEYS, SCAN, BLPOP, etc.

Examples:

Recommended middleware approach

client = RedisClient.config(
  middlewares: [RedisClient::Namespace::Middleware],
  custom: { namespace: "myapp", separator: ":" }
).new_client
client.call("SET", "key", "value")  # Actually sets "myapp:key"
client.call("KEYS", "*")            # Returns ["key"] instead of ["myapp:key"]

Legacy command_builder usage (not recommended)

builder = RedisClient::Namespace.new("myapp")
client = RedisClient.new(command_builder: builder)
client.call("SET", "key", "value")  # Actually sets "myapp:key"
client.call("KEYS", "*")            # Returns ["myapp:key"] - namespace not removed

Defined Under Namespace

Modules: CommandBuilder, Middleware Classes: Error

Constant Summary collapse

VERSION =
"0.2.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(namespace = "", separator: ":", parent_command_builder: RedisClient::CommandBuilder) ⇒ Namespace

Returns a new instance of Namespace.



38
39
40
41
42
# File 'lib/redis_client/namespace.rb', line 38

def initialize(namespace = "", separator: ":", parent_command_builder: RedisClient::CommandBuilder)
  @namespace = namespace
  @separator = separator
  @parent_command_builder = parent_command_builder
end

Instance Attribute Details

#namespaceObject (readonly)

Returns the value of attribute namespace.



36
37
38
# File 'lib/redis_client/namespace.rb', line 36

def namespace
  @namespace
end

#parent_command_builderObject (readonly)

Returns the value of attribute parent_command_builder.



36
37
38
# File 'lib/redis_client/namespace.rb', line 36

def parent_command_builder
  @parent_command_builder
end

#separatorObject (readonly)

Returns the value of attribute separator.



36
37
38
# File 'lib/redis_client/namespace.rb', line 36

def separator
  @separator
end

Instance Method Details

#generate(args, kwargs = nil) ⇒ Object



44
45
46
47
# File 'lib/redis_client/namespace.rb', line 44

def generate(args, kwargs = nil)
  CommandBuilder.namespaced_command(@parent_command_builder.generate(args, kwargs), namespace: @namespace,
                                                                                    separator: @separator)
end