Skip to content

ijp/scheme-memcached

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

An R6RS Memcached Client

What is it?

A R6RS Scheme library for dealing with the Memcached caching daemon. Currently it only supports Guile, more will be added shortly.

Right now, the library is a little simplistic. It only supports communicating with a single Memcached instance, and expects you to deal with bytevectors. It also does not currently support CAS values. A more Schemey API for expiration values may also be desirable.

But anyway, enough self-deprecation, you probably want the docs.

API

Users are expected to import the (memcached) library.

Some commands take an expiration time. This is a 32 bit integer, whose meaning depends on its size. If it is less than 60*60*24*30=2592000, then it specifies the number of seconds. If it is larger than this, it specifies a Unix Time at which to expire. Update commands treat 0 specially as a “no-expires” value, since there is little point in updating something for it to expire immediately.

make-memcached-connection

string integer -> connection

Takes a host string, and a port number, and returns a new connection to that server.

() -> connection

Same as above, but defaults to localhost, port 11211.

connection-close

connection -> void

Closes the connection to the server

memcached-get

connection bytevector -> bytevector or #f

Takes a memcached connection, and a key bytevector, and returns the bytevector value stored in memcached with that key. If there is no value with that key, #f is returned.

memcached-set! / memcached-add! / memcached-replace!

connection bytevector bytevector integer -> boolean

Takes a memcached connection, a key bytevector, a value bytevector, and an expiration time, and updates the value stored at that key to the argument value. Returns #t if it updates the value, #f if it does not.

The differences between the three are:

  • memcached-set! always updates the value
  • memcached-add! will only update the value if there is not one already stored at that key
  • memcached-replace! will only updated the value if there is one already stored at that key

connection bytevector bytevector -> boolean

Similar to above, but there is no expiration date for the key-value pair.

memcached-delete!

connection bytevector -> boolean

Takes a memcached connection, and a key bytevector, and removes the value stored at memcached with that key. If there is no value associated with that key in memcached, it does nothing. Returns #t.

memcached-prepend! / memcached-append!

connection bytevector bytevector -> boolean

Takes a memcached connection, a key bytevector, and a value bytevector, and either prepends or appends the value argument to the value stored in memcached at that key. Returns #t if successful, or #f if there is no value in memcached at that key.

memcached-version

connection -> string

Takes a memcached connection, and returns a string specifying the version of the memcached server.

memcached-flush!

connection -> boolean

Takes a memcached connection, and removes all the keys-value pairs stored in it. Returns #t.

memcached-incr! / memcached-decr!

connection bytevector integer integer integer -> integer or #f

Takes a memcached connection, a key bytevector, a delta integer, an initial value integer, and an expiration time. It returns the value of incrementing (or decrementing) the integer value stored at that key by the delta amount. If the key does not exist, it is set to the initial value integer.

connection bytevector integer integer -> integer or #f

Similar to above, but defaults to not expiring the key.

connection bytevector integer -> integer or #f

Similar to above, but if the key is not found it does not set it to a value. Instead, if the keys is not found, it returns #f.

connection bytevector -> integer or #f

Similar to the above, but it defaults to incrementing/decrementing the key by 1.

About

A r6rs memcached library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published