Outdated egg!

This is an egg for CHICKEN 4, the unsupported old release. You're almost certainly looking for the CHICKEN 5 version of this egg, if it exists.

If it does not exist, there may be equivalent functionality provided by another egg; have a look at the egg index. Otherwise, please consider porting this egg to the current version of CHICKEN.

  1. Outdated egg!
  2. memcached
    1. Description
    2. Library procedures
      1. Server handles
      2. Convenience macro
    3. Example
    4. Version History
    5. License

memcached

Description

The memcached library contains procedures that implement the client side of the Memcached protocol. Memcached is a distributed in-memory key-value store for small chunks of arbitrary data.

The Chicken memcached library uses the base64-encode procedure from the base64 library to compute hashes for given key objects, and the read and write procedures to store Scheme objects in a Memcached instance.

Library procedures

[procedure] (connect HOST PORT)

Connects to the Memcached server instance running on HOST at PORT. Returns a server handle object (see below).

[procedure] (disconnect H)

Disconnects the given server handle from its host.

[procedure] (stats H)

Invokes the statistics command on the server indicated by handle H. Returns an alist of statistics information.

[procedure] (set H KEY VAL [HASH])

Set storage command on the server indicated by handle H. KEY and VAL can be any serializable Scheme object. The hash value for KEY is obtained by the HASH procedure, which defaults to the one provided by the Chicken SRFI-69 implementation. Returns #t on success, #f otherwise.

[procedure] (add H KEY VAL [HASH])

Add storage command on the server indicated by handle H. KEY and VAL can be any serializable Scheme object. The hash value for KEY is obtained by the HASH procedure, which defaults to the one provided by the Chicken SRFI-69 implementation. Returns #t on success, #f otherwise.

[procedure] (replace H KEY VAL [HASH])

Replace storage command on the server indicated by handle H. KEY and VAL can be any serializable Scheme object. The hash value for KEY is obtained by the HASH procedure, which defaults to the one provided by the Chicken SRFI-69 implementation. Returns #t on success, #f otherwise.

[procedure] (get H KEY [HASH])

Get command on the server indicated by handle H. The hash value for KEY is obtained by the HASH procedure, which defaults to the one provided by the Chicken SRFI-69 implementation. Returns the deserialized object if the key is found, #f otherwise.

[procedure] (get H KEY [HASH])

Delete command on the server indicated by handle H. The hash value for KEY is obtained by the HASH procedure, which defaults to the one provided by the Chicken SRFI-69 implementation. Returns #t on success, #f otherwise.

[procedure] (incr H KEY DELTA [HASH])

Increment key command on the server indicated by handle H. The hash value for KEY is obtained by the HASH procedure, which defaults to the one provided by the Chicken SRFI-69 implementation. Returns #t on success, #f otherwise.

[procedure] (decr H KEY DELTA [HASH])

Decrement key command on the server indicated by handle H. The hash value for KEY is obtained by the HASH procedure, which defaults to the one provided by the Chicken SRFI-69 implementation. Returns #t on success, #f otherwise.

Server handles

All procedures in this library operate on a server handle object, which is created by the connect procedure. The following predicate and accessors are available for accessing a server handle:

[procedure] (server-handle? H)

Returns #t is H is a Memcached server handle, #f otherwise.

[procedure] (server-handle-host H)

Returns the host name of the given handle.

[procedure] (server-handle-port H)

Returns the port number of the given handle.

Convenience macro

[syntax] (with-server-connection H HOST PORT CMD ...)

A convenience macro for creating and destroying a connection for a given set of commands. H is the name of the server handle that will be created. The connection is created before any of the forms CMD... are executed, and is destroyed after the last command is executed.

Example

(with-server-connection h "localhost" 11211
     (let ((foo 4))
       (let ((success (set h "foo" foo)))
	 (let ((foo1 (get h "foo")))
	   (equal? foo foo1)))))

Version History

License

Based on the Haskell Memcached library by Evan Martin <martine@danga.com>.

 Copyright 2011-2019 Ivan Raikov and Seth Alves.
 All rights reserved.
 
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions are
 met:
 
 Redistributions of source code must retain the above copyright
 notice, this list of conditions and the following disclaimer.
 
 Redistributions in binary form must reproduce the above copyright
 notice, this list of conditions and the following disclaimer in the
 documentation and/or other materials provided with the distribution.
 
 Neither the name of the author nor the names of its contributors may
 be used to endorse or promote products derived from this software
 without specific prior written permission.
 
 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 OF THE POSSIBILITY OF SUCH DAMAGE.