Git Product home page Git Product logo

memcachex's Introduction

Memcache

CI Hex.pm Hex Docs Total Download License Last Updated

Memcached client for Elixir.

Installation

defp deps() do
  [
    {:memcachex, "~> 0.5"}
  ]
end

Overview

Memcachex comes with two kinds of API, a high level one named Memcache which provides functions to perform most of the common usecases and a low level one named Memcache.Connection which provides a less restrictive API. See the documentation for more information

Examples

{:ok, pid} = Memcache.start_link()
{:ok} = Memcache.set(pid, "hello", "world")
{:ok, "world"} = Memcache.get(pid, "hello")

See test folder for further examples.

Copyright and License

Copyright (c) 2014 Anantha Kumaran

This software is licensed under the MIT license.

memcachex's People

Contributors

ananthakumaran avatar atebmt avatar bit4bit avatar cjbottaro avatar jaimeiniesta avatar johndoneth avatar jzimbel-mbta avatar kianmeng avatar rcoonan-pd avatar rowinsongallego avatar thecodeboss avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

memcachex's Issues

[BUG] :get return invalid digit format after :decr

[BUG] :get return invalid digit format after :decr

Environment

  • Memcache (Docker) memcached:1.5.16-alpine
  • Erlang OTP 24.1
  • Elixir 1.13.1
    • {:memcachex, "~> 0.5.4"}

Examples

iex(1)> Memcache.set(pid, "a", "10")
{:ok}
iex(2)> Memcache.decr(pid, "a")      
{:ok, 9}
iex(3)> Memcache.get(pid, "a") 
{:ok, "9 "}
iex(1)> Memcache.set(pid, "a", "100")
{:ok}
iex(2)> Memcache.decr(pid, "a")
{:ok, 99}
iex(3)> Memcache.get(pid, "a")
{:ok, "99 "}

Support `:default` option on `cas/4`

This one is a little more "nice-to-have" than my other request, but I'm posting it for your consideration.

Currently cas/4 only works on cache items that already exist. It would be convenient if a :default opttion were supported, to make a "create-or-atomic-update" workflow possible.

If the initial get fails to find the requested key, we could then check opts for a :default key and set that instead.

This functionality is possible to implement with a function that wraps cas/4 in user code, but I thought I'd put the suggestion out there to add built-in support to the library. Thanks.

Emit Telemetry events

Hello!

Telemetry is getting traction now that it's included in Phoenix and Ecto out-of-the-box. What's your stance on emitting telemetry events from this library? Would you welcome contributions?

It would allow users of this library to capture important metrics and send them to their monitoring solution. This way, we save everyone the time to instrument their own usage of this library.

Stephan

[question] Release schedule?

Apologies for the additional open issue—just wondering what your usual schedule is for publishing new releases.

I would like to use the new cas/4 options in some code that I am working on now, but if you would like to wait on cutting a release, I can work around that. Thanks!

typespec errors when using Erlang/Json encoder

There's a type mismatch when using an encoder like Json or Erlang as the typespecs for set/add/replace are defined as binary() instead of term(). For example, in the unit tests:

assert {:ok} == Memcache.set(pid, "hello", ["list", 1])

Conflicts with the set/4 definition of binary in the third parameter:

  @doc """
  Sets the key to value
  Accepted options: `:cas`, `:ttl`
  """
  @spec set(GenServer.server(), binary, binary, Keyword.t()) :: store_result
  def set(server, key, value, opts \\ []) do
    ...

When calling dialyzer in an app that uses the Erlang encoder we get:

The call 'Elixir.Memcache':add
         (_name@1 :: atom(),
          _key@1 :: any(),
          _data@1 ::
              #{'ts' := 'nil' | integer(),
                'ttl' := 'nil' | integer(),
                'value' := _},
          [{'ttl', integer()}, ...]) breaks the contract
          ('Elixir.GenServer':server(),
          binary(),
          binary(),
          'Elixir.Keyword':t()) ->
             store_result()

Dalli Compatibility

Hello again!

Memcachex is not compatible with Dalli, even if both of them are using JSON as the serializer. The reason is that Dalli will only run the deserialize if a certain bit is set on the flags of the key. Here's the relevant code:

Only deseralize if bit is set:
https://github.com/petergoldstein/dalli/blob/master/lib/dalli/server.rb#L442

Set serialization bit if a serializer is used:
https://github.com/petergoldstein/dalli/blob/master/lib/dalli/server.rb#L435

I'm not entirely sure, but I think the fix would be to set that bit in the flags on the set, add, and replace commands (if a coder is specified).

What do you think?

Support `:ttl` option on `cas/4`

Currently, Memcache.cas/4 does not accept a :ttl option like most of the other functions that set cache keys. Can support be added, where the :ttl value gets passed through to the set_cas/5 call?

I'd be happy to post a PR for this change. Thanks for providing such a great library with quality docs!

ASCII Protocol

We use mcrouter for our memcache setup, but unfortunately it only supports ascii protocol.

I'm thinking of writing an ascii protocol implementation for Memcachex; is something that y'all would be onboard with?

Encoding issue on incr

Hi

I'm using memcache's increment but it is not working after a get.

iex(3)> Memcache.incr(Worker, "my_key")
{:ok, 3}
iex(4)> Memcache.get(Worker, "my_key")
** (ArgumentError) argument error
    :erlang.binary_to_term("3")
    (memcachex) lib/memcache/coder/erlang.ex:9: Memcache.Coder.Erlang.decode/2
    (memcachex) lib/memcache.ex:488: Memcache.decode_response/2

Maybe the value is not encoded on incr and decr?

=== UPDATE ===
I'm using Erlang coder, when I change to JSON it works.

Cluster?

Hi. The hexdocs for the project show a module Memcache.Cluster and Memcache.Cluster.Hash, but I can't find them in the source code.

Does this client support memcached clusters with the same consistent hashing algorithm as the Ruby clients (Dalli, Memcache)?

Thanks for the info!

Support for mget and mset?

Can you add support for these two operations?

I'm currently writing a higher level memcached client (support for clusters, fetch, mfetch, Ecto integration) that uses your client under the hood and I need mget and mset in order for mfetch to be efficient.

Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.