Class: Moneta::Adapters::Client

Inherits:
Object
  • Object
show all
Includes:
Defaults
Defined in:
lib/moneta/adapters/client.rb

Overview

Moneta client backend

Instance Method Summary collapse

Methods included from Defaults

#[], #[]=, #decrement, #fetch, included, #supports?

Methods included from OptionSupport

#expires, #prefix, #raw, #with

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :port (Integer) — default: 9000

    TCP port

  • :host (String) — default: '127.0.0.1'

    Hostname

  • :socket (String)

    Unix socket file name as alternative to ‘:port` and `:host`



14
15
16
17
# File 'lib/moneta/adapters/client.rb', line 14

def initialize(options = {})
  @socket = options[:socket] ? UNIXSocket.open(options[:socket]) :
    TCPSocket.open(options[:host] || '127.0.0.1', options[:port] || 9000)
end

Instance Method Details

#clear(options = {}) ⇒ void

This method returns an undefined value.

Clear all keys in this store

Parameters:

  • options (Hash) (defaults to: {})


57
58
59
60
61
# File 'lib/moneta/adapters/client.rb', line 57

def clear(options = {})
  write(:clear, options)
  read
  self
end

#closeObject

Explicitly close the store

Returns:

  • nil



64
65
66
67
# File 'lib/moneta/adapters/client.rb', line 64

def close
  @socket.close
  nil
end

#create(key, value, options = {}) ⇒ Boolean

Note:

Not every Moneta store implements this method, a NotImplementedError is raised if it is not supported.

Atomically sets a key to value if it’s not set.

Parameters:

  • key (Object)
  • value (Object)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • :expires (Integer)

    Update expiration time (See Expires)

  • :raw (Boolean)

    Raw access without value transformation (See Transformer)

  • :prefix (String)

    Prefix key (See Transformer)

Returns:

  • (Boolean)

    key was set



51
52
53
54
# File 'lib/moneta/adapters/client.rb', line 51

def create(key, value, options = {})
  write(:create, key, value, options)
  read
end

#delete(key, options = {}) ⇒ Object

Delete the key from the store and return the current value

Parameters:

  • key (Object)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • :raw (Boolean)

    Raw access without value transformation (See Transformer)

  • :prefix (String)

    Prefix key (See Transformer)

  • Other (Object)

    options as defined by the adapters or middleware

Returns:

  • (Object)

    current value



39
40
41
42
# File 'lib/moneta/adapters/client.rb', line 39

def delete(key, options = {})
  write(:delete, key, options)
  read
end

#featuresObject



70
71
72
73
74
75
76
# File 'lib/moneta/adapters/client.rb', line 70

def features
  @features ||=
    begin
      write(:features)
      read.freeze
    end
end

#increment(key, amount = 1, options = {}) ⇒ Object

Note:

Not every Moneta store implements this method, a NotImplementedError is raised if it is not supported.

Atomically increment integer value with key

This method also accepts negative amounts.

Parameters:

  • key (Object)
  • amount (Integer) (defaults to: 1)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • :prefix (String)

    Prefix key (See Transformer)

  • Other (Object)

    options as defined by the adapters or middleware

Returns:

  • (Object)

    value from store



45
46
47
48
# File 'lib/moneta/adapters/client.rb', line 45

def increment(key, amount = 1, options = {})
  write(:increment, key, amount, options)
  read
end

#key?(key, options = {}) ⇒ Boolean

Exists the value with key

Parameters:

  • key (Object)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • :expires (Integer)

    Update expiration time (See Expires)

  • :prefix (String)

    Prefix key (See Transformer)

  • Other (Object)

    options as defined by the adapters or middleware

Returns:

  • (Boolean)


20
21
22
23
# File 'lib/moneta/adapters/client.rb', line 20

def key?(key, options = {})
  write(:key?, key, options)
  read
end

#load(key, options = {}) ⇒ Object

Fetch value with key. Return nil if the key doesn’t exist

Parameters:

  • key (Object)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • :expires (Integer)

    Update expiration time (See Expires)

  • :raw (Boolean)

    Raw access without value transformation (See Transformer)

  • :prefix (String)

    Prefix key (See Transformer)

  • :sync (Boolean)

    Synchronized load (Cache reloads from adapter, Daybreak syncs with file)

  • Other (Object)

    options as defined by the adapters or middleware

Returns:

  • (Object)

    value



26
27
28
29
# File 'lib/moneta/adapters/client.rb', line 26

def load(key, options = {})
  write(:load, key, options)
  read
end

#store(key, value, options = {}) ⇒ Object

Store value with key

Parameters:

  • key (Object)
  • value (Object)
  • options (Hash) (defaults to: {})

Options Hash (options):

  • :expires (Integer)

    Set expiration time (See Expires)

  • :raw (Boolean)

    Raw access without value transformation (See Transformer)

  • :prefix (String)

    Prefix key (See Transformer)

  • Other (Object)

    options as defined by the adapters or middleware

Returns:

  • value



32
33
34
35
36
# File 'lib/moneta/adapters/client.rb', line 32

def store(key, value, options = {})
  write(:store, key, value, options)
  read
  value
end